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
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ const updateIdentity = () => {
sending.value = true;

updateContributorIdentity(props.contributor.id, props.modelValue.id, {
...form,
value: form.value,
type: form.type,
platform: form.type === 'email' ? 'custom' : form.platform,
verified: false,
source: 'ui',
integrationId: null,
sourceId: null,
platform: form.type === 'email' ? 'custom' : form.platform,
integrationId: null,
})
.then(() => {
ToastStore.success('Identity updated successfully');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import authAxios from '@/shared/axios/auth-axios';
import { ContributorIdentity } from '@/modules/contributor/types/Contributor';
import { ContributorIdentity, UpdateContributorIdentityPayload } from '@/modules/contributor/types/Contributor';
import { storeToRefs } from 'pinia';
import { useLfSegmentsStore } from '@/modules/lf/segments/store';

Expand Down Expand Up @@ -32,12 +32,14 @@ export class ContributorIdentitiesApiService {
).then(({ data }) => Promise.resolve(data));
}

static async update(memberId: string, id: string, identity: Partial<ContributorIdentity>) {
static async update(memberId: string, id: string, payload: UpdateContributorIdentityPayload) {
return authAxios.patch(
`/member/${memberId}/identity/${id}`,
payload,
Comment thread
joanagmaia marked this conversation as resolved.
{
...identity,
segments: getSegments(),
params: {
segments: getSegments(),
},
},
).then(({ data }) => Promise.resolve(data));
}
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/modules/contributor/store/contributor.actions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useLfSegmentsStore } from '@/modules/lf/segments/store';
import { storeToRefs } from 'pinia';
import { ContributorApiService } from '@/modules/contributor/services/contributor.api.service';
import { Contributor, ContributorAffiliation, ContributorIdentity } from '@/modules/contributor/types/Contributor';
import {
Contributor, ContributorAffiliation, ContributorIdentity, UpdateContributorIdentityPayload,
} from '@/modules/contributor/types/Contributor';
import { ContributorIdentitiesApiService } from '@/modules/contributor/services/contributor.identities.api.service';
import { MergeActionsService } from '@/shared/modules/merge/services/merge-actions.service';
import { MergeAction } from '@/shared/modules/merge/types/MemberActions';
Expand Down Expand Up @@ -72,7 +74,7 @@ export default {
return ContributorIdentitiesApiService.createMultiple(memberId, identities)
.then(this.setIdentities);
},
updateContributorIdentity(memberId: string, id: string, identity: Partial<ContributorIdentity>): Promise<ContributorIdentity[]> {
updateContributorIdentity(memberId: string, id: string, identity: UpdateContributorIdentityPayload): Promise<ContributorIdentity[]> {
return ContributorIdentitiesApiService.update(memberId, id, identity)
.then(this.setIdentities);
},
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/modules/contributor/types/Contributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ export interface ContributorIdentity {
duplicatedIdentities?: ContributorIdentity[];
}

export interface UpdateContributorIdentityPayload {
value?: string;
type?: string;
platform?: string;
verified?: boolean;
source?: string | null;
sourceId?: string | null;
integrationId?: string | null;
}

export interface Contributor {
activeDaysCount: string;
activeOn: string[] | null;
Expand Down
23 changes: 20 additions & 3 deletions services/libs/data-access-layer/src/members/identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,35 @@ export async function findMemberIdentitiesByValue(
)
}

const UPDATABLE_IDENTITY_FIELDS: ReadonlyArray<keyof UpdateMemberIdentity> = [
'platform',
'value',
'type',
'verified',
'verifiedBy',
'source',
'sourceId',
'integrationId',
]

export async function updateMemberIdentity(
qx: QueryExecutor,
memberId: string,
id: string,
data: Partial<UpdateMemberIdentity>,
): Promise<IMemberIdentity> {
if (Object.keys(data).length === 0) return null
const filtered = Object.fromEntries(
Object.entries(data).filter(
([k, v]) => (UPDATABLE_IDENTITY_FIELDS as readonly string[]).includes(k) && v !== undefined,
),
)

if (Object.keys(filtered).length === 0) return null

const setClause = Object.keys(data).map((key) => `"${key}" = $(${key})`)
const setClause = Object.keys(filtered).map((key) => `"${key}" = $(${key})`)
setClause.push('"updatedAt" = now()')

const params = { memberId, id, ...data }
const params = { memberId, id, ...filtered }

const query = `
UPDATE "memberIdentities"
Expand Down
Loading