80 lines
3.0 KiB
JavaScript
80 lines
3.0 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const types_1 = require("oak-domain/lib/types");
|
|
const assert_1 = require("oak-domain/lib/utils/assert");
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
const executor_1 = require("oak-domain/lib/utils/executor");
|
|
const checkers = [
|
|
{
|
|
type: 'data',
|
|
action: 'create',
|
|
entity: 'userEntityGrant',
|
|
checker: (data) => {
|
|
if (data instanceof Array) {
|
|
data.forEach((ele) => {
|
|
if (!ele.relationIds || ele.relationIds.length === 0) {
|
|
throw new types_1.OakInputIllegalException('userEntityGrant', ['relationIds'], '至少应选择一个关系');
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
if (!data.relationIds || data.relationIds.length === 0) {
|
|
throw new types_1.OakInputIllegalException('userEntityGrant', ['relationIds'], '至少应选择一个关系');
|
|
}
|
|
}
|
|
},
|
|
},
|
|
{
|
|
type: 'row',
|
|
entity: 'userEntityGrant',
|
|
action: 'claim',
|
|
filter: {
|
|
expired: false,
|
|
},
|
|
},
|
|
{
|
|
type: 'logical',
|
|
entity: 'userEntityGrant',
|
|
action: 'claim',
|
|
checker: (operation, context, option) => {
|
|
const { data, filter } = operation;
|
|
// assert(Object.keys(data).length === 1 && data.hasOwnProperty('userEntityClaim$ueg'));
|
|
(0, assert_1.assert)(data.hasOwnProperty('userEntityClaim$ueg'));
|
|
const { userEntityClaim$ueg } = data;
|
|
(0, assert_1.assert)(filter.id);
|
|
(0, assert_1.assert)(userEntityClaim$ueg instanceof Array);
|
|
const dealInner = (userEntityGrant) => {
|
|
const { relationEntity } = userEntityGrant;
|
|
userEntityClaim$ueg.forEach((uec) => {
|
|
const { action, data } = uec;
|
|
(0, assert_1.assert)(action === 'create');
|
|
const { userId, relationId, claimEntityId } = data;
|
|
Object.assign(data, {
|
|
userRelation: {
|
|
id: (0, uuid_1.generateNewId)(),
|
|
action: 'create',
|
|
data: {
|
|
id: (0, uuid_1.generateNewId)(),
|
|
userId,
|
|
relationId,
|
|
entityId: claimEntityId,
|
|
entity: relationEntity,
|
|
}
|
|
}
|
|
});
|
|
});
|
|
return userEntityClaim$ueg.length;
|
|
};
|
|
return (0, executor_1.pipeline)(() => context.select('userEntityGrant', {
|
|
data: {
|
|
id: 1,
|
|
relationEntity: 1,
|
|
multiple: 1,
|
|
},
|
|
filter,
|
|
}, option), ([ueg]) => dealInner(ueg));
|
|
}
|
|
}
|
|
];
|
|
exports.default = checkers;
|