1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/server/api/controllers/project-managers/delete.js

55 lines
1 KiB
JavaScript
Raw Normal View History

const Errors = {
PROJECT_MANAGER_NOT_FOUND: {
projectManagerNotFound: 'Project manager not found',
},
};
module.exports = {
inputs: {
id: {
type: 'string',
regex: /^[0-9]+$/,
required: true,
},
},
exits: {
projectManagerNotFound: {
responseType: 'notFound',
},
},
async fn(inputs) {
const { currentUser } = this.req;
let projectManager = await ProjectManager.findOne(inputs.id);
if (!projectManager) {
throw Errors.PROJECT_MANAGER_NOT_FOUND;
}
const isProjectManager = await sails.helpers.users.isProjectManager(
currentUser.id,
projectManager.projectId,
);
if (!isProjectManager) {
throw Errors.PROJECT_MANAGER_NOT_FOUND; // Forbidden
}
// TODO: check if the last one
2022-12-26 21:10:50 +01:00
projectManager = await sails.helpers.projectManagers.deleteOne.with({
record: projectManager,
request: this.req,
});
if (!projectManager) {
throw Errors.PROJECT_MANAGER_NOT_FOUND;
}
return {
item: projectManager,
};
},
};