增加了order状态改变时对订阅者的推送

This commit is contained in:
Xu Chang 2025-02-12 11:41:53 +08:00
parent 74b884d84a
commit bd6636c4fe
8 changed files with 46 additions and 0 deletions

View File

@ -1,5 +1,6 @@
export declare const DATA_SUBSCRIBER_KEYS: {
payStateChanged: string;
orderStateChanged: string;
accountNumberChanged: string;
shipStateChanged: string;
};

View File

@ -1,5 +1,6 @@
export const DATA_SUBSCRIBER_KEYS = {
payStateChanged: 'oak-pay-business-psc',
orderStateChanged: 'oak-pay-business-osc',
accountNumberChanged: 'oak-pay-business-anc',
shipStateChanged: 'oak-pay-business-ssc',
};

View File

@ -1,4 +1,5 @@
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
import assert from 'assert';
const triggers = [
{
@ -138,5 +139,17 @@ const triggers = [
return cnt;
},
},
{
name: '订单状态改变时,向订阅者发送消息',
entity: 'order',
action: ['startPaying', 'payAll', 'payPartially', 'payNone', 'timeout', 'cancel', 'startRefunding', 'refundAll', 'refundPartially', 'refundNone'],
when: 'after',
fn: async ({ operation }, context, option) => {
const { filter, id } = operation;
assert(filter.id);
context.saveOperationToEvent(id, `${DATA_SUBSCRIBER_KEYS.orderStateChanged}-${filter.id}`);
return 1;
}
},
];
export default triggers;

View File

@ -1,5 +1,6 @@
export declare const DATA_SUBSCRIBER_KEYS: {
payStateChanged: string;
orderStateChanged: string;
accountNumberChanged: string;
shipStateChanged: string;
};

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.DATA_SUBSCRIBER_KEYS = void 0;
exports.DATA_SUBSCRIBER_KEYS = {
payStateChanged: 'oak-pay-business-psc',
orderStateChanged: 'oak-pay-business-osc',
accountNumberChanged: 'oak-pay-business-anc',
shipStateChanged: 'oak-pay-business-ssc',
};

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const uuid_1 = require("oak-domain/lib/utils/uuid");
const constants_1 = require("../config/constants");
const assert_1 = tslib_1.__importDefault(require("assert"));
const triggers = [
{
@ -141,5 +142,17 @@ const triggers = [
return cnt;
},
},
{
name: '订单状态改变时,向订阅者发送消息',
entity: 'order',
action: ['startPaying', 'payAll', 'payPartially', 'payNone', 'timeout', 'cancel', 'startRefunding', 'refundAll', 'refundPartially', 'refundNone'],
when: 'after',
fn: async ({ operation }, context, option) => {
const { filter, id } = operation;
(0, assert_1.default)(filter.id);
context.saveOperationToEvent(id, `${constants_1.DATA_SUBSCRIBER_KEYS.orderStateChanged}-${filter.id}`);
return 1;
}
},
];
exports.default = triggers;

View File

@ -1,5 +1,6 @@
export const DATA_SUBSCRIBER_KEYS = {
payStateChanged: 'oak-pay-business-psc',
orderStateChanged: 'oak-pay-business-osc',
accountNumberChanged: 'oak-pay-business-anc',
shipStateChanged: 'oak-pay-business-ssc',
};

View File

@ -1,5 +1,6 @@
import { CreateTriggerInTxn, Trigger, UpdateTriggerInTxn } from 'oak-domain/lib/types/Trigger';
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
import { EntityDict } from '../oak-app-domain';
import { BRC } from '../types/RuntimeCxt';
import assert from 'assert';
@ -155,6 +156,20 @@ const triggers: Trigger<EntityDict, 'order', BRC>[] = [
return cnt;
},
},
{
name: '订单状态改变时,向订阅者发送消息',
entity: 'order',
action: ['startPaying', 'payAll', 'payPartially', 'payNone', 'timeout', 'cancel', 'startRefunding', 'refundAll', 'refundPartially', 'refundNone'],
when: 'after',
fn: async ({ operation }, context, option) => {
const { filter, id } = operation as EntityDict['order']['Update'];
assert(filter!.id!);
context.saveOperationToEvent(id, `${DATA_SUBSCRIBER_KEYS.orderStateChanged}-${filter!.id!}`);
return 1;
}
} as UpdateTriggerInTxn<EntityDict, 'order', BRC>,
];
export default triggers;