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

51 lines
1.5 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.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("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 (0, uuid_1.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 (0, uuid_1.generateNewIdAsync)(),
action: 'disable',
data: {},
filter: {
parasite: filter,
},
}, {});
return 1;
},
},
];
exports.default = triggers;