Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/backend/src/controllers/tasks.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validateWBS, WbsNumber } from 'shared';
export default class TasksController {
static async createTask(req: Request, res: Response, next: NextFunction) {
try {
const { title, deadline, startDate, priority, status, assignees, notes, labelIds } = req.body;
const { title, deadline, startDate, priority, status, assignees, notes, labelIds, blockedByIds } = req.body;
const wbsNum: WbsNumber = validateWBS(req.params.wbsNum as string);

const task = await TasksService.createTask(
Expand All @@ -18,6 +18,7 @@ export default class TasksController {
assignees,
req.organization,
labelIds,
blockedByIds ?? [],
startDate ? new Date(startDate) : undefined,
deadline ? new Date(deadline) : undefined
);
Expand All @@ -30,7 +31,7 @@ export default class TasksController {

static async editTask(req: Request, res: Response, next: NextFunction) {
try {
const { title, notes, priority, deadline, startDate, wbsNum, labelIds } = req.body;
const { title, notes, priority, deadline, startDate, wbsNum, labelIds, blockedByIds } = req.body;
const { taskId } = req.params as Record<string, string>;

const updateTask = await TasksService.editTask(
Expand All @@ -41,6 +42,7 @@ export default class TasksController {
notes,
priority,
labelIds,
blockedByIds ?? [],
startDate ? new Date(startDate) : undefined,
deadline ? new Date(deadline) : undefined,
wbsNum
Expand Down
42 changes: 38 additions & 4 deletions src/backend/src/prisma-query-args/tasks.query-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export type TaskQueryArgs = ReturnType<typeof getTaskQueryArgs>;
export type TaskPreviewQueryArgs = ReturnType<typeof getTaskPreviewQueryArgs>;
export type CalendarTaskQueryArgs = ReturnType<typeof getCalendarTaskQueryArgs>;
export type TaskLabelQueryArgs = ReturnType<typeof getTaskLabelQueryArgs>;
export type TaskBlockedByQueryArgs = ReturnType<typeof getTaskBlockedByQueryArgs>;
export type BlockingWorkPackagesQueryArgs = ReturnType<typeof getBlockingWorkPackagesArgs>;

export const getTaskLabelQueryArgs = () =>
Prisma.validator<Prisma.Task_LabelDefaultArgs>()({
Expand All @@ -15,14 +17,44 @@ export const getTaskLabelQueryArgs = () =>
}
});

export const getTaskBlockedByQueryArgs = () =>
Prisma.validator<Prisma.TaskDefaultArgs>()({
select: {
taskId: true,
title: true
}
});

// the work package (if any) that this task's own work package is blocked by, along with just enough
// of its tasks to tell whether it's still incomplete
export const getBlockingWorkPackagesArgs = () =>
Prisma.validator<Prisma.WBS_ElementDefaultArgs>()({
include: {
workPackage: {
include: {
blockedBy: {
select: {
carNumber: true,
projectNumber: true,
workPackageNumber: true,
name: true,
tasks: { where: { dateDeleted: null }, select: { status: true } }
}
}
}
}
}
});

export const getTaskQueryArgs = (organizationId: string) =>
Prisma.validator<Prisma.TaskDefaultArgs>()({
include: {
wbsElement: true,
wbsElement: getBlockingWorkPackagesArgs(),
createdBy: getUserQueryArgs(organizationId),
deletedBy: getUserQueryArgs(organizationId),
assignees: getUserQueryArgs(organizationId),
labels: getTaskLabelQueryArgs()
labels: getTaskLabelQueryArgs(),
blockedBy: getTaskBlockedByQueryArgs()
}
});

Expand All @@ -39,13 +71,15 @@ export const getCalendarTaskQueryArgs = (organizationId: string) =>
dateDeleted: true,
leadId: true,
managerId: true,
name: true
name: true,
workPackage: getBlockingWorkPackagesArgs().include.workPackage
}
},
createdBy: getUserQueryArgs(organizationId),
deletedBy: getUserQueryArgs(organizationId),
assignees: getUserQueryArgs(organizationId),
labels: getTaskLabelQueryArgs()
labels: getTaskLabelQueryArgs(),
blockedBy: getTaskBlockedByQueryArgs()
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE "_taskBlocking" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL,

CONSTRAINT "_taskBlocking_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateIndex
CREATE INDEX "_taskBlocking_B_index" ON "_taskBlocking"("B");

-- AddForeignKey
ALTER TABLE "_taskBlocking" ADD CONSTRAINT "_taskBlocking_A_fkey" FOREIGN KEY ("A") REFERENCES "Task"("taskId") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_taskBlocking" ADD CONSTRAINT "_taskBlocking_B_fkey" FOREIGN KEY ("B") REFERENCES "Task"("taskId") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 2 additions & 0 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ model Task {
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
wbsElementId String
labels Task_Label[]
blockedBy Task[] @relation(name: "taskBlocking")
blocking Task[] @relation(name: "taskBlocking")

@@index([wbsElementId])
}
Expand Down
22 changes: 22 additions & 0 deletions src/backend/src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelResearch.taskLabelId],
[],
undefined,
daysFromNow(10)
);
Expand All @@ -2296,6 +2297,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelDesign.taskLabelId],
[],
daysAgo(5),
daysFromNow(15)
);
Expand All @@ -2310,6 +2312,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId, joeBlow.userId],
ner,
[taskLabelResearch.taskLabelId, taskLabelBlocked.taskLabelId],
[],
undefined,
daysFromNow(8)
);
Expand All @@ -2325,6 +2328,7 @@ const performSeed: () => Promise<void> = async () => {
[joeBlow.userId],
ner,
[taskLabelTesting.taskLabelId],
[],
undefined,
daysFromNow(14)
);
Expand All @@ -2339,6 +2343,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId],
ner,
[taskLabelAdmin.taskLabelId],
[],
daysAgo(14),
daysFromNow(7)
);
Expand All @@ -2353,6 +2358,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId, joeBlow.userId, joeShmoe.userId],
ner,
[taskLabelDesign.taskLabelId],
[],
undefined,
daysFromNow(9)
);
Expand All @@ -2367,6 +2373,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId],
ner,
[taskLabelAdmin.taskLabelId],
[],
undefined,
daysFromNow(6)
);
Expand All @@ -2381,6 +2388,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelBuild.taskLabelId],
[],
undefined,
daysAgo(30)
);
Expand All @@ -2403,6 +2411,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelBuild.taskLabelId],
[],
undefined,
daysAgo(90)
);
Expand All @@ -2417,6 +2426,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId, joeBlow.userId, joeShmoe.userId],
ner,
[taskLabelAdmin.taskLabelId],
[],
daysAgo(70),
daysAgo(55)
);
Expand All @@ -2431,6 +2441,7 @@ const performSeed: () => Promise<void> = async () => {
[],
ner,
[taskLabelAdmin.taskLabelId],
[],
undefined,
daysFromNow(12)
);
Expand All @@ -2445,6 +2456,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelTesting.taskLabelId],
[],
undefined,
daysFromNow(8)
);
Expand All @@ -2459,6 +2471,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId, joeShmoe.userId],
ner,
[taskLabelAdmin.taskLabelId],
[],
undefined,
daysFromNow(7)
);
Expand All @@ -2473,6 +2486,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax.userId],
ner,
[taskLabelDesign.taskLabelId],
[],
daysAgo(80),
daysAgo(65)
);
Expand All @@ -2487,6 +2501,7 @@ const performSeed: () => Promise<void> = async () => {
[thomasEmrax, joeShmoe, joeBlow].map((user) => user.userId),
ner,
[taskLabelBuild.taskLabelId, taskLabelBlocked.taskLabelId],
[],
undefined,
daysFromNow(16)
);
Expand All @@ -2501,6 +2516,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelBuild.taskLabelId],
[],
undefined,
daysFromNow(13)
);
Expand All @@ -2515,6 +2531,7 @@ const performSeed: () => Promise<void> = async () => {
[joeShmoe.userId],
ner,
[taskLabelTesting.taskLabelId],
[],
undefined,
daysFromNow(18)
);
Expand All @@ -2529,6 +2546,7 @@ const performSeed: () => Promise<void> = async () => {
[joeBlow.userId],
ner,
[],
[],
undefined,
daysAgo(45)
);
Expand All @@ -2543,6 +2561,7 @@ const performSeed: () => Promise<void> = async () => {
[joeBlow.userId],
ner,
[taskLabelDesign.taskLabelId],
[],
undefined,
daysAgo(60)
);
Expand All @@ -2557,6 +2576,7 @@ const performSeed: () => Promise<void> = async () => {
[regina.userId],
ner,
[taskLabelResearch.taskLabelId, taskLabelAdmin.taskLabelId],
[],
daysAgo(21),
daysAgo(10)
);
Expand All @@ -2571,6 +2591,7 @@ const performSeed: () => Promise<void> = async () => {
[zatanna.userId],
ner,
[taskLabelAdmin.taskLabelId],
[],
daysAgo(10),
daysAgo(9)
);
Expand All @@ -2585,6 +2606,7 @@ const performSeed: () => Promise<void> = async () => {
[sandy.userId],
ner,
[taskLabelResearch.taskLabelId],
[],
daysAgo(16),
daysAgo(1)
);
Expand Down
4 changes: 4 additions & 0 deletions src/backend/src/routes/tasks.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ tasksRouter.post(
nonEmptyString(body('assignees.*')),
body('labelIds').isArray(),
body('labelIds.*').isString(),
body('blockedByIds').optional().isArray(),
body('blockedByIds.*').optional().isString(),
validateInputs,
TasksController.createTask
);
Expand All @@ -58,6 +60,8 @@ tasksRouter.post(
intMinZero(body('wbsNum.workPackageNumber')),
body('labelIds').isArray(),
body('labelIds.*').isString(),
body('blockedByIds').optional().isArray(),
body('blockedByIds.*').optional().isString(),
validateInputs,
TasksController.editTask
);
Expand Down
Loading
Loading