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

38 lines
1.2 KiB
JavaScript
Raw 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.

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;