UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

90 lines (89 loc) 4.51 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.createInformHasPOSTasks = createInformHasPOSTasks; const factory = require("../../../factory"); // import { Settings } from '../../../settings'; function createInformHasPOSTasks(params) { return (repos // settings: Settings ) => __awaiter(this, void 0, void 0, function* () { var _a; if (params.ids.length !== 1) { throw new factory.errors.Argument('id', 'id.length must be 1'); } const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onResourceUpdated']); // 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 movieTheaters = yield repos.movieTheater.projectFields({ limit: 1, page: 1, project: { id: { $eq: params.project.id } }, id: { $eq: params.ids[0] } }, ['id'] // [] ); const movieTheater = movieTheaters.shift(); if (movieTheater === undefined) { throw new factory.errors.NotFound(factory.placeType.MovieTheater); } // 施設のhasPOSを全て連携する repos.hasPOS.operator.id = movieTheater.id; const hasPOS = yield repos.hasPOS.search({ project: { id: { $eq: params.project.id } } }); const movieTheaters4inform = [{ // hasPOS: (Array.isArray(movieTheater.hasPOS)) ? movieTheater.hasPOS : [], hasPOS: (Array.isArray(hasPOS)) ? hasPOS : [], id: movieTheater.id, typeOf: factory.placeType.MovieTheater }]; if (movieTheaters4inform.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); movieTheaters4inform.forEach((movieTheater4inform) => { var _a; const informActionAttributes = { object: movieTheater4inform, 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 }); } } }); }