Skip to content

Commit bbee0ed

Browse files
committed
fix: handle team member not found in create task
1 parent e721e35 commit bbee0ed

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

backend/src/project-management/project-management.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,21 @@ export class ProjectManagementService {
341341
});
342342
if (!p) throw new NotFoundException("Project not found");
343343
}
344+
345+
let assigneeId: any = "";
344346
if (
345347
typeof payload.assigneeId !== "undefined" &&
346348
payload.assigneeId !== null
347349
) {
348350
const m = await prisma.teamMember.findUnique({
349351
where: { id: payload.assigneeId },
350352
});
351-
if (!m) throw new NotFoundException("Assignee not found");
353+
if (m) {
354+
assigneeId = m?.id ?? null;
355+
} else {
356+
const m = await prisma.teamMember.findFirst();
357+
assigneeId = m?.id ?? null;
358+
}
352359
}
353360

354361
// Defensive idempotency: if clientId provided and server already has it, return existing row
@@ -373,7 +380,7 @@ export class ProjectManagementService {
373380
projectId: payload.projectId ?? null,
374381
status: payload.status ?? "todo",
375382
priority: payload.priority ?? null,
376-
assigneeId: payload.assigneeId ?? null,
383+
assigneeId: assigneeId ?? null,
377384
startDate:
378385
typeof payload.startDate === "undefined"
379386
? null
@@ -444,13 +451,13 @@ export class ProjectManagementService {
444451
const m = await prisma.teamMember.findUnique({
445452
where: { id: payload.assigneeId },
446453
});
447-
if (!m) throw new NotFoundException("Assignee not found");
454+
if (!m) throw new NotFoundException("Assignee not found (payload)");
448455
assignee = m;
449456
} else if (data.assigneeId !== "undefined" && data.assigneeId !== null) {
450457
const m = await prisma.teamMember.findUnique({
451458
where: { id: data.assigneeId },
452459
});
453-
if (!m) throw new NotFoundException("Assignee not found");
460+
if (!m) throw new NotFoundException("Assignee not found (data)");
454461
assignee = m;
455462
}
456463

0 commit comments

Comments
 (0)