fix: separate pending and sent mail batches
This commit is contained in:
1 parent
fd2dd557c7
commit
5fe461c77d
7 files changed
+50
-8
No files matched your search
@@ -21,7 +21,8 @@ function filters(input={},kind){
|
||||
for(const name of ['page','pageSize']){result[name]=Number(result[name]);if(!Number.isSafeInteger(result[name])||result[name]<1)fail('页码或分页大小无效。');}
|
||||
if(![25,50,100].includes(result.pageSize))fail('每页仅支持25、50或100条。');
|
||||
if(result.status&&!(kind==='batches'?batchStates:orderStates).includes(result.status))fail('状态筛选无效。');
|
||||
if(kind==='batches'&&!['active','all'].includes(result.scope))fail('批次范围无效。');
|
||||
if(kind==='batches'&&!['active','sent','all'].includes(result.scope))fail('批次范围无效。');
|
||||
if(kind==='batches'&&result.status==='sent'&&result.scope==='active')result.scope='sent';
|
||||
for(const key of ['q','categoryId','connectionId'])if(result[key]!==undefined&&(typeof result[key]!=='string'||result[key].length>200))fail('查询内容过长或无效。');
|
||||
for(const key of ['from','to'])if(result[key]&&(!/^\d{4}-\d{2}-\d{2}$/.test(result[key])||!Number.isFinite(Date.parse(result[key]))||new Date(result[key]).toISOString().slice(0,10)!==result[key]))fail('日期筛选无效。');
|
||||
if(result.from&&result.to&&result.from>result.to)fail('开始日期不能晚于结束日期。');
|
||||
@@ -90,11 +91,11 @@ function publicRevision(context,user){
|
||||
}
|
||||
function queryOrders(context,input,user){const rows=visibleOrders(context,user),revision=crypto.createHash('sha256').update(publicRevision(context,user)+JSON.stringify(rows.map(r=>[r.id,r.collectingBatches]))).digest('hex').slice(0,24);return page(rows,filters(input,'orders'),revision);}
|
||||
function batchRow(context,batch){
|
||||
return {...pick(batch,['id','version','categoryId','subject','status','error','createdAt','windowStart','windowEnd','cutoff','orderNos','testRunId']),categoryName:batch.ruleSnapshot?.name||context.orderRules.get('rules',batch.categoryId)?.draft?.name||batch.categoryId,notificationMode:modeOf(batch),windowStart:batch.windowStart||batch.window?.start,windowEnd:batch.windowEnd||batch.window?.end||batch.cutoff,orderCount:batch.orderIds?.length||0,connectionIds:[...new Set((batch.orderIds||[]).map(id=>{const o=context.orderRules.get('orders',id);return o?.sample?.connectionId||o?.event?.connectionId||o?.connectionId;}).filter(Boolean))]};
|
||||
return {...pick(batch,['id','version','categoryId','subject','status','error','createdAt','sentAt','resolvedAt','windowStart','windowEnd','cutoff','orderNos','testRunId']),categoryName:batch.ruleSnapshot?.name||context.orderRules.get('rules',batch.categoryId)?.draft?.name||batch.categoryId,notificationMode:modeOf(batch),windowStart:batch.windowStart||batch.window?.start,windowEnd:batch.windowEnd||batch.window?.end||batch.cutoff,orderCount:batch.orderIds?.length||0,connectionIds:[...new Set((batch.orderIds||[]).map(id=>{const o=context.orderRules.get('orders',id);return o?.sample?.connectionId||o?.event?.connectionId||o?.connectionId;}).filter(Boolean))]};
|
||||
}
|
||||
function queryBatches(context,input,user){
|
||||
const f=filters(input,'batches'),data=records(context.orderRules);
|
||||
const rows=[...data.batches,...require('./collecting-batches.cjs').list(context.orderRules)].filter(b=>canReadBatch(context.workspace,user,b,context.orderRules)&&(f.scope==='all'||!['sent','cancelled'].includes(b.status))).map(b=>batchRow(context,b));
|
||||
const rows=[...data.batches,...require('./collecting-batches.cjs').list(context.orderRules)].filter(b=>canReadBatch(context.workspace,user,b,context.orderRules)&&(f.scope==='all'||(f.scope==='sent'?b.status==='sent':!['sent','cancelled'].includes(b.status)))).map(b=>batchRow(context,b));
|
||||
return page(rows,f,crypto.createHash('sha256').update(publicRevision(context,user)+JSON.stringify(rows)).digest('hex').slice(0,24));
|
||||
}
|
||||
function orderDetail(context,id,user){
|
||||
|
||||
Reference in new issue
Block a user