oak-pay-business/lib/watchers/settlePlan.js

40 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("oak-domain/lib/utils/uuid");
const watchers = [
{
//settle 更新order时filter不允许携带iState故使用fn方式
name: '当settlePlan达到结算时间时结算settlePlan',
entity: 'settlePlan',
filter: async () => {
const now = Date.now();
return {
iState: 'unsettled',
when: {
$lte: now,
},
};
},
projection: {
id: 1,
},
fn: async (context, data) => {
if (data.length > 0) {
const ids = data.map((ele) => ele.id);
await context.operate('settlePlan', {
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'settle',
data: {},
filter: {
id: {
$in: ids,
}
}
}, {});
}
return context.opResult;
}
}
];
exports.default = watchers;