@chevre/domain
Version:
Chevre Domain Library for Node.js
54 lines (53 loc) • 2.54 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncCategoryCode = syncCategoryCode;
const factory = require("../../../factory");
/**
* 区分を他リソースへ同期する
*/
function syncCategoryCode(params) {
return (repos) => __awaiter(this, void 0, void 0, function* () {
if (params.isDeleted) {
for (const categoryCodeId of params.ids) {
// プロダクトモデルを削除
yield repos.productModel.deleteByCategory({
category: {
project: { id: params.project.id, typeOf: factory.organizationType.Project },
id: categoryCodeId
}
});
}
}
else {
for (const categoryCodeId of params.ids) {
const syncingCategoryCode = (yield repos.categoryCode.projectFields({
limit: 1,
page: 1,
project: { id: { $eq: params.project.id } },
id: { $eq: categoryCodeId }
}, ['codeValue', 'inCodeSet', 'name', 'project', 'id'])).shift();
if (syncingCategoryCode !== undefined) {
switch (syncingCategoryCode.inCodeSet.identifier) {
case factory.categoryCode.CategorySetIdentifier.SeatingType:
// プロダクトモデルへ同期
yield repos.productModel.upsertByCategory({
category: Object.assign(Object.assign({}, syncingCategoryCode), { id: categoryCodeId })
});
break;
default:
// no op
}
}
}
}
});
}
;