@chevre/domain 23.2.0-alpha.21 → 23.2.0-alpha.23
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.
- package/example/src/chevre/place/upsertRoomsByBranchCode.ts +40 -0
- package/example/src/chevre/place/upsertSeatSectionsByBranchCode.ts +56 -0
- package/lib/chevre/repo/mongoose/schemas/place.d.ts +6 -2
- package/lib/chevre/repo/place/movieTheater.d.ts +3 -1
- package/lib/chevre/repo/place/movieTheater.js +4 -2
- package/lib/chevre/repo/place/screeningRoom.d.ts +33 -11
- package/lib/chevre/repo/place/screeningRoom.js +61 -0
- package/lib/chevre/repo/place/section.d.ts +26 -2
- package/lib/chevre/repo/place/section.js +150 -24
- package/package.json +1 -1
- package/example/src/chevre/place/upsertSeatsByBranchCode.ts +0 -72
|
@@ -0,0 +1,40 @@
|
|
|
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 roomRepo = await chevre.repository.place.ScreeningRoom.createInstance(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const result = await roomRepo.upsertRoomsByBranchCode(
|
|
13
|
+
[
|
|
14
|
+
{
|
|
15
|
+
$set: {
|
|
16
|
+
branchCode: 'SAMPLE',
|
|
17
|
+
name: { ja: 'sampleNameJa', 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
|
+
movieTheaterId: '5bfb841d5a78d7948369979a',
|
|
32
|
+
parentOrganization: { id: '59d20831e53ebc2b4e774466' }
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
console.log(result);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
main()
|
|
39
|
+
.then(console.log)
|
|
40
|
+
.catch(console.error);
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
const movieTheaterId = '5bfb841d5a78d7948369979a';
|
|
7
|
+
const sellerId = '59d20831e53ebc2b4e774466';
|
|
8
|
+
const roomCode = '10';
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const sectionRepo = await chevre.repository.place.Section.createInstance(mongoose.connection);
|
|
14
|
+
|
|
15
|
+
let result = await sectionRepo.addSeatSectionsByBranchCodeIfNotExist(
|
|
16
|
+
[
|
|
17
|
+
{
|
|
18
|
+
$set: {
|
|
19
|
+
branchCode: 'SAMPLE',
|
|
20
|
+
name: { ja: 'sampleNameJa', en: 'from samples' },
|
|
21
|
+
additionalProperty: []
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
{
|
|
26
|
+
project: { id: project.id },
|
|
27
|
+
movieTheaterId,
|
|
28
|
+
parentOrganization: { id: sellerId },
|
|
29
|
+
roomCode
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
console.log(result);
|
|
33
|
+
|
|
34
|
+
result = await sectionRepo.updateSeatSectionsByBranchCode(
|
|
35
|
+
[
|
|
36
|
+
{
|
|
37
|
+
$set: {
|
|
38
|
+
branchCode: 'SAMPLE',
|
|
39
|
+
name: { ja: 'sampleNameJaxxx', en: 'from samples' },
|
|
40
|
+
additionalProperty: []
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
{
|
|
45
|
+
project: { id: project.id },
|
|
46
|
+
movieTheaterId,
|
|
47
|
+
parentOrganization: { id: sellerId },
|
|
48
|
+
roomCode
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
console.log(result);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
main()
|
|
55
|
+
.then(console.log)
|
|
56
|
+
.catch(console.error);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
2
|
import * as factory from '../../../factory';
|
|
3
|
-
type
|
|
3
|
+
type ISeatSection = Pick<factory.place.screeningRoomSection.IPlace, 'additionalProperty' | 'branchCode' | 'name' | 'typeOf'> & {
|
|
4
|
+
containsPlace?: factory.place.seat.IPlace[];
|
|
5
|
+
};
|
|
6
|
+
type IDocType = Omit<factory.place.screeningRoom.IPlace, 'containsPlace'> & {
|
|
4
7
|
description?: any;
|
|
5
8
|
openingHoursSpecification?: any;
|
|
6
9
|
smokingAllowed?: boolean;
|
|
10
|
+
containsPlace: ISeatSection[];
|
|
7
11
|
};
|
|
8
12
|
type IModel = Model<IDocType>;
|
|
9
13
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
@@ -11,4 +15,4 @@ type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocT
|
|
|
11
15
|
declare const modelName = "Place";
|
|
12
16
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
13
17
|
declare function createSchema(): ISchema;
|
|
14
|
-
export { createSchema, IModel, indexes, modelName };
|
|
18
|
+
export { createSchema, IDocType, IModel, indexes, modelName };
|
|
@@ -19,7 +19,9 @@ export declare class MovieTheaterRepo {
|
|
|
19
19
|
/**
|
|
20
20
|
* 施設を保管する
|
|
21
21
|
*/
|
|
22
|
-
saveMovieTheater(params: factory.place.movieTheater.IPlace
|
|
22
|
+
saveMovieTheater(params: Pick<factory.place.movieTheater.IPlace, 'additionalProperty' | 'branchCode' | 'hasEntranceGate' | 'id' | 'kanaName' | 'name' | 'offers' | 'parentOrganization' | 'project' | 'typeOf' | 'url'> & {
|
|
23
|
+
hasEntranceGate?: never;
|
|
24
|
+
}): Promise<{
|
|
23
25
|
id: string;
|
|
24
26
|
}>;
|
|
25
27
|
saveMovieTheaterByBranchCode4coa(params: IMovieTheaterIncludingScreeningRooms): Promise<void>;
|
|
@@ -96,13 +96,15 @@ class MovieTheaterRepo {
|
|
|
96
96
|
let savedId;
|
|
97
97
|
let doc;
|
|
98
98
|
if (params.id === '') {
|
|
99
|
-
const { id } = params,
|
|
99
|
+
const { id, hasEntranceGate } = params, // 入場ゲートを保管しない(2026-01-11~)
|
|
100
|
+
creatingParams = __rest(params, ["id", "hasEntranceGate"]); // omit id(2024-09-12~)
|
|
100
101
|
doc = yield this.civicStructureModel.create(creatingParams);
|
|
101
102
|
savedId = doc.id;
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
105
|
// 上書き禁止属性を除外(2022-08-24~)
|
|
105
|
-
const { id, branchCode, project, typeOf } = params,
|
|
106
|
+
const { id, branchCode, project, typeOf, hasEntranceGate } = params, // 入場ゲートを保管しない(2026-01-11~)
|
|
107
|
+
updateFields = __rest(params, ["id", "branchCode", "project", "typeOf", "hasEntranceGate"]);
|
|
106
108
|
doc = yield this.civicStructureModel.findOneAndUpdate({ _id: { $eq: params.id } }, updateFields, { upsert: false, new: true, projection: { _id: 1 } })
|
|
107
109
|
.exec();
|
|
108
110
|
savedId = params.id;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BulkWriteResult } from 'mongodb';
|
|
2
|
+
import { Connection, FilterQuery, PipelineStage } from 'mongoose';
|
|
2
3
|
import * as factory from '../../factory';
|
|
4
|
+
import { IDocType } from '../mongoose/schemas/place';
|
|
3
5
|
export type IScreeningRoomFoundByBranchCode = Pick<factory.place.screeningRoom.IPlace, 'typeOf' | 'branchCode' | 'name' | 'containsPlace' | 'seatCount' | 'parentOrganization'>;
|
|
4
6
|
type IMatchStage = PipelineStage.Match;
|
|
7
|
+
type IUpsertingRoom = Pick<factory.place.screeningRoom.IPlace, 'additionalProperty' | 'address' | 'branchCode' | 'name' | 'openSeatingAllowed'>;
|
|
5
8
|
interface IUpdateOptions {
|
|
6
9
|
project: {
|
|
7
10
|
id: string;
|
|
@@ -11,6 +14,15 @@ interface IUpdateOptions {
|
|
|
11
14
|
};
|
|
12
15
|
movieTheaterCode: string;
|
|
13
16
|
}
|
|
17
|
+
interface IUpsertOptions {
|
|
18
|
+
project: {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
parentOrganization?: {
|
|
22
|
+
id?: string;
|
|
23
|
+
};
|
|
24
|
+
movieTheaterId: string;
|
|
25
|
+
}
|
|
14
26
|
/**
|
|
15
27
|
* ルーム編集時レスポンス
|
|
16
28
|
*/
|
|
@@ -43,6 +55,18 @@ export declare class ScreeningRoomRepo {
|
|
|
43
55
|
};
|
|
44
56
|
containedInPlace: Pick<factory.place.screeningRoom.IContainedInPlace, 'id' | 'name'>;
|
|
45
57
|
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* コードをキーにして冪等作成
|
|
60
|
+
* 2026-01-12~
|
|
61
|
+
*/
|
|
62
|
+
upsertRoomsByBranchCode(params: {
|
|
63
|
+
$set: IUpsertingRoom;
|
|
64
|
+
$unset?: {
|
|
65
|
+
[key in keyof IUpsertingRoom]?: 1;
|
|
66
|
+
};
|
|
67
|
+
}[], options: IUpsertOptions): Promise<{
|
|
68
|
+
bulkWriteResult?: BulkWriteResult;
|
|
69
|
+
}>;
|
|
46
70
|
deleteRoomByBranchCode(screeningRoom: {
|
|
47
71
|
/**
|
|
48
72
|
* ルームコード
|
|
@@ -100,24 +124,22 @@ export declare class ScreeningRoomRepo {
|
|
|
100
124
|
id: string;
|
|
101
125
|
};
|
|
102
126
|
}): Promise<void>;
|
|
103
|
-
getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/place/screeningRoom").IPlace & {
|
|
104
|
-
description?: any;
|
|
105
|
-
openingHoursSpecification?: any;
|
|
106
|
-
smokingAllowed?: boolean;
|
|
107
|
-
}> & import("@chevre/factory/lib/place/screeningRoom").IPlace & {
|
|
127
|
+
getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, IDocType> & Omit<import("@chevre/factory/lib/place/screeningRoom").IPlace, "containsPlace"> & {
|
|
108
128
|
description?: any;
|
|
109
129
|
openingHoursSpecification?: any;
|
|
110
130
|
smokingAllowed?: boolean;
|
|
131
|
+
containsPlace: (Pick<import("@chevre/factory/lib/place/screeningRoomSection").IPlace, "name" | "typeOf" | "additionalProperty" | "branchCode"> & {
|
|
132
|
+
containsPlace?: factory.place.seat.IPlace[];
|
|
133
|
+
})[];
|
|
111
134
|
} & {
|
|
112
135
|
_id: import("mongoose").Types.ObjectId;
|
|
113
|
-
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/place/screeningRoom").IPlace & {
|
|
114
|
-
description?: any;
|
|
115
|
-
openingHoursSpecification?: any;
|
|
116
|
-
smokingAllowed?: boolean;
|
|
117
|
-
}> & import("@chevre/factory/lib/place/screeningRoom").IPlace & {
|
|
136
|
+
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, IDocType> & Omit<import("@chevre/factory/lib/place/screeningRoom").IPlace, "containsPlace"> & {
|
|
118
137
|
description?: any;
|
|
119
138
|
openingHoursSpecification?: any;
|
|
120
139
|
smokingAllowed?: boolean;
|
|
140
|
+
containsPlace: (Pick<import("@chevre/factory/lib/place/screeningRoomSection").IPlace, "name" | "typeOf" | "additionalProperty" | "branchCode"> & {
|
|
141
|
+
containsPlace?: factory.place.seat.IPlace[];
|
|
142
|
+
})[];
|
|
121
143
|
} & {
|
|
122
144
|
_id: import("mongoose").Types.ObjectId;
|
|
123
145
|
}>>;
|
|
@@ -278,6 +278,67 @@ class ScreeningRoomRepo {
|
|
|
278
278
|
}
|
|
279
279
|
});
|
|
280
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* コードをキーにして冪等作成
|
|
283
|
+
* 2026-01-12~
|
|
284
|
+
*/
|
|
285
|
+
upsertRoomsByBranchCode(params, options) {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
const { project, parentOrganization, movieTheaterId } = options;
|
|
288
|
+
// 施設存在確認
|
|
289
|
+
const movieTheater = yield this.civicStructureModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.MovieTheater }, 'project.id': { $eq: project.id }, _id: { $eq: movieTheaterId } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
|
|
290
|
+
? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
291
|
+
: undefined), { _id: 0, id: { $toString: '$_id' }, typeOf: 1, branchCode: 1, name: 1, parentOrganization: 1 })
|
|
292
|
+
.lean()
|
|
293
|
+
.exec();
|
|
294
|
+
if (movieTheater === null) {
|
|
295
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
296
|
+
}
|
|
297
|
+
const containedInPlace = {
|
|
298
|
+
id: movieTheater.id,
|
|
299
|
+
typeOf: movieTheater.typeOf,
|
|
300
|
+
branchCode: movieTheater.branchCode,
|
|
301
|
+
name: movieTheater.name
|
|
302
|
+
};
|
|
303
|
+
const bulkWriteOps = [];
|
|
304
|
+
if (Array.isArray(params)) {
|
|
305
|
+
params.forEach(({ $set, $unset }) => {
|
|
306
|
+
const { branchCode } = $set, setFields = __rest($set, ["branchCode"]);
|
|
307
|
+
if (typeof branchCode !== 'string' || branchCode === '') {
|
|
308
|
+
throw new factory.errors.ArgumentNull('branchCode');
|
|
309
|
+
}
|
|
310
|
+
// リソースのユニークネスを保証するfilter
|
|
311
|
+
const filter = {
|
|
312
|
+
typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
313
|
+
'project.id': { $eq: project.id },
|
|
314
|
+
'containedInPlace.id': { $eq: movieTheaterId },
|
|
315
|
+
branchCode: { $eq: branchCode }
|
|
316
|
+
};
|
|
317
|
+
const initialRoom = {
|
|
318
|
+
typeOf: factory.placeType.ScreeningRoom,
|
|
319
|
+
project: { id: project.id, typeOf: factory.organizationType.Project },
|
|
320
|
+
branchCode,
|
|
321
|
+
containedInPlace,
|
|
322
|
+
containsPlace: [],
|
|
323
|
+
parentOrganization: movieTheater.parentOrganization
|
|
324
|
+
};
|
|
325
|
+
const setOnInsert = initialRoom;
|
|
326
|
+
const update = Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined);
|
|
327
|
+
const updateOne = {
|
|
328
|
+
filter,
|
|
329
|
+
update,
|
|
330
|
+
upsert: true
|
|
331
|
+
};
|
|
332
|
+
bulkWriteOps.push({ updateOne });
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
if (bulkWriteOps.length > 0) {
|
|
336
|
+
const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
337
|
+
return { bulkWriteResult };
|
|
338
|
+
}
|
|
339
|
+
return {};
|
|
340
|
+
});
|
|
341
|
+
}
|
|
281
342
|
deleteRoomByBranchCode(screeningRoom, options) {
|
|
282
343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
283
344
|
const { project, parentOrganization, movieTheaterCode } = options;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BulkWriteResult } from 'mongodb';
|
|
1
2
|
import type { Connection, PipelineStage } from 'mongoose';
|
|
2
3
|
import * as factory from '../../factory';
|
|
3
4
|
type IScreeningRoomSectionWithoutContainsPlace = Omit<factory.place.screeningRoomSection.IPlace, 'containsPlace'>;
|
|
@@ -25,6 +26,17 @@ interface IUpdateSectionResult {
|
|
|
25
26
|
};
|
|
26
27
|
typeOf: factory.placeType.ScreeningRoom;
|
|
27
28
|
}
|
|
29
|
+
type IUpsertingSeatSection = Pick<factory.place.screeningRoomSection.IPlace, 'additionalProperty' | 'branchCode' | 'name'>;
|
|
30
|
+
interface IUpsertOptions {
|
|
31
|
+
project: {
|
|
32
|
+
id: string;
|
|
33
|
+
};
|
|
34
|
+
parentOrganization?: {
|
|
35
|
+
id?: string;
|
|
36
|
+
};
|
|
37
|
+
movieTheaterId: string;
|
|
38
|
+
roomCode: string;
|
|
39
|
+
}
|
|
28
40
|
/**
|
|
29
41
|
* セクションリポジトリ
|
|
30
42
|
*/
|
|
@@ -39,9 +51,21 @@ export declare class SectionRepo {
|
|
|
39
51
|
*/
|
|
40
52
|
updateSectionByBranchCode(screeningRoomSection: ICreatingSection, $unset: any, options: IUpdateOptions): Promise<IUpdateSectionResult>;
|
|
41
53
|
/**
|
|
42
|
-
*
|
|
54
|
+
* コードをキーにして冪等追加
|
|
55
|
+
*/
|
|
56
|
+
addSeatSectionsByBranchCodeIfNotExist(params: {
|
|
57
|
+
$set: IUpsertingSeatSection;
|
|
58
|
+
}[], options: IUpsertOptions): Promise<{
|
|
59
|
+
bulkWriteResult?: BulkWriteResult;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* コードをキーにして冪等編集
|
|
43
63
|
*/
|
|
44
|
-
|
|
64
|
+
updateSeatSectionsByBranchCode(params: {
|
|
65
|
+
$set: IUpsertingSeatSection;
|
|
66
|
+
}[], options: IUpsertOptions): Promise<{
|
|
67
|
+
bulkWriteResult?: BulkWriteResult;
|
|
68
|
+
}>;
|
|
45
69
|
migrateSectionIdentifier(screeningRoomSection: {
|
|
46
70
|
project: {
|
|
47
71
|
id: string;
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
exports.SectionRepo = void 0;
|
|
13
24
|
const factory = require("../../factory");
|
|
@@ -192,38 +203,153 @@ class SectionRepo {
|
|
|
192
203
|
});
|
|
193
204
|
}
|
|
194
205
|
/**
|
|
195
|
-
*
|
|
206
|
+
* コードをキーにして冪等追加
|
|
196
207
|
*/
|
|
197
|
-
|
|
198
|
-
overwriteSeats(screeningRoomSection, options) {
|
|
208
|
+
addSeatSectionsByBranchCodeIfNotExist(params, options) {
|
|
199
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
const { project, parentOrganization,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
210
|
+
const { project, parentOrganization, movieTheaterId, roomCode } = options;
|
|
211
|
+
// ルーム存在確認
|
|
212
|
+
const roomDoc = yield this.placeModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.id': { $eq: movieTheaterId }, branchCode: { $eq: roomCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
|
|
213
|
+
? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
214
|
+
: undefined), { _id: 1 })
|
|
215
|
+
.lean()
|
|
216
|
+
.exec();
|
|
217
|
+
if (roomDoc === null) {
|
|
218
|
+
throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
|
|
204
219
|
}
|
|
205
|
-
|
|
220
|
+
// console.log('roomDoc:', roomDoc);
|
|
221
|
+
const bulkWriteOps = [];
|
|
222
|
+
if (Array.isArray(params)) {
|
|
223
|
+
params.forEach(({ $set }) => {
|
|
224
|
+
var _a, _b;
|
|
225
|
+
const { branchCode } = $set, setFields = __rest($set, ["branchCode"]);
|
|
226
|
+
const filter = {
|
|
227
|
+
typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
228
|
+
'project.id': { $eq: project.id },
|
|
229
|
+
_id: { $eq: roomDoc._id },
|
|
230
|
+
'containsPlace.branchCode': { $ne: branchCode } // セクションコードが存在しなければ追加する
|
|
231
|
+
};
|
|
232
|
+
const pushingSeatSection = Object.assign(Object.assign({ typeOf: factory.placeType.ScreeningRoomSection, 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')
|
|
233
|
+
? { name: setFields.name }
|
|
234
|
+
: undefined), (Array.isArray(setFields.additionalProperty)) ? { additionalProperty: setFields.additionalProperty } : undefined);
|
|
235
|
+
const update = {
|
|
236
|
+
$push: { containsPlace: pushingSeatSection }
|
|
237
|
+
};
|
|
238
|
+
const updateOne = { filter, update };
|
|
239
|
+
bulkWriteOps.push({ updateOne });
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (bulkWriteOps.length > 0) {
|
|
243
|
+
const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
244
|
+
return { bulkWriteResult };
|
|
245
|
+
}
|
|
246
|
+
return {};
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* コードをキーにして冪等編集
|
|
251
|
+
*/
|
|
252
|
+
updateSeatSectionsByBranchCode(params, options) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
const { project, parentOrganization, movieTheaterId, roomCode } = options;
|
|
255
|
+
// ルーム存在確認
|
|
256
|
+
const roomDoc = yield this.placeModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.id': { $eq: movieTheaterId }, branchCode: { $eq: roomCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
|
|
206
257
|
? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
207
|
-
: undefined),
|
|
208
|
-
|
|
209
|
-
'containsPlace.$[screeningRoomSection].containsPlace': containsPlace.map((p) => {
|
|
210
|
-
return Object.assign(Object.assign(Object.assign({ typeOf: p.typeOf, branchCode: p.branchCode }, (p.name !== undefined && p.name !== null) ? { name: p.name } : undefined), (Array.isArray(p.seatingType)) ? { seatingType: p.seatingType } : undefined), (Array.isArray(p.additionalProperty)) ? { additionalProperty: p.additionalProperty } : undefined);
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
: undefined), {
|
|
214
|
-
new: true,
|
|
215
|
-
arrayFilters: [
|
|
216
|
-
{ 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
|
|
217
|
-
],
|
|
218
|
-
projection: { 'containedInPlace.id': 1, typeOf: 1 }
|
|
219
|
-
})
|
|
258
|
+
: undefined), { _id: 1 })
|
|
259
|
+
.lean()
|
|
220
260
|
.exec();
|
|
221
|
-
if (
|
|
222
|
-
throw new factory.errors.NotFound(factory.placeType.
|
|
261
|
+
if (roomDoc === null) {
|
|
262
|
+
throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
|
|
223
263
|
}
|
|
224
|
-
|
|
264
|
+
const bulkWriteOps = [];
|
|
265
|
+
if (Array.isArray(params)) {
|
|
266
|
+
params.forEach(({ $set }) => {
|
|
267
|
+
const { branchCode } = $set, setFields = __rest($set, ["branchCode"]);
|
|
268
|
+
// セクションの存在するドキュメントでフィルター
|
|
269
|
+
const filter = {
|
|
270
|
+
typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
271
|
+
'project.id': { $eq: project.id },
|
|
272
|
+
_id: { $eq: roomDoc._id },
|
|
273
|
+
'containsPlace.branchCode': { $eq: branchCode }
|
|
274
|
+
};
|
|
275
|
+
const update = {
|
|
276
|
+
// 限られた属性のみ更新する
|
|
277
|
+
$set: Object.assign(Object.assign({}, (setFields.name !== undefined && setFields.name !== null)
|
|
278
|
+
? { 'containsPlace.$[seatSection].name': setFields.name }
|
|
279
|
+
: undefined), (Array.isArray(setFields.additionalProperty))
|
|
280
|
+
? { 'containsPlace.$[seatSection].additionalProperty': setFields.additionalProperty }
|
|
281
|
+
: undefined)
|
|
282
|
+
// $unset: {}
|
|
283
|
+
};
|
|
284
|
+
const arrayFilters = [
|
|
285
|
+
{ 'seatSection.branchCode': branchCode }
|
|
286
|
+
];
|
|
287
|
+
const updateOne = { filter, update, arrayFilters };
|
|
288
|
+
bulkWriteOps.push({ updateOne });
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (bulkWriteOps.length > 0) {
|
|
292
|
+
const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
293
|
+
return { bulkWriteResult };
|
|
294
|
+
}
|
|
295
|
+
return {};
|
|
225
296
|
});
|
|
226
297
|
}
|
|
298
|
+
// /**
|
|
299
|
+
// * セクションの座席を上書きする
|
|
300
|
+
// */
|
|
301
|
+
// // tslint:disable-next-line:max-func-body-length
|
|
302
|
+
// public async overwriteSeats(
|
|
303
|
+
// screeningRoomSection: Pick<factory.place.screeningRoomSection.IPlace, 'branchCode' | 'containsPlace'>,
|
|
304
|
+
// options: IUpdateOptions
|
|
305
|
+
// ): Promise<IUpdateSectionResult> {
|
|
306
|
+
// const { project, parentOrganization, movieTheaterCode, roomCode } = options;
|
|
307
|
+
// const { containsPlace } = screeningRoomSection;
|
|
308
|
+
// if (!Array.isArray(containsPlace)) {
|
|
309
|
+
// throw new factory.errors.ArgumentNull('containsPlace');
|
|
310
|
+
// }
|
|
311
|
+
// const doc = await this.placeModel.findOneAndUpdate<HydratedDocument<IUpdateSectionResult>>(
|
|
312
|
+
// {
|
|
313
|
+
// typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
314
|
+
// 'project.id': { $eq: project.id },
|
|
315
|
+
// 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode },
|
|
316
|
+
// branchCode: { $eq: roomCode },
|
|
317
|
+
// 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode },
|
|
318
|
+
// ...(typeof parentOrganization?.id === 'string')
|
|
319
|
+
// ? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
|
|
320
|
+
// : undefined
|
|
321
|
+
// },
|
|
322
|
+
// {
|
|
323
|
+
// // 座席リストが1つ以上指定された場合のみ、上書きする
|
|
324
|
+
// ...(containsPlace.length > 0)
|
|
325
|
+
// ? {
|
|
326
|
+
// 'containsPlace.$[screeningRoomSection].containsPlace':
|
|
327
|
+
// containsPlace.map((p) => {
|
|
328
|
+
// return {
|
|
329
|
+
// typeOf: p.typeOf,
|
|
330
|
+
// branchCode: p.branchCode,
|
|
331
|
+
// ...(p.name !== undefined && p.name !== null) ? { name: p.name } : undefined,
|
|
332
|
+
// ...(Array.isArray(p.seatingType)) ? { seatingType: p.seatingType } : undefined,
|
|
333
|
+
// ...(Array.isArray(p.additionalProperty)) ? { additionalProperty: p.additionalProperty } : undefined
|
|
334
|
+
// };
|
|
335
|
+
// })
|
|
336
|
+
// }
|
|
337
|
+
// : undefined
|
|
338
|
+
// },
|
|
339
|
+
// {
|
|
340
|
+
// new: true,
|
|
341
|
+
// arrayFilters: [
|
|
342
|
+
// { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
|
|
343
|
+
// ],
|
|
344
|
+
// projection: { 'containedInPlace.id': 1, typeOf: 1 }
|
|
345
|
+
// }
|
|
346
|
+
// )
|
|
347
|
+
// .exec();
|
|
348
|
+
// if (doc === null) {
|
|
349
|
+
// throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
|
|
350
|
+
// }
|
|
351
|
+
// return doc.toObject();
|
|
352
|
+
// }
|
|
227
353
|
// tslint:disable-next-line:max-func-body-length
|
|
228
354
|
migrateSectionIdentifier(screeningRoomSection) {
|
|
229
355
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,72 +0,0 @@
|
|
|
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);
|