@chevre/domain 23.2.0-alpha.21 → 23.2.0-alpha.22

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,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);
@@ -11,4 +11,4 @@ type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocT
11
11
  declare const modelName = "Place";
12
12
  declare const indexes: [d: IndexDefinition, o: IndexOptions][];
13
13
  declare function createSchema(): ISchema;
14
- export { createSchema, IModel, indexes, modelName };
14
+ 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): Promise<{
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, creatingParams = __rest(params, ["id"]); // omit id(2024-09-12~)
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, updateFields = __rest(params, ["id", "branchCode", "project", "typeOf"]);
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 { Connection, FilterQuery, PipelineStage } from 'mongoose';
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,21 +124,13 @@ 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> & import("@chevre/factory/lib/place/screeningRoom").IPlace & {
108
128
  description?: any;
109
129
  openingHoursSpecification?: any;
110
130
  smokingAllowed?: boolean;
111
131
  } & {
112
132
  _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 & {
133
+ }, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, IDocType> & import("@chevre/factory/lib/place/screeningRoom").IPlace & {
118
134
  description?: any;
119
135
  openingHoursSpecification?: any;
120
136
  smokingAllowed?: boolean;
@@ -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;
package/package.json CHANGED
@@ -116,5 +116,5 @@
116
116
  "postversion": "git push origin --tags",
117
117
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
118
118
  },
119
- "version": "23.2.0-alpha.21"
119
+ "version": "23.2.0-alpha.22"
120
120
  }
@@ -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);