@chevre/domain 20.2.0-alpha.35 → 20.2.0-alpha.37

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.
@@ -67,7 +67,19 @@ export declare class MongoRepository {
67
67
  /**
68
68
  * 複数イベントを作成する
69
69
  */
70
- createMany<T extends factory.eventType>(params: factory.event.IAttributes<T>[]): Promise<factory.event.IEvent<T>[]>;
70
+ createMany<T extends factory.eventType>(params: {
71
+ attributes: factory.event.IAttributes<T>[];
72
+ expectsNoContent: boolean;
73
+ }): Promise<factory.event.IEvent<T>[] | void>;
74
+ /**
75
+ * 特定の追加特性をキーにして、なければ作成する(複数対応)
76
+ */
77
+ createIfNotExistMany<T extends factory.eventType.ScreeningEvent>(params: {
78
+ attributes: factory.event.IAttributes<T>;
79
+ filter: {
80
+ name: string;
81
+ };
82
+ }[]): Promise<void>;
71
83
  /**
72
84
  * イベント部分更新
73
85
  */
@@ -85,10 +97,10 @@ export declare class MongoRepository {
85
97
  upsert?: boolean;
86
98
  }): Promise<factory.event.IEvent<T>>;
87
99
  saveMany<T extends factory.eventType>(params: {
88
- id?: string;
100
+ id: string;
89
101
  attributes: factory.event.IAttributes<T>;
90
102
  $unset?: IProjection;
91
- upsert?: boolean;
103
+ upsert: boolean;
92
104
  }[]): Promise<void>;
93
105
  save4ttts(params: {
94
106
  oldEventId: string;
@@ -448,12 +448,53 @@ class MongoRepository {
448
448
  */
449
449
  createMany(params) {
450
450
  return __awaiter(this, void 0, void 0, function* () {
451
- const docs = yield this.eventModel.insertMany(params.map((p) => {
451
+ const docs = yield this.eventModel.insertMany(params.attributes.map((p) => {
452
452
  return Object.assign({ _id: uniqid() }, p);
453
453
  }));
454
+ if (params.expectsNoContent) {
455
+ return;
456
+ }
454
457
  return docs.map((doc) => doc.toObject());
455
458
  });
456
459
  }
460
+ /**
461
+ * 特定の追加特性をキーにして、なければ作成する(複数対応)
462
+ */
463
+ createIfNotExistMany(params) {
464
+ return __awaiter(this, void 0, void 0, function* () {
465
+ const bulkWriteOps = [];
466
+ if (Array.isArray(params)) {
467
+ params.forEach((creatingEventParams) => {
468
+ var _a;
469
+ if (creatingEventParams.attributes.typeOf === factory.eventType.ScreeningEvent) {
470
+ const additionalPropertyValue = (_a = creatingEventParams.attributes.additionalProperty) === null || _a === void 0 ? void 0 : _a.find((property) => property.name === creatingEventParams.filter.name);
471
+ if (typeof additionalPropertyValue !== 'string') {
472
+ throw new factory.errors.NotFound('additionalProperty.value');
473
+ }
474
+ bulkWriteOps.push({
475
+ updateOne: {
476
+ filter: {
477
+ typeOf: creatingEventParams.attributes.typeOf,
478
+ // 追加特性をキーに更新
479
+ additionalProperty: {
480
+ $exists: true,
481
+ $all: [{ name: creatingEventParams.filter.name, value: additionalPropertyValue }]
482
+ }
483
+ },
484
+ update: {
485
+ $setOnInsert: Object.assign({ _id: uniqid() }, creatingEventParams.attributes)
486
+ },
487
+ upsert: true
488
+ }
489
+ });
490
+ }
491
+ });
492
+ }
493
+ if (bulkWriteOps.length > 0) {
494
+ yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
495
+ }
496
+ });
497
+ }
457
498
  /**
458
499
  * イベント部分更新
459
500
  */
@@ -507,52 +548,40 @@ class MongoRepository {
507
548
  const bulkWriteOps = [];
508
549
  if (Array.isArray(params)) {
509
550
  params.forEach((p) => {
510
- if (p.id === undefined) {
511
- const id = uniqid();
551
+ const upsert = p.upsert === true;
552
+ if (p.attributes.typeOf === factory.eventType.ScreeningEvent) {
553
+ // 上書き禁止属性を除外(2022-08-24~)
554
+ const _a = p.attributes, { identifier, project, typeOf, remainingAttendeeCapacity } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "remainingAttendeeCapacity"]);
512
555
  bulkWriteOps.push({
513
- insertOne: {
514
- document: Object.assign(Object.assign({}, p.attributes), { _id: id })
556
+ updateOne: {
557
+ filter: {
558
+ _id: p.id,
559
+ typeOf: p.attributes.typeOf
560
+ },
561
+ // upsertの場合、createがありうるので属性を除外しない
562
+ update: Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: p.attributes.typeOf, project: p.attributes.project }, (typeof p.attributes.identifier === 'string')
563
+ ? { identifier: p.attributes.identifier } : undefined), (typeof p.attributes.remainingAttendeeCapacity === 'number')
564
+ ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
565
+ : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
566
+ upsert
515
567
  }
516
568
  });
517
569
  }
518
- else {
519
- const upsert = p.upsert === true;
520
- if (p.attributes.typeOf === factory.eventType.ScreeningEvent) {
521
- // 上書き禁止属性を除外(2022-08-24~)
522
- const _a = p.attributes, { identifier, project, typeOf, remainingAttendeeCapacity } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "remainingAttendeeCapacity"]);
523
- bulkWriteOps.push({
524
- updateOne: {
525
- filter: {
526
- _id: p.id,
527
- typeOf: p.attributes.typeOf
528
- },
529
- // upsertの場合、createがありうるので属性を除外しない
530
- update: Object.assign({ $setOnInsert: Object.assign(Object.assign(Object.assign({ typeOf: p.attributes.typeOf }, (p.attributes.project !== undefined)
531
- ? { project: p.attributes.project } : undefined), (p.attributes.identifier !== undefined)
532
- ? { identifier: p.attributes.identifier } : undefined), (typeof p.attributes.remainingAttendeeCapacity === 'number')
533
- ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
534
- : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
535
- upsert
536
- }
537
- });
538
- }
539
- else if (p.attributes.typeOf === factory.eventType.ScreeningEventSeries) {
540
- // 上書き禁止属性を除外(2022-08-24~)
541
- const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
542
- bulkWriteOps.push({
543
- updateOne: {
544
- filter: {
545
- _id: p.id,
546
- typeOf: p.attributes.typeOf
547
- },
548
- // upsertの場合、createがありうるので属性を除外しない
549
- update: Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: p.attributes.typeOf }, (p.attributes.project !== undefined)
550
- ? { project: p.attributes.project } : undefined), (p.attributes.identifier !== undefined)
551
- ? { identifier: p.attributes.identifier } : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
552
- upsert
553
- }
554
- });
555
- }
570
+ else if (p.attributes.typeOf === factory.eventType.ScreeningEventSeries) {
571
+ // 上書き禁止属性を除外(2022-08-24~)
572
+ const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
573
+ bulkWriteOps.push({
574
+ updateOne: {
575
+ filter: {
576
+ _id: p.id,
577
+ typeOf: p.attributes.typeOf
578
+ },
579
+ // upsertの場合、createがありうるので属性を除外しない
580
+ update: Object.assign({ $setOnInsert: Object.assign({ typeOf: p.attributes.typeOf, project: p.attributes.project }, (typeof p.attributes.identifier === 'string')
581
+ ? { identifier: p.attributes.identifier } : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
582
+ upsert
583
+ }
584
+ });
556
585
  }
557
586
  });
558
587
  }
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.35"
123
+ "version": "20.2.0-alpha.37"
124
124
  }