60 lines
1.1 KiB
TypeScript
60 lines
1.1 KiB
TypeScript
import type {
|
|
BusinessAccount,
|
|
BusinessVerificationEvent,
|
|
} from '../generated/prisma/client';
|
|
|
|
export function profileSnapshot(account: BusinessAccount) {
|
|
const {
|
|
legalName,
|
|
tradingName,
|
|
registrationNumber,
|
|
taxIdentifier,
|
|
countryCode,
|
|
contactEmail,
|
|
contactPhone,
|
|
billingLine1,
|
|
billingCity,
|
|
billingRegion,
|
|
billingPostalCode,
|
|
profileVersion,
|
|
} = account;
|
|
return {
|
|
legalName,
|
|
tradingName,
|
|
registrationNumber,
|
|
taxIdentifier,
|
|
countryCode,
|
|
contactEmail,
|
|
contactPhone,
|
|
billingLine1,
|
|
billingCity,
|
|
billingRegion,
|
|
billingPostalCode,
|
|
profileVersion,
|
|
};
|
|
}
|
|
|
|
export function businessStatus(
|
|
event?: Pick<BusinessVerificationEvent, 'kind'>,
|
|
) {
|
|
if (!event) return 'DRAFT' as const;
|
|
return (
|
|
{
|
|
SUBMITTED: 'PENDING',
|
|
APPROVED: 'VERIFIED',
|
|
REJECTED: 'REJECTED',
|
|
} as const
|
|
)[event.kind];
|
|
}
|
|
|
|
export function presentBusiness(
|
|
account: BusinessAccount & { events: BusinessVerificationEvent[] },
|
|
) {
|
|
const { events, ...profile } = account;
|
|
return {
|
|
...profile,
|
|
status: businessStatus(events[0]),
|
|
latestEvent: events[0] ?? null,
|
|
};
|
|
}
|