const Errors = { NOT_ENOUGH_RIGHTS: { notEnoughRights: 'Not enough rights', }, LIST_NOT_FOUND: { listNotFound: 'List not found', }, }; module.exports = { inputs: { id: { type: 'string', regex: /^[0-9]+$/, required: true, }, }, exits: { notEnoughRights: { responseType: 'forbidden', }, listNotFound: { responseType: 'notFound', }, }, async fn(inputs) { const { currentUser } = this.req; // eslint-disable-next-line prefer-const let { list, board } = await sails.helpers.lists .getProjectPath(inputs.id) .intercept('pathNotFound', () => Errors.LIST_NOT_FOUND); const boardMembership = await BoardMembership.findOne({ boardId: list.boardId, userId: currentUser.id, }); if (!boardMembership) { throw Errors.LIST_NOT_FOUND; // Forbidden } if (boardMembership.role !== BoardMembership.Roles.EDITOR) { throw Errors.NOT_ENOUGH_RIGHTS; } list = await sails.helpers.lists.deleteOne.with({ record: list, board, request: this.req, }); if (!list) { throw Errors.LIST_NOT_FOUND; } return { item: list, }; }, };