UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

71 lines (70 loc) 3.76 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.createInformOfferTasks = createInformOfferTasks; const factory = require("../../../factory"); function createInformOfferTasks(params, setting) { return (repos // settings: Settings ) => __awaiter(this, void 0, void 0, function* () { var _a; if (params.ids.length === 0) { return; } // 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 offers = yield repos.offer.search({ id: { $in: params.ids } }, { typeOf: 1, name: 1, priceSpecification: 1, additionalProperty: 1, identifier: 1, project: 1 }); const offers4inform = offers.map(({ id, typeOf, name, priceSpecification, additionalProperty, identifier, project }) => { return { id, typeOf, name, priceSpecification, additionalProperty, identifier, project }; }); if (offers4inform.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); offers4inform.forEach((offer4inform) => { var _a; const informActionAttributes = { object: offer4inform, 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 }); } } }); }