-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add user info in projects by userId
- Loading branch information
Showing
3 changed files
with
67 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,71 @@ | ||
const { v4 } = require('uuid'); | ||
const { v4 } = require("uuid"); | ||
import { ProjectsModel } from "../models/ProjectsModel"; | ||
|
||
export class ProjectsController { | ||
/** | ||
* Get projects | ||
* @returns List of projects | ||
*/ | ||
static getProjects() { | ||
return ProjectsModel.query().select().orderBy('created_at'); | ||
} | ||
|
||
/** | ||
* Get projects | ||
* @returns List of projects | ||
*/ | ||
static getProjects() { | ||
return ProjectsModel.query().select().orderBy('created_at'); | ||
} | ||
/** | ||
* Get project by id | ||
* @param {String} id Projects ID | ||
* @returns Project by id | ||
*/ | ||
static getProjectById(id) { | ||
return ProjectsModel.query().findById(id); | ||
} | ||
|
||
/** | ||
* Get project by id | ||
* @param {String} id Projects ID | ||
* @returns Project by id | ||
*/ | ||
static getProjectById(id) { | ||
return ProjectsModel.query().findById(id); | ||
} | ||
/** | ||
* Get the projects by user id | ||
* @param {String} userId User ID | ||
* @returns The list of projects by user id | ||
*/ | ||
// TODO: Some fields are missing | ||
static getProjectsByUserId(userId) { | ||
return ProjectsModel.query() | ||
.join("users", "projects.user_id", "users.id") | ||
.select(["projects.*", "users.first_name", "users.last_name"]) | ||
.where("projects.user_id", userId) | ||
.orderBy("projects.created_at"); | ||
} | ||
|
||
/** | ||
* Get the projects by user id | ||
* @param {String} userId User ID | ||
* @returns The list of projects by user id | ||
*/ | ||
// TODO: Some fields are missing | ||
static getProjectsByUserId(userId) { | ||
return ProjectsModel.query().select(['projects.id', 'projects.project_name', 'projects.patient_code', 'projects.status']).where('projects.user_id', userId) | ||
} | ||
/** | ||
* Insert a project in the DB | ||
* @param {Object} payload Project | ||
* @returns The project inserted | ||
*/ | ||
static createProject(payload) { | ||
return ProjectsModel.query().insert({ | ||
id: v4(), | ||
project_name: payload.project_name, | ||
patient_code: payload.patient_code, | ||
status: payload.status, | ||
scene: payload.scene, | ||
assigned_at: payload.assigned_at, | ||
user_id: payload.user_id, | ||
}); | ||
} | ||
|
||
/** | ||
* Insert a project in the DB | ||
* @param {Object} payload Project | ||
* @returns The project inserted | ||
*/ | ||
static createProject(payload) { | ||
return ProjectsModel.query().insert({ | ||
id: v4(), | ||
project_name: payload.project_name, | ||
patient_code: payload.patient_code, | ||
status: payload.status, | ||
scene: payload.scene, | ||
assigned_at: payload.assigned_at, | ||
user_id: payload.user_id | ||
}) | ||
} | ||
/** | ||
* Update the project by id | ||
* @param {String} id Project ID | ||
* @param {Object} payload Updated fields | ||
* @returns | ||
*/ | ||
static updateProject(id, payload) { | ||
return ProjectsModel.query().updateAndFetchById(id, payload); | ||
} | ||
|
||
/** | ||
* Update the project by id | ||
* @param {String} id Project ID | ||
* @param {Object} payload Updated fields | ||
* @returns | ||
*/ | ||
static updateProject(id, payload) { | ||
return ProjectsModel.query().updateAndFetchById(id, payload); | ||
} | ||
|
||
/** | ||
* Delete the project by id | ||
* @param {String} id Project ID | ||
* @returns Deleted message | ||
*/ | ||
static deleteProject(id) { | ||
return ProjectsModel.query().deleteById(id); | ||
} | ||
} | ||
/** | ||
* Delete the project by id | ||
* @param {String} id Project ID | ||
* @returns Deleted message | ||
*/ | ||
static deleteProject(id) { | ||
return ProjectsModel.query().deleteById(id); | ||
} | ||
} |