oak-general-business/lib/triggers/mobile.js

40 lines
1.3 KiB
JavaScript
Raw Permalink 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 triggers = [
{
name: '当mobile删除前将关联的已禁用token删除',
entity: 'mobile',
action: 'remove',
when: 'before',
asRoot: true,
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const mobiles = await context.select('mobile', {
data: {
id: 1,
ableState: 1,
},
filter,
}, { forUpdate: true });
if (mobiles && mobiles.length > 0) {
const mobileIds = mobiles.map((ele) => ele.id);
await context.operate('token', {
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'remove',
data: {},
filter: {
entity: 'mobile',
entityId: {
$in: mobileIds,
},
ableState: 'disabled',
},
}, option);
}
return mobiles.length;
}
}
];
exports.default = triggers;