42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||
const triggers = [
|
||
{
|
||
name: '禁用passport时,将关联的passport删除',
|
||
entity: 'passport',
|
||
action: 'update',
|
||
check: (operation) => {
|
||
const { data } = operation;
|
||
return data.hasOwnProperty('enabled') && data.enabled === false;
|
||
},
|
||
when: 'after',
|
||
fn: async ({ operation }, context, option) => {
|
||
const { data, filter } = operation;
|
||
const applicationPassports = await context.select('applicationPassport', {
|
||
data: {
|
||
id: 1,
|
||
},
|
||
filter: {
|
||
passport: filter,
|
||
}
|
||
}, { forUpdate: true });
|
||
if (applicationPassports && applicationPassports.length > 0) {
|
||
const ids = applicationPassports.map((ele) => ele.id);
|
||
await context.operate('applicationPassport', {
|
||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||
action: 'remove',
|
||
data: {},
|
||
filter: {
|
||
id: {
|
||
$in: ids,
|
||
}
|
||
},
|
||
}, option);
|
||
}
|
||
return 1;
|
||
}
|
||
},
|
||
];
|
||
exports.default = triggers;
|