fix: validate goods input and prepare isolated business acceptance
This commit is contained in:
@@ -44,6 +44,21 @@ export class GoodsService extends SaasCrudServiceBase<typeof Crud.Goods> {
|
||||
throw new SaasBusinessReject('STOCK_COMMAND_REQUIRED','现有商品库存只能通过受管库存命令变更');
|
||||
}
|
||||
}
|
||||
if (change.operation === 'add' || change.operation === 'update') {
|
||||
const input = change.input;
|
||||
if (Object.prototype.hasOwnProperty.call(input, 'title') && !input.title.trim()) {
|
||||
throw new SaasBusinessReject('GOODS_INPUT_INVALID', '商品名称不能为空');
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(input, 'price') && !/^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/.test(input.price)) {
|
||||
throw new SaasBusinessReject('GOODS_INPUT_INVALID', '商品价格必须是非负金额');
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(input, 'stock') && (!Number.isSafeInteger(input.stock) || input.stock < 0 || input.stock > 2147483647)) {
|
||||
throw new SaasBusinessReject('GOODS_INPUT_INVALID', '商品库存必须是有效的非负整数');
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(input, 'status') && input.status !== 0 && input.status !== 1) {
|
||||
throw new SaasBusinessReject('GOODS_INPUT_INVALID', '商品状态仅允许下架或上架');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SaasAction(Actions.GoodsBatchInfo)
|
||||
|
||||
Reference in New Issue
Block a user