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

49 lines
1.4 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.

import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
const triggers = [
{
name: '当parasite过期时使其相关token也过期',
entity: 'parasite',
action: 'update',
check: (operation) => {
const { data } = operation;
return !!data.expired;
},
when: 'before',
fn: async ({ operation }, context) => {
const { data, filter } = operation;
await context.operate('token', {
id: await generateNewIdAsync(),
action: 'disable',
data: {},
filter: {
parasite: filter,
},
}, {});
return 1;
},
},
{
name: '当parasite失效时使其相关token也过期',
entity: 'parasite',
action: 'cancel',
check: (operation) => {
const { data } = operation;
return !!data.expired;
},
when: 'before',
fn: async ({ operation }, context) => {
const { data, filter } = operation;
await context.operate('token', {
id: await generateNewIdAsync(),
action: 'disable',
data: {},
filter: {
parasite: filter,
},
}, {});
return 1;
},
},
];
export default triggers;