Skip to content

Commit

Permalink
feat: add user info in projects by userId
Browse files Browse the repository at this point in the history
  • Loading branch information
AngyDev committed Apr 4, 2022
1 parent 7e2e99b commit f9a34e7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 62 deletions.
2 changes: 2 additions & 0 deletions client/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const saveObject = async (id, projectId, file, filename) => {
url: `${API_URL}/upload/${projectId}`,
data: data,
});

return res.data;
} catch (error) {
return error.message;
}
Expand Down
4 changes: 2 additions & 2 deletions server/dbDesign/db_v2.vuerd.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@
"active": false,
"left": 620,
"top": 434,
"zIndex": 4,
"zIndex": 3,
"widthName": 61.9599609375,
"widthComment": 60,
"color": "#03A9F4"
Expand Down Expand Up @@ -771,7 +771,7 @@
"active": true,
"left": 47.3333,
"top": 403,
"zIndex": 20,
"zIndex": 4,
"widthName": 60,
"widthComment": 60,
"color": "#FF9800"
Expand Down
123 changes: 63 additions & 60 deletions server/src/controllers/ProjectsController.js
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);
}
}

0 comments on commit f9a34e7

Please sign in to comment.