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