Deploying workaround for matching applicationID with brandname for easier api calls through workflow while sending SMS
This commit is contained in:
parent
8416078496
commit
1bb447eca9
|
|
@ -70,11 +70,36 @@ async function findBusinessByApplicationId(merchantId, applicationId) {
|
|||
if (!normalizedApplicationId) return null;
|
||||
|
||||
const businesses = await getIndex(merchantId);
|
||||
return businesses.find((business) => {
|
||||
const exactMatch = businesses.find((business) => {
|
||||
const storedApplicationId = normalizeScopeId(business.applicationId);
|
||||
const storedBusinessId = normalizeScopeId(business.businessId);
|
||||
return storedApplicationId === normalizedApplicationId || storedBusinessId === normalizedApplicationId;
|
||||
}) || null;
|
||||
});
|
||||
|
||||
if (exactMatch) return exactMatch;
|
||||
|
||||
const normalizedBrandLookup = normalizedApplicationId.toLowerCase();
|
||||
const brandMatches = businesses.filter((business) => normalizeText(business.brandName).toLowerCase() === normalizedBrandLookup);
|
||||
|
||||
if (brandMatches.length > 1) {
|
||||
throw createHttpError(
|
||||
409,
|
||||
'Multiple businesses matched the provided applicationId brand fallback',
|
||||
{
|
||||
code: 'AMBIGUOUS_BUSINESS_MATCH',
|
||||
details: {
|
||||
companyId: merchantId,
|
||||
applicationId: normalizedApplicationId,
|
||||
matchedBusinesses: brandMatches.map((business) => ({
|
||||
businessId: business.businessId,
|
||||
brandName: business.brandName,
|
||||
})),
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return brandMatches[0] || null;
|
||||
}
|
||||
|
||||
const PROVIDER_FIELDS = ['providerName', 'senderId', 'dltEntityId', 'authKey'];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user