@chevre/domain 23.2.0-alpha.22 → 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.
@@ -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 IDocType = factory.place.screeningRoom.IPlace & {
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>;
@@ -124,16 +124,22 @@ export declare class ScreeningRoomRepo {
124
124
  id: string;
125
125
  };
126
126
  }): Promise<void>;
127
- getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, IDocType> & 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"> & {
128
128
  description?: any;
129
129
  openingHoursSpecification?: any;
130
130
  smokingAllowed?: boolean;
131
+ containsPlace: (Pick<import("@chevre/factory/lib/place/screeningRoomSection").IPlace, "name" | "typeOf" | "additionalProperty" | "branchCode"> & {
132
+ containsPlace?: factory.place.seat.IPlace[];
133
+ })[];
131
134
  } & {
132
135
  _id: import("mongoose").Types.ObjectId;
133
- }, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, IDocType> & 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"> & {
134
137
  description?: any;
135
138
  openingHoursSpecification?: any;
136
139
  smokingAllowed?: boolean;
140
+ containsPlace: (Pick<import("@chevre/factory/lib/place/screeningRoomSection").IPlace, "name" | "typeOf" | "additionalProperty" | "branchCode"> & {
141
+ containsPlace?: factory.place.seat.IPlace[];
142
+ })[];
137
143
  } & {
138
144
  _id: import("mongoose").Types.ObjectId;
139
145
  }>>;
@@ -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
- overwriteSeats(screeningRoomSection: Pick<factory.place.screeningRoomSection.IPlace, 'branchCode' | 'containsPlace'>, options: IUpdateOptions): Promise<IUpdateSectionResult>;
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
- // tslint:disable-next-line:max-func-body-length
198
- overwriteSeats(screeningRoomSection, options) {
208
+ addSeatSectionsByBranchCodeIfNotExist(params, options) {
199
209
  return __awaiter(this, void 0, void 0, function* () {
200
- const { project, parentOrganization, movieTheaterCode, roomCode } = options;
201
- const { containsPlace } = screeningRoomSection;
202
- if (!Array.isArray(containsPlace)) {
203
- throw new factory.errors.ArgumentNull('containsPlace');
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
- const doc = yield this.placeModel.findOneAndUpdate(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode }, branchCode: { $eq: roomCode }, 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
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), Object.assign({}, (containsPlace.length > 0)
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 (doc === null) {
222
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
261
+ if (roomDoc === null) {
262
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
223
263
  }
224
- return doc.toObject();
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
@@ -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.22"
119
+ "version": "23.2.0-alpha.23"
120
120
  }