@chevre/domain 21.0.0-alpha.12 → 21.0.0-alpha.14
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.
|
@@ -105,6 +105,12 @@ export declare class MongoRepository {
|
|
|
105
105
|
name: string;
|
|
106
106
|
};
|
|
107
107
|
}[]): Promise<BulkWriteOpResultObject | void>;
|
|
108
|
+
/**
|
|
109
|
+
* コンテンツ+バージョンをキーにして、なければ作成する(複数対応)
|
|
110
|
+
*/
|
|
111
|
+
createScreeningEventSeriesIfNotExistByWorkPerformed(params: {
|
|
112
|
+
attributes: factory.event.IAttributes<factory.eventType.ScreeningEventSeries>;
|
|
113
|
+
}[]): Promise<BulkWriteOpResultObject | void>;
|
|
108
114
|
/**
|
|
109
115
|
* イベント部分更新
|
|
110
116
|
*/
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -25,6 +25,7 @@ const uniqid = require("uniqid");
|
|
|
25
25
|
const factory = require("../factory");
|
|
26
26
|
const onIndexCreated_1 = require("./mongoose/onIndexCreated");
|
|
27
27
|
const event_1 = require("./mongoose/schemas/event");
|
|
28
|
+
const errorHandler_1 = require("../errorHandler");
|
|
28
29
|
exports.PROJECTION_MINIMIZED_EVENT = {
|
|
29
30
|
project: 1,
|
|
30
31
|
_id: 1,
|
|
@@ -503,6 +504,52 @@ class MongoRepository {
|
|
|
503
504
|
}
|
|
504
505
|
});
|
|
505
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* コンテンツ+バージョンをキーにして、なければ作成する(複数対応)
|
|
509
|
+
*/
|
|
510
|
+
createScreeningEventSeriesIfNotExistByWorkPerformed(params) {
|
|
511
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
const bulkWriteOps = [];
|
|
513
|
+
if (Array.isArray(params)) {
|
|
514
|
+
params.forEach((creatingEventParams) => {
|
|
515
|
+
const version = creatingEventParams.attributes.workPerformed.version;
|
|
516
|
+
if (typeof version !== 'string') {
|
|
517
|
+
throw new factory.errors.ArgumentNull('workPerformed.version');
|
|
518
|
+
}
|
|
519
|
+
const setOnInsertFields = creatingEventParams.attributes;
|
|
520
|
+
bulkWriteOps.push({
|
|
521
|
+
updateOne: {
|
|
522
|
+
filter: {
|
|
523
|
+
typeOf: creatingEventParams.attributes.typeOf,
|
|
524
|
+
'project.id': { $eq: creatingEventParams.attributes.project.id },
|
|
525
|
+
'location.branchCode': {
|
|
526
|
+
$exists: true,
|
|
527
|
+
$eq: creatingEventParams.attributes.location.branchCode
|
|
528
|
+
},
|
|
529
|
+
'workPerformed.identifier': {
|
|
530
|
+
$exists: true,
|
|
531
|
+
$eq: creatingEventParams.attributes.workPerformed.identifier
|
|
532
|
+
},
|
|
533
|
+
'workPerformed.version': {
|
|
534
|
+
$exists: true,
|
|
535
|
+
$eq: version
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
update: {
|
|
539
|
+
$setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() })
|
|
540
|
+
// 変更可能な属性のみ上書き
|
|
541
|
+
// $set: {}
|
|
542
|
+
},
|
|
543
|
+
upsert: true
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
if (bulkWriteOps.length > 0) {
|
|
549
|
+
return this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
506
553
|
/**
|
|
507
554
|
* イベント部分更新
|
|
508
555
|
*/
|
|
@@ -529,21 +576,31 @@ class MongoRepository {
|
|
|
529
576
|
save(params) {
|
|
530
577
|
return __awaiter(this, void 0, void 0, function* () {
|
|
531
578
|
let doc;
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
579
|
+
try {
|
|
580
|
+
if (params.id === undefined) {
|
|
581
|
+
const id = uniqid();
|
|
582
|
+
doc = yield this.eventModel.create(Object.assign(Object.assign({}, params.attributes), { _id: id }));
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
const upsert = params.upsert === true;
|
|
586
|
+
// 上書き禁止属性を除外(2022-08-24~)
|
|
587
|
+
const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
|
|
588
|
+
doc = yield this.eventModel.findOneAndUpdate({
|
|
589
|
+
_id: params.id,
|
|
590
|
+
typeOf: params.attributes.typeOf
|
|
591
|
+
}, Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: params.attributes.typeOf }, (params.attributes.project !== undefined)
|
|
592
|
+
? { project: params.attributes.project } : undefined), (params.attributes.identifier !== undefined)
|
|
593
|
+
? { identifier: params.attributes.identifier } : undefined), $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert, new: true })
|
|
594
|
+
.exec();
|
|
595
|
+
}
|
|
535
596
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}, Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: params.attributes.typeOf }, (params.attributes.project !== undefined)
|
|
544
|
-
? { project: params.attributes.project } : undefined), (params.attributes.identifier !== undefined)
|
|
545
|
-
? { identifier: params.attributes.identifier } : undefined), $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert, new: true })
|
|
546
|
-
.exec();
|
|
597
|
+
catch (error) {
|
|
598
|
+
if ((0, errorHandler_1.isMongoError)(error)) {
|
|
599
|
+
if (error.code === errorHandler_1.MongoErrorCode.DuplicateKey) {
|
|
600
|
+
throw new factory.errors.AlreadyInUse(factory.eventType.ScreeningEventSeries, ['workPerformed.version']);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
throw error;
|
|
547
604
|
}
|
|
548
605
|
if (doc === null) {
|
|
549
606
|
throw new factory.errors.NotFound(this.eventModel.modelName);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.schema = exports.modelName = void 0;
|
|
4
4
|
const mongoose_1 = require("mongoose");
|
|
5
5
|
const writeConcern_1 = require("../writeConcern");
|
|
6
|
+
const factory = require("../../../factory");
|
|
6
7
|
const modelName = 'Event';
|
|
7
8
|
exports.modelName = modelName;
|
|
8
9
|
/**
|
|
@@ -121,6 +122,28 @@ schema.index({ 'workPerformed.identifier': 1, startDate: 1 }, {
|
|
|
121
122
|
'workPerformed.identifier': { $exists: true }
|
|
122
123
|
}
|
|
123
124
|
});
|
|
125
|
+
schema.index({ 'workPerformed.version': 1, startDate: 1 }, {
|
|
126
|
+
name: 'searchByWorkPerformedVersion',
|
|
127
|
+
partialFilterExpression: {
|
|
128
|
+
'workPerformed.version': { $exists: true }
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
// コンテンツ+バージョンに対するuniqueness
|
|
132
|
+
schema.index({
|
|
133
|
+
'project.id': 1,
|
|
134
|
+
'location.branchCode': 1,
|
|
135
|
+
'workPerformed.identifier': 1,
|
|
136
|
+
'workPerformed.version': 1
|
|
137
|
+
}, {
|
|
138
|
+
unique: true,
|
|
139
|
+
name: 'uniqueScreeningEventSeries',
|
|
140
|
+
partialFilterExpression: {
|
|
141
|
+
typeOf: factory.eventType.ScreeningEventSeries,
|
|
142
|
+
'location.branchCode': { $exists: true },
|
|
143
|
+
'workPerformed.identifier': { $exists: true },
|
|
144
|
+
'workPerformed.version': { $exists: true }
|
|
145
|
+
}
|
|
146
|
+
});
|
|
124
147
|
schema.index({ startDate: 1 }, { name: 'searchByStartDate' });
|
|
125
148
|
schema.index({ endDate: 1, startDate: 1 }, { name: 'searchByEndDate' });
|
|
126
149
|
schema.index({ 'hasOfferCatalog.id': 1, startDate: 1 }, {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
12
|
+
"@chevre/factory": "4.310.0-alpha.0",
|
|
13
13
|
"@cinerino/sdk": "3.153.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -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": "21.0.0-alpha.
|
|
123
|
+
"version": "21.0.0-alpha.14"
|
|
124
124
|
}
|