2026-08-09 12:00:13 +03:30
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true });
exports . ORDER_TRANSITIONS = void 0 ;
exports . isFinalStatus = isFinalStatus ;
exports . allowedTransitions = allowedTransitions ;
exports . canTransition = canTransition ;
exports . assertTransition = assertTransition ;
const common_1 = require ( "@nestjs/common" );
const client_1 = require ( "@prisma/client" );
const order_status_1 = require ( "./order-status" );
exports . ORDER_TRANSITIONS = {
awaiting_review : [ client_1 . OrderStatus . pricing ],
pricing : [ client_1 . OrderStatus . awaiting_settlement ],
awaiting_settlement : [
client_1 . OrderStatus . awaiting_cash_payment ,
client_1 . OrderStatus . check_in_progress ,
client_1 . OrderStatus . pricing ,
],
awaiting_cash_payment : [
client_1 . OrderStatus . awaiting_cash_confirmation ,
client_1 . OrderStatus . expired ,
],
awaiting_cash_confirmation : [
client_1 . OrderStatus . cash_confirmed ,
client_1 . OrderStatus . awaiting_cash_payment ,
],
2026-11-08 11:57:47 +03:30
cash_confirmed : [ client_1 . OrderStatus . final_approved , client_1 . OrderStatus . preparing ],
2026-08-09 12:00:13 +03:30
check_in_progress : [ client_1 . OrderStatus . awaiting_check_review ],
awaiting_check_review : [
client_1 . OrderStatus . checks_approved ,
client_1 . OrderStatus . check_needs_fix ,
],
check_needs_fix : [ client_1 . OrderStatus . awaiting_check_review ],
2026-11-08 11:57:47 +03:30
checks_approved : [ client_1 . OrderStatus . final_approved , client_1 . OrderStatus . preparing ],
2026-08-09 12:00:13 +03:30
final_approved : [ client_1 . OrderStatus . preparing ],
preparing : [ client_1 . OrderStatus . ready_to_ship ],
ready_to_ship : [ client_1 . OrderStatus . shipped ],
shipped : [ client_1 . OrderStatus . delivered ],
delivered : [],
cancelled : [],
rejected : [],
expired : [],
cart : [ client_1 . OrderStatus . awaiting_review ],
submitted : [ client_1 . OrderStatus . awaiting_review ],
needs_correction : [ client_1 . OrderStatus . awaiting_review , client_1 . OrderStatus . pricing ],
awaiting_settlement_fix : [ client_1 . OrderStatus . awaiting_settlement ],
cash_in_progress : [ client_1 . OrderStatus . awaiting_cash_payment ],
cash_invoice_issued : [ client_1 . OrderStatus . awaiting_cash_payment ],
cash_payment_submitted : [ client_1 . OrderStatus . awaiting_cash_confirmation ],
check_rejected : [ client_1 . OrderStatus . check_needs_fix ],
};
const ADMIN_TERMINAL_TRANSITIONS = [
client_1 . OrderStatus . cancelled ,
client_1 . OrderStatus . rejected ,
];
const FINAL_STATUSES = [
client_1 . OrderStatus . delivered ,
client_1 . OrderStatus . cancelled ,
client_1 . OrderStatus . rejected ,
client_1 . OrderStatus . expired ,
];
function isFinalStatus ( status ) {
return FINAL_STATUSES . includes ( status );
}
function allowedTransitions ( from ) {
const next = [...( exports . ORDER_TRANSITIONS [ from ] ?? [])];
if ( ! isFinalStatus ( from )) {
for ( const terminal of ADMIN_TERMINAL_TRANSITIONS ) {
if ( ! next . includes ( terminal ))
next . push ( terminal );
}
}
return next ;
}
function canTransition ( from , to ) {
return allowedTransitions ( from ). includes ( to );
}
function assertTransition ( from , to ) {
if ( canTransition ( from , to ))
return ;
throw new common_1 . BadRequestException ( `تغییر وضعیت از « ${ order_status_1 . ORDER_STATUS_LABELS [ from ] } » به « ${ order_status_1 . ORDER_STATUS_LABELS [ to ] } » مجاز نیست` );
}
//# sourceMappingURL=order-transitions.js.map