74 lines
3.2 KiB
JavaScript
74 lines
3.2 KiB
JavaScript
import assert from 'assert';
|
||
import { OakInputIllegalException } from 'oak-domain/lib/types';
|
||
const checkers = [
|
||
{
|
||
entity: 'accountOper',
|
||
action: 'create',
|
||
type: 'row',
|
||
filter: {
|
||
account: {
|
||
ableState: 'enabled',
|
||
},
|
||
},
|
||
errMsg: 'account.update.accountDisabled',
|
||
},
|
||
{
|
||
entity: 'accountOper',
|
||
action: 'create',
|
||
type: 'data',
|
||
checker(data, context) {
|
||
assert(!(data instanceof Array));
|
||
const { type, totalPlus, availPlus } = data;
|
||
if (typeof totalPlus !== 'number') {
|
||
throw new OakInputIllegalException('accountOper', ['totalPlus'], 'accountOper中的totalPlus不是数字');
|
||
}
|
||
if (typeof availPlus !== 'number') {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper中的availPlus不是数字');
|
||
}
|
||
switch (type) {
|
||
case 'consume': {
|
||
if (totalPlus >= 0 || availPlus > 0 || totalPlus > availPlus) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为consume时,其totalPlus/availPlus必须为0或负数,且totalPlus的绝对值要更大');
|
||
}
|
||
break;
|
||
}
|
||
case 'deposit': {
|
||
if (totalPlus < 0 || availPlus < 0 || totalPlus !== availPlus) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为deposit时,其totalPlus/availPlus必须为正数且相等');
|
||
}
|
||
break;
|
||
}
|
||
case 'loan': {
|
||
if (totalPlus !== 0 || availPlus >= 0) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为loan时,其totalPlus必须为0,且availPlus必须为负数');
|
||
}
|
||
break;
|
||
}
|
||
case 'repay': {
|
||
if (totalPlus !== 0 || availPlus <= 0) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为repay时,其totalPlus必须为0,且availPlus必须为正数');
|
||
}
|
||
break;
|
||
}
|
||
case 'withdraw': {
|
||
if (totalPlus >= 0 || availPlus >= 0 || totalPlus !== availPlus) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为withdraw时,其totalPlus和availPlus必须为不相等的负数');
|
||
}
|
||
break;
|
||
}
|
||
case 'withdrawBack': {
|
||
if (totalPlus <= 0 || availPlus <= 0 || totalPlus !== availPlus) {
|
||
throw new OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为withdraw时,其totalPlus和availPlus必须为不相等的正数');
|
||
}
|
||
break;
|
||
}
|
||
default: {
|
||
assert(false);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
];
|
||
export default checkers;
|