Skip to content

Commit

Permalink
regression: Do not throw an error when a required custom field is mis…
Browse files Browse the repository at this point in the history
…sing on visitor to contact migration
  • Loading branch information
matheusbsilva137 committed Nov 27, 2024
1 parent fad7de4 commit cf14131
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/meteor/app/livechat/server/lib/contacts/createContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type CreateContactParams = {
contactManager?: string;
channels?: ILivechatContactChannel[];
importIds?: string[];
shouldValidateCustomFields?: boolean;
};

export async function createContact({
Expand All @@ -27,13 +28,15 @@ export async function createContact({
channels = [],
unknown,
importIds,
shouldValidateCustomFields = true,
}: CreateContactParams): Promise<string> {
if (contactManager) {
await validateContactManager(contactManager);
}

const allowedCustomFields = await getAllowedCustomFields();
const customFields = validateCustomFields(allowedCustomFields, receivedCustomFields);
const customFields = shouldValidateCustomFields
? validateCustomFields(await getAllowedCustomFields(), receivedCustomFields)
: receivedCustomFields;

return LivechatContacts.insertContact({
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
},
],
customFields: undefined,
shouldValidateCustomFields: false,
contactManager: 'manager1',
},
],
Expand Down Expand Up @@ -87,6 +88,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
},
],
customFields: undefined,
shouldValidateCustomFields: false,
contactManager: undefined,
},
],
Expand Down Expand Up @@ -130,6 +132,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
},
],
customFields: undefined,
shouldValidateCustomFields: false,
lastChat: {
_id: 'last-chat-id',
ts: testDate,
Expand Down Expand Up @@ -175,6 +178,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
customFields: {
customFieldId: 'customFieldValue',
},
shouldValidateCustomFields: false,
contactManager: undefined,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function mapVisitorToContact(visitor: ILivechatVisitor, source: IOm
ignoreAdditionalFields: true,
ignoreValidationErrors: true,
}),
shouldValidateCustomFields: false,
lastChat: visitor.lastChat,
contactManager: visitor.contactManager?.username && (await getContactManagerIdByUsername(visitor.contactManager.username)),
};
Expand Down

0 comments on commit cf14131

Please sign in to comment.