Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 1x 1x 17x 1x 11x 11x 11x 11x 11x 11x 11x 11x 1x 11x 11x 10x 6x 6x 6x 6x 7x 1x | 'use strict';
const _ = require('lodash');
const Logger = use('Logger');
class CreateSystemBooking {
static get key() {
return 'CreateSystemBooking-job';
}
static get concurrency() {
return 1;
}
async handle(job) {
const {
data: { targetSystemStatus, canPayment, ...data },
} = job;
const Config = use('Config');
const configs = Config.get('modules.booking.general');
const namespace = configs.namespace;
const statuses = configs.statuses;
const bookingService = make(`${namespace}/Services/BookingService`);
let booking = await bookingService.getOne({
sourceId: data.sourceId,
systemId: data.systemId,
status: ['NOT_IN', [statuses.cancel]],
});
// sourceIdに紐づくレコードを出力
if (booking) {
Logger.info('CreateSystemBooking.handle currentBooking:', booking.toJSON());
}
const isNotCreated = _.isEmpty(booking);
if (isNotCreated) {
booking = await bookingService.create(data);
// 新規に作成された予約の情報を出力
Eif (booking) {
Logger.info('CreateSystemBooking.handle createdBooking:', booking.toJSON());
}
// remove sourceId from same booking sourceId
await bookingService.updateMany(
{
sourceId: data.sourceId,
systemId: data.systemId,
id: ['NOT_IN', [booking.id]],
},
{ sourceId: null },
);
// sync notes
await bookingService.syncNotes(booking, {
targetSystemStatus,
canPayment,
});
}
return { booking, isNew: isNotCreated };
}
}
module.exports = CreateSystemBooking;
|