Hi @bootsy1974 ,
A Map lookup would be pretty simple to implement.
const contactTypeByCode = new Map([
['SiteApp_CACFP_PrincipleDirector', 'Principle Director'],
['SiteApp_CACFP_PrincipleAsstDir', 'Principle Assistant Director'],
['SiteApp_CACFP_Cook', 'Cook'],
]);
const getContactTypeTitle = (contactTypeCode: string) {
return contactTypeByCode.get(contactTypeCode) || 'Site Contact';
};
You might wish to increase the type-safety by requiring the caller to pass a code that's in the Map already.
const contactTypeByCodeArr = [
['SiteApp_CACFP_PrincipleDirector', 'Principle Director'],
['SiteApp_CACFP_PrincipleAsstDir', 'Principle Assistant Director'],
['SiteApp_CACFP_Cook', 'Cook'],
] as const;
type ContactCode = typeof contactTypeByCodeArr[number][0];
const contactTypeByCode = new Map(contactTypeByCodeArr);
const getContactTypeTitle = (contactTypeCode: ContactCode) {
return contactTypeByCode.get(contactTypeCode);
};
Best regards,
Yijing Sun
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.