Skip to content

Commit

Permalink
#1587: copied changes from old branch to this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Megan Liu committed Jun 3, 2024
1 parent ba2a06c commit 65a8ff8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/backend/src/controllers/work-packages.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ export default class WorkPackagesController {
try {
const user = await getCurrentUser(res);
const wbsNum = validateWBS(req.params.wbsNum);
const { crId } = req.body;
const organizationId = getOrganizationId(req.headers);

await WorkPackagesService.deleteWorkPackage(user, wbsNum, organizationId);
await WorkPackagesService.deleteWorkPackage(user, wbsNum, crId, organizationId);
res.status(200).json({ message: `Successfully deleted work package #${req.params.wbsNum}` });
} catch (error: unknown) {
next(error);
Expand Down
2 changes: 1 addition & 1 deletion src/backend/src/routes/work-packages.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ workPackagesRouter.post(
validateInputs,
WorkPackagesController.editWorkPackage
);
workPackagesRouter.delete('/:wbsNum/delete', WorkPackagesController.deleteWorkPackage);
workPackagesRouter.delete('/:wbsNum/delete', intMinZero(body('crId')), WorkPackagesController.deleteWorkPackage);
workPackagesRouter.get('/:wbsNum/blocking', WorkPackagesController.getBlockingWorkPackages);
workPackagesRouter.post(
'/slack-upcoming-deadlines',
Expand Down
7 changes: 6 additions & 1 deletion src/backend/src/services/projects.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,12 @@ export default class ProjectsService {
await Promise.all(
workPackages.map(
async (workPackage) =>
await WorkPackagesService.deleteWorkPackage(user, wbsNumOf(workPackage.wbsElement), organizationId)
await WorkPackagesService.deleteWorkPackage(
user,
wbsNumOf(workPackage.wbsElement),
workPackage.workPackageId,
organizationId
)
)
);

Expand Down
14 changes: 13 additions & 1 deletion src/backend/src/services/work-packages.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,10 @@ export default class WorkPackagesService {
* Deletes the Work Package
* @param submitter The user who deleted the work package
* @param wbsNum The work package number to be deleted
* @param crId The id of the change request to be implemented by this deletion
* @param organizationId The organization id that the user is in
*/
static async deleteWorkPackage(submitter: User, wbsNum: WbsNumber, organizationId: string): Promise<void> {
static async deleteWorkPackage(submitter: User, wbsNum: WbsNumber, crId: string, organizationId: string): Promise<void> {
// Verify submitter is allowed to delete work packages
if (!(await userHasPermission(submitter.userId, organizationId, isAdmin)))
throw new AccessDeniedAdminOnlyException('delete work packages');
Expand All @@ -437,6 +438,17 @@ export default class WorkPackagesService {

const { wbsElementId, id: workPackageId } = workPackage;

await validateChangeRequestAccepted(crId);

await prisma.change.create({
data: {
changeRequestId: crId,
implementerId: submitter.userId,
wbsElementId,
detail: 'Work Package Deleted'
}
});

const dateDeleted = new Date();
const deletedByUserId = submitter.userId;

Expand Down

0 comments on commit 65a8ff8

Please sign in to comment.