@chevre/domain 23.2.0-alpha.10 → 23.2.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
import { chevre } from '../../../../lib/index';
|
|
4
|
+
|
|
5
|
+
const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
let result = await seatRepo.addSeatsByBranchCodeIfNotExist(
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
$set: {
|
|
16
|
+
branchCode: 'SAMPLE',
|
|
17
|
+
name: { ja: 'from samples', en: 'from samples' },
|
|
18
|
+
additionalProperty: []
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
$set: {
|
|
23
|
+
branchCode: 'SAMPLE2',
|
|
24
|
+
name: { ja: 'from samples2', en: 'from samples' },
|
|
25
|
+
additionalProperty: []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
{
|
|
30
|
+
project: { id: project.id },
|
|
31
|
+
movieTheaterCode: '118',
|
|
32
|
+
roomCode: '10',
|
|
33
|
+
sectionCode: 'Default02'
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
console.log(result);
|
|
37
|
+
|
|
38
|
+
result = await seatRepo.updateSeatsByBranchCode(
|
|
39
|
+
[
|
|
40
|
+
{
|
|
41
|
+
$set: {
|
|
42
|
+
branchCode: 'SAMPLE',
|
|
43
|
+
name: { ja: 'from samples', en: 'from samples' },
|
|
44
|
+
additionalProperty: [],
|
|
45
|
+
maximumAttendeeCapacity: 0
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$set: {
|
|
50
|
+
branchCode: 'SAMPLE2',
|
|
51
|
+
name: { ja: 'from samples2', en: 'from samples' },
|
|
52
|
+
additionalProperty: []
|
|
53
|
+
// maximumAttendeeCapacity: 0
|
|
54
|
+
},
|
|
55
|
+
$unset: {
|
|
56
|
+
maximumAttendeeCapacity: 1
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
{
|
|
61
|
+
project: { id: project.id },
|
|
62
|
+
movieTheaterCode: '118',
|
|
63
|
+
roomCode: '10',
|
|
64
|
+
sectionCode: 'Default02'
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
console.log(result);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
main()
|
|
71
|
+
.then(console.log)
|
|
72
|
+
.catch(console.error);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BulkWriteResult } from 'mongodb';
|
|
2
|
+
import { AnyExpression, Connection, PipelineStage } from 'mongoose';
|
|
2
3
|
import * as factory from '../../factory';
|
|
3
4
|
type IMatchStage = PipelineStage.Match;
|
|
4
5
|
type ICreatingSeat = Pick<factory.place.seat.IPlace, 'additionalProperty' | 'branchCode' | 'name' | 'maximumAttendeeCapacity' | 'seatingType'>;
|
|
@@ -40,6 +41,25 @@ export declare class SeatRepo {
|
|
|
40
41
|
filterTypeOf: boolean;
|
|
41
42
|
}): IMatchStage[];
|
|
42
43
|
createSeat(seat: ICreatingSeat, options: IUpdateOptions): Promise<IUpdateSeatResult>;
|
|
44
|
+
/**
|
|
45
|
+
* コードをキーにして冪等追加
|
|
46
|
+
*/
|
|
47
|
+
addSeatsByBranchCodeIfNotExist(params: {
|
|
48
|
+
$set: ICreatingSeat;
|
|
49
|
+
}[], options: IUpdateOptions): Promise<{
|
|
50
|
+
bulkWriteResult: BulkWriteResult;
|
|
51
|
+
} | void>;
|
|
52
|
+
/**
|
|
53
|
+
* コードをキーにして冪等編集
|
|
54
|
+
*/
|
|
55
|
+
updateSeatsByBranchCode(params: {
|
|
56
|
+
$set: ICreatingSeat;
|
|
57
|
+
$unset?: {
|
|
58
|
+
[key in keyof ICreatingSeat]?: 1;
|
|
59
|
+
};
|
|
60
|
+
}[], options: IUpdateOptions): Promise<{
|
|
61
|
+
bulkWriteResult: BulkWriteResult;
|
|
62
|
+
} | void>;
|
|
43
63
|
updateSeatByBranchCode(seat: ICreatingSeat, $unset: any, options: IUpdateOptions): Promise<IUpdateSeatResult>;
|
|
44
64
|
searchSeats(params: factory.place.seat.ISearchConditions): Promise<factory.place.seat.IPlace[]>;
|
|
45
65
|
projectSeatsByScreeningRoom(params: Pick<factory.place.seat.ISearchConditions, '$projection' | 'additionalProperty' | 'branchCode' | 'seatingType' | 'name' | 'limit' | 'page'> & {
|
|
@@ -267,6 +267,123 @@ class SeatRepo {
|
|
|
267
267
|
return doc.toObject();
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* コードをキーにして冪等追加
|
|
272
|
+
*/
|
|
273
|
+
addSeatsByBranchCodeIfNotExist(params, options) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
const { project, parentOrganization, movieTheaterCode, roomCode, sectionCode } = options;
|
|
276
|
+
// 施設存在確認
|
|
277
|
+
const movieTheaterDoc = yield this.civicStructureModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.MovieTheater }, 'project.id': { $eq: project.id }, branchCode: { $eq: movieTheaterCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
|
|
278
|
+
? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
279
|
+
: undefined), { _id: 1 })
|
|
280
|
+
.lean()
|
|
281
|
+
.exec();
|
|
282
|
+
if (movieTheaterDoc === null) {
|
|
283
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
284
|
+
}
|
|
285
|
+
const bulkWriteOps = [];
|
|
286
|
+
if (Array.isArray(params)) {
|
|
287
|
+
// セクションの存在するドキュメントでフィルター
|
|
288
|
+
const filter = {
|
|
289
|
+
typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
290
|
+
'project.id': { $eq: project.id },
|
|
291
|
+
'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode },
|
|
292
|
+
branchCode: { $eq: roomCode },
|
|
293
|
+
'containsPlace.branchCode': { $eq: sectionCode }
|
|
294
|
+
};
|
|
295
|
+
params.forEach(({ $set }) => {
|
|
296
|
+
var _a, _b;
|
|
297
|
+
const setFields = __rest($set, []);
|
|
298
|
+
const pushingSeat = Object.assign(Object.assign(Object.assign(Object.assign({ typeOf: factory.placeType.Seat, branchCode: setFields.branchCode }, (typeof ((_a = setFields.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = setFields.name) === null || _b === void 0 ? void 0 : _b.en) === 'string')
|
|
299
|
+
? { name: setFields.name }
|
|
300
|
+
: undefined), (Array.isArray(setFields.seatingType)) ? { seatingType: setFields.seatingType } : undefined), (Array.isArray(setFields.additionalProperty)) ? { additionalProperty: setFields.additionalProperty } : undefined), (setFields.maximumAttendeeCapacity === 0)
|
|
301
|
+
? { maximumAttendeeCapacity: setFields.maximumAttendeeCapacity }
|
|
302
|
+
: undefined);
|
|
303
|
+
const updateFilter = {
|
|
304
|
+
$push: { 'containsPlace.$[screeningRoomSection].containsPlace': pushingSeat }
|
|
305
|
+
};
|
|
306
|
+
const arrayFilters = [
|
|
307
|
+
{
|
|
308
|
+
'screeningRoomSection.branchCode': { $eq: sectionCode }, // セクションに
|
|
309
|
+
'screeningRoomSection.containsPlace.branchCode': { $ne: pushingSeat.branchCode } // 座席が存在しなければ
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
const updateOne = {
|
|
313
|
+
filter,
|
|
314
|
+
update: updateFilter,
|
|
315
|
+
arrayFilters
|
|
316
|
+
};
|
|
317
|
+
bulkWriteOps.push({ updateOne });
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (bulkWriteOps.length > 0) {
|
|
321
|
+
const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
322
|
+
return { bulkWriteResult };
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* コードをキーにして冪等編集
|
|
328
|
+
*/
|
|
329
|
+
updateSeatsByBranchCode(params, options) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
const { project, parentOrganization, movieTheaterCode, roomCode, sectionCode } = options;
|
|
332
|
+
const bulkWriteOps = [];
|
|
333
|
+
if (Array.isArray(params)) {
|
|
334
|
+
params.forEach(({ $set, $unset }) => {
|
|
335
|
+
var _a, _b;
|
|
336
|
+
// 座席の存在するドキュメントでフィルター
|
|
337
|
+
const filter = Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode }, branchCode: { $eq: roomCode }, 'containsPlace.branchCode': { $eq: sectionCode }, 'containsPlace.containsPlace.branchCode': { $eq: $set.branchCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
|
|
338
|
+
? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
339
|
+
: undefined);
|
|
340
|
+
const setFields = __rest($set, []);
|
|
341
|
+
const updateFilter = {
|
|
342
|
+
$set: Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].branchCode': setFields.branchCode }, (typeof ((_a = setFields.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = setFields.name) === null || _b === void 0 ? void 0 : _b.en) === 'string')
|
|
343
|
+
? {
|
|
344
|
+
'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': setFields.name
|
|
345
|
+
}
|
|
346
|
+
: undefined), (Array.isArray(setFields.seatingType))
|
|
347
|
+
? {
|
|
348
|
+
'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': setFields.seatingType
|
|
349
|
+
}
|
|
350
|
+
: undefined), (Array.isArray(setFields.additionalProperty))
|
|
351
|
+
? {
|
|
352
|
+
// tslint:disable-next-line:max-line-length
|
|
353
|
+
'containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': setFields.additionalProperty
|
|
354
|
+
}
|
|
355
|
+
: undefined), (setFields.maximumAttendeeCapacity === 0)
|
|
356
|
+
? {
|
|
357
|
+
// tslint:disable-next-line:max-line-length
|
|
358
|
+
'containsPlace.$[screeningRoomSection].containsPlace.$[seat].maximumAttendeeCapacity': setFields.maximumAttendeeCapacity
|
|
359
|
+
}
|
|
360
|
+
: undefined),
|
|
361
|
+
$unset: Object.assign(Object.assign(Object.assign({}, (($unset === null || $unset === void 0 ? void 0 : $unset.name) === 1)
|
|
362
|
+
? { 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': 1 }
|
|
363
|
+
: undefined), (($unset === null || $unset === void 0 ? void 0 : $unset.seatingType) === 1)
|
|
364
|
+
? { 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': 1 }
|
|
365
|
+
: undefined), (($unset === null || $unset === void 0 ? void 0 : $unset.maximumAttendeeCapacity) === 1)
|
|
366
|
+
? { 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].maximumAttendeeCapacity': 1 }
|
|
367
|
+
: undefined)
|
|
368
|
+
};
|
|
369
|
+
const arrayFilters = [
|
|
370
|
+
{ 'screeningRoomSection.branchCode': { $eq: sectionCode } },
|
|
371
|
+
{ 'seat.branchCode': { $eq: setFields.branchCode } }
|
|
372
|
+
];
|
|
373
|
+
const updateOne = {
|
|
374
|
+
filter,
|
|
375
|
+
update: updateFilter,
|
|
376
|
+
arrayFilters
|
|
377
|
+
};
|
|
378
|
+
bulkWriteOps.push({ updateOne });
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
if (bulkWriteOps.length > 0) {
|
|
382
|
+
const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
383
|
+
return { bulkWriteResult };
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
270
387
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
271
388
|
updateSeatByBranchCode(seat, $unset, options) {
|
|
272
389
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED