@chevre/domain
Version:
Chevre Domain Library for Node.js
88 lines (87 loc) • 5.64 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.onReservationCheckedIn = onReservationCheckedIn;
/**
* 予約発券時アクション
*/
const factory = require("../../../factory");
const factory_1 = require("../factory");
function onReservationCheckedIn(params) {
// tslint:disable-next-line:max-func-body-length
return (repos) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
const { dateIssued } = params.object.reservedTicket;
const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onReservationStatusChanged']);
const tasks = [];
const project = { id: params.project.id, typeOf: factory.organizationType.Project };
const informReservations = (_a = setting === null || setting === void 0 ? void 0 : setting.onReservationStatusChanged) === null || _a === void 0 ? void 0 : _a.informReservation;
let reservations4inform = [];
const ticketToken = (_b = params.purpose) === null || _b === void 0 ? void 0 : _b.code;
if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
reservations4inform = params.object.ids.map((reservationId, index) => {
return Object.assign(Object.assign({ typeOf: factory.reservationType.EventReservation, project, id: reservationId, checkedIn: true }, (dateIssued instanceof Date) ? { modifiedTime: dateIssued } : undefined), (index === 0 && typeof ticketToken === 'string') ? { reservedTicket: { ticketToken } } : undefined);
});
}
if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
// ReservationPackageへ変更(2024-11-03~)
reservations4inform = yield Promise.all(params.object.reservationNumbers.map((reservationNumber, index) => __awaiter(this, void 0, void 0, function* () {
const subReservationIds = yield repos.reservation.searchIdsByReservationNumber({
reservationNumber: { $in: [reservationNumber] }
});
return Object.assign(Object.assign({ typeOf: factory.reservationType.ReservationPackage, project,
reservationNumber, checkedIn: true, subReservation: subReservationIds.map((id) => ({ id })) }, (dateIssued instanceof Date) ? { modifiedTime: dateIssued } : undefined), (index === 0 && typeof ticketToken === 'string') ? { reservedTicket: { ticketToken } } : undefined);
})));
}
if (reservations4inform.length > 0) {
const informTaskRunsAt = new Date();
// inform galobally
if (Array.isArray(informReservations)) {
let orderAsAbout;
if (typeof params.instrument.orderNumber === 'string') {
orderAsAbout = { orderNumber: params.instrument.orderNumber, typeOf: factory.order.OrderType.Order };
}
informReservations.forEach((informReservation) => {
var _a, _b;
const informUrl = String((_a = informReservation.recipient) === null || _a === void 0 ? void 0 : _a.url);
const recipientName = (_b = informReservation.recipient) === null || _b === void 0 ? void 0 : _b.name;
const informReservationAttributes = Object.assign({ object: reservations4inform, recipient: {
id: '',
name: (typeof recipientName === 'string') ? recipientName : 'unknown', // redefine name(2025-02-17~)
typeOf: factory.creativeWorkType.WebApplication
// url: informUrl // discontinue(2025-02-13~)
}, target: {
httpMethod: 'POST',
encodingType: factory.encodingFormat.Application.json,
typeOf: 'EntryPoint',
urlTemplate: informUrl
} }, (orderAsAbout !== undefined) ? { about: orderAsAbout } : undefined // add about(2025-02-19~)
);
const informReservationTask = {
project,
name: factory.taskName.TriggerWebhook,
status: factory.taskStatus.Ready,
runsAt: informTaskRunsAt,
remainingNumberOfTries: factory_1.NUM_TRY_INFORM_RESERVATION,
numberOfTried: 0,
executionResults: [],
data: informReservationAttributes
};
tasks.push(informReservationTask);
});
}
}
if (tasks.length > 0) {
yield repos.task.saveMany(tasks, { emitImmediately: true });
}
// create AggregateScreeningEvent task -> migrate to agg(2024-10-29~)
});
}
;