38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
import { generateNewIdAsync } from '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 generateNewIdAsync(),
|
||
action: 'remove',
|
||
data: {},
|
||
filter: {
|
||
entity: 'mobile',
|
||
entityId: {
|
||
$in: mobileIds,
|
||
},
|
||
ableState: 'disabled',
|
||
},
|
||
}, option);
|
||
}
|
||
return mobiles.length;
|
||
}
|
||
}
|
||
];
|
||
export default triggers;
|