forked from yoone/API
refactor(order.service): 简化订单ID验证逻辑并优化查询条件
移除冗余的空值检查,使用可选链操作符简化验证 仅在validIds非空时添加查询条件
This commit is contained in:
parent
907228297d
commit
a22e302c4e
|
|
@ -2461,17 +2461,9 @@ export class OrderService {
|
|||
}
|
||||
|
||||
try {
|
||||
// 空值检查和数据清理
|
||||
if (!ids || !Array.isArray(ids)) {
|
||||
throw new Error('订单ID列表不能为空');
|
||||
}
|
||||
|
||||
// 过滤掉NaN和非数字值,只保留有效的数字ID
|
||||
const validIds = ids.filter(id => Number.isFinite(id) && id > 0);
|
||||
|
||||
if (validIds.length === 0) {
|
||||
throw new Error('未提供有效的订单ID');
|
||||
}
|
||||
const validIds = ids?.filter?.(id => Number.isFinite(id) && id > 0);
|
||||
|
||||
const dataSource = this.dataSourceManager.getDataSource('default');
|
||||
|
||||
|
|
@ -2479,7 +2471,9 @@ export class OrderService {
|
|||
return await dataSource.transaction(async manager => {
|
||||
// 准备查询条件
|
||||
const whereCondition: any = {};
|
||||
if(validIds.length > 0){
|
||||
whereCondition.id = In(validIds);
|
||||
}
|
||||
|
||||
// 获取订单、订单项和物流信息
|
||||
const orders = await manager.getRepository(Order).find({
|
||||
|
|
|
|||
Loading…
Reference in New Issue