diff --git a/backend/src/api/public/openapi.yaml b/backend/src/api/public/openapi.yaml index 8e78d67d6f..c7897e65f5 100644 --- a/backend/src/api/public/openapi.yaml +++ b/backend/src/api/public/openapi.yaml @@ -319,6 +319,16 @@ 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' + 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 5b385a005b..d1f9167406 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, @@ -85,10 +85,21 @@ export async function verifyMemberIdentity(req: Request, res: Response): Promise captureOldState(identity) await qx.tx(async (tx) => { - updatedIdentity = await updateMemberIdentity(tx, memberId, identityId, { - verified, - verifiedBy, - }) + 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') + } + + throw error + } if (!updatedIdentity) { throw new InternalError('Failed to update member identity')