feat(api): add staff order detail and compliance eligibility
This commit is contained in:
39
backend/query-api/src/lib/staff-order-eligibility.js
Normal file
39
backend/query-api/src/lib/staff-order-eligibility.js
Normal file
@@ -0,0 +1,39 @@
|
||||
function dedupeStrings(values = []) {
|
||||
return [...new Set(
|
||||
values
|
||||
.filter((value) => typeof value === 'string')
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean)
|
||||
)];
|
||||
}
|
||||
|
||||
export function dedupeDocumentNames(values = []) {
|
||||
return dedupeStrings(values);
|
||||
}
|
||||
|
||||
export function buildStaffOrderEligibilityBlockers({
|
||||
hasActiveWorkforce = true,
|
||||
businessBlockReason = null,
|
||||
hasExistingParticipation = false,
|
||||
missingDocumentNames = [],
|
||||
} = {}) {
|
||||
const blockers = [];
|
||||
|
||||
if (!hasActiveWorkforce) {
|
||||
blockers.push('Workforce profile is not active');
|
||||
}
|
||||
|
||||
if (businessBlockReason !== null && businessBlockReason !== undefined) {
|
||||
blockers.push(businessBlockReason
|
||||
? `You are blocked from working for this client: ${businessBlockReason}`
|
||||
: 'You are blocked from working for this client');
|
||||
}
|
||||
|
||||
if (hasExistingParticipation) {
|
||||
blockers.push('You already applied to or booked this order');
|
||||
}
|
||||
|
||||
blockers.push(...dedupeDocumentNames(missingDocumentNames).map((name) => `Missing required document: ${name}`));
|
||||
|
||||
return dedupeStrings(blockers);
|
||||
}
|
||||
Reference in New Issue
Block a user