import { OakAttrNotNullException } from 'oak-domain/lib/types'; import { pipeline } from 'oak-domain/lib/utils/executor'; const checkers = [ { // 退款所在的pay一定是可以退款状态,且其上不能有另一个正在退款的请求 entity: 'refund', type: 'row', filter: { pay: { refundable: true, refund$pay: { '#sqp': 'not in', iState: 'refunding', } }, }, action: 'create', errMsg: 'error::refund.create.hasAnotherRefunding', }, { entity: 'refund', action: 'succeed', type: 'logicalData', checker(operation, context) { const { data, filter } = operation; const { externalId } = data; // 必须有ExternalId,除非是account类型的支付 if (!externalId) { return pipeline(() => context.select('refund', { data: { id: 1, pay: { id: 1, entity: 1, }, }, filter: { id: filter.id, } }, { dontCollect: true }), (refunds) => { const [refund] = refunds; if (refund.pay.entity !== 'account') { throw new OakAttrNotNullException('refund', ['externalId']); } }); } } }, { entity: 'refund', action: 'fail', type: 'logicalData', checker(operation, context) { const { data, filter } = operation; const { reason } = data; // 必须有reason,除非是account类型的支付 if (!reason) { return pipeline(() => context.select('refund', { data: { id: 1, pay: { id: 1, entity: 1, }, }, filter: { id: filter.id, } }, { dontCollect: true }), (refunds) => { const [refund] = refunds; if (refund.pay.entity !== 'account') { throw new OakAttrNotNullException('refund', ['reason']); } }); } } }, ]; export default checkers;