40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
"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;
|