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

31 lines
943 B
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 { assert } from 'oak-domain/lib/utils/assert';
const triggers = [
{
name: '当loginName类型的applicationPassport创建前将其allowPwd置为ture',
entity: 'applicationPassport',
action: 'create',
when: 'before',
fn: async ({ operation }, context, option) => {
const { data } = operation;
assert(!(data instanceof Array));
const [passport] = await context.select('passport', {
data: {
id: 1,
type: 1,
},
filter: {
id: data?.passportId,
}
}, {
forUpdate: true,
});
const { type } = passport || {};
if (type === 'loginName' && !data.allowPwd) {
data.allowPwd = true;
}
return 1;
}
},
];
export default triggers;