75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const tslib_1 = require("tslib");
|
|
const uuid_1 = require("oak-domain/lib/utils/uuid");
|
|
const executor_1 = require("oak-domain/lib/utils/executor");
|
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
const checkers = [
|
|
{
|
|
entity: 'withdrawAccount',
|
|
type: 'logical',
|
|
action: 'create',
|
|
checker(operation, context, option) {
|
|
const { data } = operation;
|
|
if (data) {
|
|
const { id, entity, entityId, isDefault } = data;
|
|
if (entity && entityId && isDefault) {
|
|
return context.operate('withdrawAccount', {
|
|
id: (0, uuid_1.generateNewId)(),
|
|
action: 'update',
|
|
data: {
|
|
isDefault: false,
|
|
},
|
|
filter: {
|
|
entity,
|
|
entityId,
|
|
isDefault: true,
|
|
id: {
|
|
$ne: id,
|
|
},
|
|
}
|
|
}, option);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
{
|
|
entity: 'withdrawAccount',
|
|
type: 'logical',
|
|
action: 'update',
|
|
checker(operation, context, option) {
|
|
const { data, filter } = operation;
|
|
if (data?.isDefault) {
|
|
return (0, executor_1.pipeline)(() => context.select('withdrawAccount', {
|
|
data: {
|
|
id: 1,
|
|
entity: 1,
|
|
entityId: 1,
|
|
},
|
|
filter,
|
|
}, {}), (accounts) => {
|
|
(0, assert_1.default)(accounts.length === 1);
|
|
const [account] = accounts;
|
|
const { entity, entityId, id } = account;
|
|
return context.operate('withdrawAccount', {
|
|
id: (0, uuid_1.generateNewId)(),
|
|
action: 'update',
|
|
data: {
|
|
isDefault: false,
|
|
},
|
|
filter: {
|
|
entity,
|
|
entityId,
|
|
isDefault: true,
|
|
id: {
|
|
$ne: id,
|
|
},
|
|
}
|
|
}, option);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
];
|
|
exports.default = checkers;
|