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

89 lines
2.9 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';
import { set } from 'oak-domain/lib/utils/lodash';
const triggers = [
{
name: '切换微信扫码登录方式',
entity: 'application',
action: 'update',
when: 'after',
fn: async ({ operation }, context) => {
const { data, filter } = operation;
const [application] = await context.select('application', {
data: {
id: 1,
config: 1,
},
filter: {
id: filter?.id,
},
count: 1,
}, {});
const { config } = application || {};
const toggleEnabelFn = async (type) => {
const [applicationP] = await context.select('application', {
data: {
id: 1,
config: 1,
},
filter: {
type,
},
count: 1,
}, {});
const { config: config2, id } = applicationP || {};
if (config2 && config2.type === type) {
if (type === 'web') {
set(config2, 'wechat.enable', false);
}
if (type === 'wechatPublic') {
Object.assign(config2, {
enable: false
});
}
await context.operate('application', {
id: await generateNewIdAsync(),
action: 'update',
data: {
config: config2,
},
filter: {
id,
}
}, {});
}
};
if (config?.type === 'web') {
const { wechat } = config;
if (wechat && wechat.enable) {
await toggleEnabelFn('wechatPublic');
}
}
else if (config?.type === 'wechatPublic') {
if (config.enable) {
await toggleEnabelFn('web');
}
}
return 1;
}
},
{
name: '删除application前将关联的passport删除',
entity: 'application',
action: 'remove',
when: 'before',
fn: async ({ operation }, context, option) => {
const { filter } = operation;
await context.operate('applicationPassport', {
id: await generateNewIdAsync(),
action: 'remove',
data: {},
filter: {
application: filter,
},
}, option);
return 1;
}
},
];
export default triggers;