From 3273eb05677711f3d3efe30890e670e98c8ebbef Mon Sep 17 00:00:00 2001 From: Yeganathan S <63534555+skwowet@users.noreply.github.com> Date: Mon, 23 Mar 2026 18:10:21 +0530 Subject: [PATCH 1/2] fix: allow empty affiliations array in PATCH project-affiliations Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com> --- .../patchProjectAffiliation.ts | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts b/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts index 45cc1d7db2..6b7c502aef 100644 --- a/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts +++ b/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts @@ -26,9 +26,9 @@ const paramsSchema = z.object({ projectId: z.uuid(), }) -const bodySchema = z.object({ - affiliations: z - .array( +const bodySchema = z + .object({ + affiliations: z.array( z .object({ organizationId: z.uuid(), @@ -38,10 +38,13 @@ const bodySchema = z.object({ .refine((a) => a.dateEnd == null || a.dateEnd >= a.dateStart, { message: 'dateEnd must be greater than or equal to dateStart', }), - ) - .min(1), - verifiedBy: z.string().max(255), -}) + ), + verifiedBy: z.string().max(255).optional(), + }) + .refine((b) => b.affiliations.length === 0 || b.verifiedBy != null, { + message: 'verifiedBy is required when affiliations are provided', + path: ['verifiedBy'], + }) export async function patchProjectAffiliation(req: Request, res: Response): Promise { const { memberId, projectId } = validateOrThrow(paramsSchema, req.params) @@ -75,17 +78,19 @@ export async function patchProjectAffiliation(req: Request, res: Response): Prom await qx.tx(async (tx) => { await deleteAllMemberSegmentAffiliationsForProject(tx, memberId, projectId) - await insertMemberSegmentAffiliations( - tx, - memberId, - projectId, - affiliations.map((a) => ({ - organizationId: a.organizationId, - dateStart: a.dateStart.toISOString(), - dateEnd: a.dateEnd?.toISOString() ?? null, - verifiedBy, - })), - ) + if (affiliations.length > 0) { + await insertMemberSegmentAffiliations( + tx, + memberId, + projectId, + affiliations.map((a) => ({ + organizationId: a.organizationId, + dateStart: a.dateStart.toISOString(), + dateEnd: a.dateEnd?.toISOString() ?? null, + verifiedBy: verifiedBy!, + })), + ) + } const oldOrgIds = existingAffiliations.map((a) => a.organizationId) const newOrgIds = affiliations.map((a) => a.organizationId) From 34acf975fe2f729de7bf8dba5a1f6fa799e90bd9 Mon Sep 17 00:00:00 2001 From: Yeganathan S <63534555+skwowet@users.noreply.github.com> Date: Mon, 23 Mar 2026 18:19:36 +0530 Subject: [PATCH 2/2] Update backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com> --- .../v1/members/project-affiliations/patchProjectAffiliation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts b/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts index 6b7c502aef..65002e352d 100644 --- a/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts +++ b/backend/src/api/public/v1/members/project-affiliations/patchProjectAffiliation.ts @@ -42,7 +42,7 @@ const bodySchema = z verifiedBy: z.string().max(255).optional(), }) .refine((b) => b.affiliations.length === 0 || b.verifiedBy != null, { - message: 'verifiedBy is required when affiliations are provided', + message: 'verifiedBy is required when affiliations is non-empty', path: ['verifiedBy'], })