Implemented KYB, compliance decisions, integration, and testing
This commit is contained in:
+42
-4
@@ -1,7 +1,8 @@
|
||||
import type { User } from '@merchantflow/contracts';
|
||||
import type { Prisma } from '@merchantflow/database';
|
||||
import type { Capabilities } from '@merchantflow/contracts';
|
||||
import { workflowActions, type Evidence } from './workflow-policy.js';
|
||||
import { workflowActions, validApproval, canReopenKyb, type Evidence } from './workflow-policy.js';
|
||||
import { activationCodes, isIntegrationCheck, reviewPolicyVersion } from '@merchantflow/contracts';
|
||||
import { ApiError } from './shared.js';
|
||||
export function merchantScope(user: User): Prisma.MerchantWhereInput {
|
||||
switch (user.role) {
|
||||
@@ -29,16 +30,53 @@ export function capabilities(user: User, merchant: Evidence): Capabilities {
|
||||
const sales =
|
||||
user.role === 'HEAD_OF_SALES' ||
|
||||
(user.role === 'ACCOUNT_MANAGER' && merchant.ownerId === user.id);
|
||||
const locked = merchant.reviews.some((review) =>
|
||||
['PENDING', 'APPROVED'].includes(review.decision),
|
||||
);
|
||||
const locked =
|
||||
merchant.reviews.some((review) => review.decision === 'PENDING') ||
|
||||
(merchant.reviews[0]?.decision === 'APPROVED' &&
|
||||
(merchant.reviews[0].policyVersion >= reviewPolicyVersion || merchant.status !== 'KYB'));
|
||||
const actions = workflowActions(user, merchant);
|
||||
const terminal = ['LIVE', 'REJECTED'].includes(merchant.status);
|
||||
const reopen = canReopenKyb(merchant);
|
||||
return {
|
||||
editCommercial: sales,
|
||||
editIdentity: sales && !locked,
|
||||
assign: user.role === 'HEAD_OF_SALES',
|
||||
collectChecklist: sales && merchant.status === 'KYB' && !locked,
|
||||
review: user.role === 'COMPLIANCE_OFFICER' && merchant.status === 'COMPLIANCE_REVIEW',
|
||||
reopenKyb: sales && reopen,
|
||||
activationCodes:
|
||||
sales && validApproval(merchant)
|
||||
? activationCodes.filter((code) =>
|
||||
isIntegrationCheck(code)
|
||||
? merchant.status === 'INTEGRATION'
|
||||
: merchant.status === 'TESTING',
|
||||
)
|
||||
: [],
|
||||
handoff: {
|
||||
owner: terminal
|
||||
? 'NONE'
|
||||
: merchant.status === 'COMPLIANCE_REVIEW'
|
||||
? 'COMPLIANCE_OFFICER'
|
||||
: !merchant.ownerId
|
||||
? 'HEAD_OF_SALES'
|
||||
: 'ACCOUNT_MANAGER',
|
||||
ownerId: terminal || merchant.status === 'COMPLIANCE_REVIEW' ? null : merchant.ownerId,
|
||||
action: terminal
|
||||
? 'COMPLETE'
|
||||
: merchant.status === 'COMPLIANCE_REVIEW'
|
||||
? 'REVIEW'
|
||||
: !merchant.ownerId
|
||||
? 'ASSIGN'
|
||||
: reopen
|
||||
? 'REOPEN_KYB'
|
||||
: merchant.status === 'KYB'
|
||||
? 'COLLECT'
|
||||
: merchant.status === 'INTEGRATION'
|
||||
? 'INTEGRATE'
|
||||
: merchant.status === 'TESTING'
|
||||
? 'TEST'
|
||||
: 'COMMERCIAL',
|
||||
},
|
||||
activityKinds:
|
||||
user.role === 'COMPLIANCE_OFFICER'
|
||||
? (['KYB_NOTE'] as const)
|
||||
|
||||
Reference in New Issue
Block a user