36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const operationResult_1 = require("oak-domain/lib/utils/operationResult");
|
||
const ship_1 = require("../utils/ship");
|
||
const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
|
||
const watchers = [
|
||
{
|
||
name: '对shipping状态的物流,同步其真实状态',
|
||
entity: 'ship',
|
||
filter: async () => {
|
||
const now = Date.now();
|
||
return {
|
||
iState: 'shipping',
|
||
$$updateAt$$: {
|
||
$lte: now - QUERY_PAYING_STATE_GAP,
|
||
},
|
||
};
|
||
},
|
||
projection: ship_1.shipProjection,
|
||
fn: async (context, data) => {
|
||
const results = [];
|
||
for (const ship of data) {
|
||
const result = await (0, ship_1.refreshtShipState)(ship, context);
|
||
if (result) {
|
||
results.push(result);
|
||
}
|
||
}
|
||
if (results.length === 0) {
|
||
return {};
|
||
}
|
||
return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
|
||
}
|
||
}
|
||
];
|
||
exports.default = watchers;
|