Built merchant management, activity history, and the pipeline
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { User } from '@merchantflow/contracts';
|
||||
import type { Prisma } from '@merchantflow/database';
|
||||
import { successfulStages, type Status } from '@merchantflow/contracts';
|
||||
import type { Capabilities } from '@merchantflow/contracts';
|
||||
import { workflowActions, type Evidence } from './workflow-policy.js';
|
||||
import { ApiError } from './shared.js';
|
||||
export function merchantScope(user: User): Prisma.MerchantWhereInput {
|
||||
switch (user.role) {
|
||||
@@ -24,17 +25,14 @@ export function requireSales(user: User) {
|
||||
if (!['HEAD_OF_SALES', 'ACCOUNT_MANAGER'].includes(user.role))
|
||||
throw new ApiError('FORBIDDEN', 403);
|
||||
}
|
||||
export function capabilities(
|
||||
user: User,
|
||||
merchant: { status: Status; ownerId: string | null; reviews: { decision: string }[] },
|
||||
) {
|
||||
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 index = successfulStages.findIndex((stage) => stage === merchant.status);
|
||||
const actions = workflowActions(user, merchant);
|
||||
return {
|
||||
editCommercial: sales,
|
||||
editIdentity: sales && !locked,
|
||||
@@ -46,9 +44,8 @@ export function capabilities(
|
||||
? (['KYB_NOTE'] as const)
|
||||
: (['NOTE', 'CALL', 'EMAIL', 'MEETING'] as const),
|
||||
manageTaskKind: user.role === 'COMPLIANCE_OFFICER' ? 'COMPLIANCE' : 'COMMERCIAL',
|
||||
actions,
|
||||
nextStage:
|
||||
sales && merchant.ownerId && index >= 0 && merchant.status !== 'COMPLIANCE_REVIEW'
|
||||
? (successfulStages[index + 1] ?? null)
|
||||
: null,
|
||||
actions.find((action) => action.kind === 'ADVANCE' && action.enabled)?.toStatus ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user