UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

91 lines (90 loc) 4.58 kB
"use strict"; 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.createInformOfferCatalogTasks = createInformOfferCatalogTasks; exports.onOfferCatalogUpdated = onOfferCatalogUpdated; const factory = require("../../../factory"); const syncOfferCatalog_1 = require("./syncOfferCatalog"); function createInformOfferCatalogTasks(params, setting) { return (repos // settings: Settings ) => __awaiter(this, void 0, void 0, function* () { var _a; if (params.ids.length === 0) { return; } let offerCatalogs = []; if (params.isOfferCatalogItem) { offerCatalogs = yield repos.offerCatalogItem.projectFields({ id: { $in: params.ids } }, ['identifier', 'name', 'numberOfItems', 'project', 'typeOf']); } else { offerCatalogs = yield repos.offerCatalog.projectFields({ id: { $in: params.ids } }, ['identifier', 'name', 'numberOfItems', 'project', 'typeOf']); } // const informResources = settings.onResourceUpdated.informResource; const informResources = (_a = setting === null || setting === void 0 ? void 0 : setting.onResourceUpdated) === null || _a === void 0 ? void 0 : _a.informResource; const offerCatalogs4inform = offerCatalogs.map(({ id, typeOf, name, identifier, project, numberOfItems }) => { return { id, typeOf, name, identifier, project, numberOfItems }; }); if (offerCatalogs4inform.length > 0) { const taskRunsAt = new Date(); const informTasks = []; informResources === null || informResources === void 0 ? void 0 : informResources.forEach((informResource) => { var _a; const informUrl = String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.url); offerCatalogs4inform.forEach((offerCatalog4inform) => { var _a; const informActionAttributes = { object: offerCatalog4inform, recipient: { id: '', name: String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.name), typeOf: factory.creativeWorkType.WebApplication // url: informUrl // discontinue(2025-02-13~) }, target: { httpMethod: 'POST', encodingType: factory.encodingFormat.Application.json, typeOf: 'EntryPoint', urlTemplate: informUrl } }; informTasks.push({ project: { id: params.project.id, typeOf: factory.organizationType.Project }, name: factory.taskName.TriggerWebhook, status: factory.taskStatus.Ready, runsAt: taskRunsAt, remainingNumberOfTries: 10, numberOfTried: 0, executionResults: [], data: informActionAttributes }); }); }); if (informTasks.length > 0) { yield repos.task.saveMany(informTasks, { emitImmediately: true }); } } }); } /** * オファーカタログ変更時処理 */ function onOfferCatalogUpdated(params) { return (repos) => __awaiter(this, void 0, void 0, function* () { yield (0, syncOfferCatalog_1.syncOfferCatalog)({ project: { id: params.project.id }, ids: params.ids, typeOf: params.typeOf, isDeleted: false, isOfferCatalogItem: params.isOfferCatalogItem === true })(repos); }); }