From a177a4d3394de5d5a12f39cc8401492d7cca60f8 Mon Sep 17 00:00:00 2001 From: Yeganathan S <63534555+skwowet@users.noreply.github.com> Date: Tue, 28 Apr 2026 16:29:59 +0530 Subject: [PATCH 1/2] fix: return conflict for duplicate verified member identity in public api Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com> --- backend/src/api/public/openapi.yaml | 6 ++++++ .../members/identities/verifyMemberIdentity.ts | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/src/api/public/openapi.yaml b/backend/src/api/public/openapi.yaml index 8e78d67d6f..3b1a67be59 100644 --- a/backend/src/api/public/openapi.yaml +++ b/backend/src/api/public/openapi.yaml @@ -319,6 +319,12 @@ paths: application/json: schema: $ref: '#/components/schemas/HttpError' + '409': + description: Identity is already verified on another member. + content: + application/json: + schema: + $ref: '#/components/schemas/HttpError' # ────────────────────────────────────────────── # Maintainer Roles diff --git a/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts b/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts index 5b385a005b..d581ac4566 100644 --- a/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts +++ b/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts @@ -6,7 +6,7 @@ import { memberUnmergeAction, memberVerifyIdentityAction, } from '@crowd/audit-logs' -import { InternalError, NotFoundError } from '@crowd/common' +import { ConflictError, InternalError, NotFoundError } from '@crowd/common' import { invalidateMemberQueryCache, prepareMemberUnmerge, @@ -15,6 +15,7 @@ import { } from '@crowd/common_services' import { MemberField, + checkMemberIdentityExistence, deleteMemberIdentity, findMemberById, findMemberIdentityById, @@ -85,6 +86,19 @@ export async function verifyMemberIdentity(req: Request, res: Response): Promise captureOldState(identity) await qx.tx(async (tx) => { + if (verified) { + const existingIdentities = await checkMemberIdentityExistence( + tx, + identity.value, + identity.platform, + identity.type, + ) + + if (existingIdentities.some((i) => i.memberId !== memberId && i.verified)) { + throw new ConflictError('Identity already verified on another member') + } + } + updatedIdentity = await updateMemberIdentity(tx, memberId, identityId, { verified, verifiedBy, From d2b93a59879b4faab528166458b208784d9aa8ef Mon Sep 17 00:00:00 2001 From: Yeganathan S <63534555+skwowet@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:23:16 +0530 Subject: [PATCH 2/2] fix: resolve pr comments from ai bots Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com> --- backend/src/api/public/openapi.yaml | 4 +++ .../identities/verifyMemberIdentity.ts | 27 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/src/api/public/openapi.yaml b/backend/src/api/public/openapi.yaml index 3b1a67be59..c7897e65f5 100644 --- a/backend/src/api/public/openapi.yaml +++ b/backend/src/api/public/openapi.yaml @@ -325,6 +325,10 @@ paths: application/json: schema: $ref: '#/components/schemas/HttpError' + example: + error: + code: CONFLICT + message: Identity already verified on another member # ────────────────────────────────────────────── # Maintainer Roles diff --git a/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts b/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts index d581ac4566..d1f9167406 100644 --- a/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts +++ b/backend/src/api/public/v1/members/identities/verifyMemberIdentity.ts @@ -15,7 +15,6 @@ import { } from '@crowd/common_services' import { MemberField, - checkMemberIdentityExistence, deleteMemberIdentity, findMemberById, findMemberIdentityById, @@ -86,23 +85,21 @@ export async function verifyMemberIdentity(req: Request, res: Response): Promise captureOldState(identity) await qx.tx(async (tx) => { - if (verified) { - const existingIdentities = await checkMemberIdentityExistence( - tx, - identity.value, - identity.platform, - identity.type, - ) - - if (existingIdentities.some((i) => i.memberId !== memberId && i.verified)) { + try { + updatedIdentity = await updateMemberIdentity(tx, memberId, identityId, { + verified, + verifiedBy, + }) + } catch (error) { + const constraint = + error.constraint ?? error.original?.constraint ?? error.parent?.constraint + + if (verified && constraint === 'uix_memberIdentities_platform_value_type_verified') { throw new ConflictError('Identity already verified on another member') } - } - updatedIdentity = await updateMemberIdentity(tx, memberId, identityId, { - verified, - verifiedBy, - }) + throw error + } if (!updatedIdentity) { throw new InternalError('Failed to update member identity')