45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const tslib_1 = require("tslib");
|
||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
||
const crypto_1 = require("crypto");
|
||
const triggers = [
|
||
{
|
||
name: "创建oauth app时,填充数据",
|
||
action: "create",
|
||
when: "before",
|
||
entity: "oauthApplication",
|
||
fn: async ({ operation }, context) => {
|
||
(0, assert_1.default)(operation.data && !Array.isArray(operation.data), "oauthApplication create data 必须存在且为单条记录");
|
||
const { data } = operation;
|
||
const systemId = context.getSystemId();
|
||
data.systemId = systemId;
|
||
data.clientSecret = (0, crypto_1.randomUUID)();
|
||
return 0; // 没有引起数据库行修改
|
||
}
|
||
},
|
||
{
|
||
name: "更新apps的secret",
|
||
action: "resetSecret",
|
||
when: "before",
|
||
entity: "oauthApplication",
|
||
fn: async ({ operation }, context) => {
|
||
const { filter } = operation;
|
||
(0, assert_1.default)(filter && filter.id, "resetSecret 操作必须指定 filter.id");
|
||
const opRes = await context.operate("oauthApplication", {
|
||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||
action: "update",
|
||
data: {
|
||
clientSecret: (0, crypto_1.randomUUID)(),
|
||
},
|
||
filter: {
|
||
id: filter.id,
|
||
}
|
||
}, {});
|
||
return opRes;
|
||
}
|
||
},
|
||
];
|
||
exports.default = triggers;
|