@chevre/domain 21.8.0-alpha.32 → 21.8.0-alpha.34
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/example/src/chevre/countOffers.ts +32 -0
- package/example/src/chevre/searchOffersFromAggregateOffer.ts +17 -17
- package/example/src/chevre/sync2aggregateOffer.ts +27 -0
- package/lib/chevre/repo/offer.d.ts +7 -3
- package/lib/chevre/repo/offer.js +264 -87
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const result = await offerRepo.count(
|
|
13
|
+
{
|
|
14
|
+
project: { id: { $eq: String(process.env.PROJECT_ID) } },
|
|
15
|
+
availability: { $eq: chevre.factory.itemAvailability.InStock },
|
|
16
|
+
id: {
|
|
17
|
+
// $eq: '1001'
|
|
18
|
+
// $in: string[];
|
|
19
|
+
},
|
|
20
|
+
identifier: {
|
|
21
|
+
// $eq: '1001'
|
|
22
|
+
// $in: string[];
|
|
23
|
+
// $regex: '003'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
console.log(result);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main()
|
|
31
|
+
.then(console.log)
|
|
32
|
+
.catch(console.error);
|
|
@@ -9,13 +9,18 @@ async function main() {
|
|
|
9
9
|
|
|
10
10
|
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
11
11
|
|
|
12
|
-
const offers = await offerRepo.
|
|
12
|
+
const offers = await offerRepo.search(
|
|
13
13
|
{
|
|
14
14
|
limit: 5,
|
|
15
15
|
page: 1,
|
|
16
16
|
sort: { 'priceSpecification.price': 1 },
|
|
17
17
|
project: { id: { $eq: String(process.env.PROJECT_ID) } },
|
|
18
18
|
availability: { $eq: chevre.factory.itemAvailability.InStock },
|
|
19
|
+
itemOffered: {
|
|
20
|
+
typeOf: {
|
|
21
|
+
// $eq: chevre.factory.product.ProductType.EventService
|
|
22
|
+
}
|
|
23
|
+
},
|
|
19
24
|
addOn: {
|
|
20
25
|
itemOffered: {
|
|
21
26
|
/**
|
|
@@ -121,26 +126,21 @@ async function main() {
|
|
|
121
126
|
codeValue: {
|
|
122
127
|
// $in: ['1']
|
|
123
128
|
}
|
|
124
|
-
}
|
|
125
|
-
itemOffered: {
|
|
126
|
-
typeOf: {
|
|
127
|
-
// $eq: chevre.factory.product.ProductType.Product
|
|
128
|
-
}
|
|
129
|
-
},
|
|
129
|
+
}
|
|
130
130
|
/**
|
|
131
131
|
* 有効期間設定がない、あるいは、有効期間内
|
|
132
132
|
*/
|
|
133
133
|
// onlyValid: true
|
|
134
|
-
additionalProperty: {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
134
|
+
// additionalProperty: {
|
|
135
|
+
// $all: [
|
|
136
|
+
// {
|
|
137
|
+
// $elemMatch: {
|
|
138
|
+
// name: { $eq: 'nameForPrinting' },
|
|
139
|
+
// value: { $in: ['General'] }
|
|
140
|
+
// }
|
|
141
|
+
// }
|
|
142
|
+
// ]
|
|
143
|
+
// }
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
id: 1,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const offerRepo = new chevre.repository.Offer(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const result = await offerRepo.sync2aggregateOffer({
|
|
13
|
+
id: {
|
|
14
|
+
$in: ['1001']
|
|
15
|
+
},
|
|
16
|
+
project: {
|
|
17
|
+
id: String(process.env.PROJECT_ID)
|
|
18
|
+
},
|
|
19
|
+
isDeleted: false,
|
|
20
|
+
typeOf: chevre.factory.offerType.AggregateOffer
|
|
21
|
+
});
|
|
22
|
+
console.log(result);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
main()
|
|
26
|
+
.then(console.log)
|
|
27
|
+
.catch(console.error);
|
|
@@ -80,9 +80,12 @@ export declare class MongoRepository {
|
|
|
80
80
|
};
|
|
81
81
|
id: string;
|
|
82
82
|
}): Promise<factory.aggregateOffer.IAggregateOffer>;
|
|
83
|
-
count(params: factory.unitPriceOffer.ISearchConditions): Promise<number>;
|
|
84
|
-
search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection
|
|
85
|
-
|
|
83
|
+
count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
|
|
84
|
+
search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection,
|
|
85
|
+
/**
|
|
86
|
+
* 強制的にoffersコレクションを使用する
|
|
87
|
+
*/
|
|
88
|
+
useOffersAsPrimary?: boolean): Promise<factory.unitPriceOffer.IUnitPriceOffer[]>;
|
|
86
89
|
save(params: factory.unitPriceOffer.IUnitPriceOffer): Promise<factory.unitPriceOffer.IUnitPriceOffer>;
|
|
87
90
|
/**
|
|
88
91
|
* sskts専用オファー保管
|
|
@@ -147,5 +150,6 @@ export declare class MongoRepository {
|
|
|
147
150
|
}): Promise<{
|
|
148
151
|
id: string;
|
|
149
152
|
}[]>;
|
|
153
|
+
private searchFromAggregateOffer;
|
|
150
154
|
}
|
|
151
155
|
export {};
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -29,12 +29,19 @@ const offerCatalog_1 = require("./mongoose/schemas/offerCatalog");
|
|
|
29
29
|
const task_1 = require("./mongoose/schemas/task");
|
|
30
30
|
const task_2 = require("../eventEmitter/task");
|
|
31
31
|
const settings_1 = require("../settings");
|
|
32
|
+
const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
|
|
32
33
|
/**
|
|
33
34
|
* オファーリポジトリ
|
|
34
35
|
*/
|
|
35
36
|
class MongoRepository {
|
|
36
37
|
constructor(connection) {
|
|
37
38
|
this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
|
|
39
|
+
// .on('index', (error: any) => {
|
|
40
|
+
// if (error !== undefined) {
|
|
41
|
+
// // tslint:disable-next-line:no-console
|
|
42
|
+
// console.error('index event emitted.', error);
|
|
43
|
+
// }
|
|
44
|
+
// });
|
|
38
45
|
this.offerModel = connection.model(offer_1.modelName, offer_1.schema);
|
|
39
46
|
this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
|
|
40
47
|
this.taskModel = connection.model(task_1.modelName, task_1.schema);
|
|
@@ -715,6 +722,7 @@ class MongoRepository {
|
|
|
715
722
|
static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
|
|
716
723
|
let projectStage = {
|
|
717
724
|
_id: 0,
|
|
725
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
|
|
718
726
|
typeOf: '$offers.typeOf',
|
|
719
727
|
project: '$project',
|
|
720
728
|
id: '$offers.id',
|
|
@@ -751,7 +759,10 @@ class MongoRepository {
|
|
|
751
759
|
const negativeProjectionFields = Object.keys(params)
|
|
752
760
|
.filter((key) => params[key] === 0);
|
|
753
761
|
if (positiveProjectionFields.length > 0) {
|
|
754
|
-
projectStage = {
|
|
762
|
+
projectStage = {
|
|
763
|
+
_id: 0,
|
|
764
|
+
offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`
|
|
765
|
+
};
|
|
755
766
|
positiveProjectionFields.forEach((field) => {
|
|
756
767
|
projectStage[field] = `$offers.${field}`;
|
|
757
768
|
});
|
|
@@ -813,7 +824,8 @@ class MongoRepository {
|
|
|
813
824
|
}, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
|
|
814
825
|
? { sort: { _id: factory.sortType.Ascending } }
|
|
815
826
|
: undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
|
|
816
|
-
|
|
827
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
828
|
+
offers = yield this.search(searchOffersConditions, params.projection, settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY);
|
|
817
829
|
// 完全廃止(基本的にsortedOfferIdsと合わせて利用する想定)(2023-09-04~)
|
|
818
830
|
// if (params.sort) {
|
|
819
831
|
// // sorting
|
|
@@ -857,15 +869,41 @@ class MongoRepository {
|
|
|
857
869
|
}
|
|
858
870
|
count(params) {
|
|
859
871
|
return __awaiter(this, void 0, void 0, function* () {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
.
|
|
872
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
873
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
874
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
875
|
+
const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
|
|
876
|
+
{
|
|
877
|
+
$unwind: { path: '$offers' }
|
|
878
|
+
},
|
|
879
|
+
...matchStages,
|
|
880
|
+
{
|
|
881
|
+
$count: 'offerCount'
|
|
882
|
+
}
|
|
883
|
+
])
|
|
884
|
+
.exec();
|
|
885
|
+
return offerCount;
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
|
|
889
|
+
return this.offerModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
|
|
890
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
891
|
+
.exec();
|
|
892
|
+
}
|
|
864
893
|
});
|
|
865
894
|
}
|
|
866
|
-
search(params, projection
|
|
895
|
+
search(params, projection,
|
|
896
|
+
/**
|
|
897
|
+
* 強制的にoffersコレクションを使用する
|
|
898
|
+
*/
|
|
899
|
+
useOffersAsPrimary) {
|
|
867
900
|
var _a;
|
|
868
901
|
return __awaiter(this, void 0, void 0, function* () {
|
|
902
|
+
// primaryコレクションをコントロール(2023-09-05~)
|
|
903
|
+
const useAggregateOfferAsPrimary = settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY && (useOffersAsPrimary !== true);
|
|
904
|
+
if (useAggregateOfferAsPrimary) {
|
|
905
|
+
return this.searchFromAggregateOffer(params, projection);
|
|
906
|
+
}
|
|
869
907
|
const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
|
|
870
908
|
const positiveProjectionExists = (projection !== undefined && projection !== null)
|
|
871
909
|
? Object.values(projection)
|
|
@@ -890,57 +928,93 @@ class MongoRepository {
|
|
|
890
928
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
891
929
|
});
|
|
892
930
|
}
|
|
893
|
-
|
|
894
|
-
var _a;
|
|
895
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
896
|
-
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
897
|
-
const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
|
|
898
|
-
const aggregate = this.aggregateOfferModel.aggregate([
|
|
899
|
-
{ $unwind: '$offers' },
|
|
900
|
-
...matchStages,
|
|
901
|
-
...(typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) === 'number')
|
|
902
|
-
? [{ $sort: { 'offers.priceSpecification.price': params.sort['priceSpecification.price'] } }]
|
|
903
|
-
: [],
|
|
904
|
-
{ $project: projectStage }
|
|
905
|
-
]);
|
|
906
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
907
|
-
/* istanbul ignore else */
|
|
908
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
909
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
910
|
-
aggregate.limit(params.limit * page)
|
|
911
|
-
.skip(params.limit * (page - 1));
|
|
912
|
-
}
|
|
913
|
-
return aggregate.exec();
|
|
914
|
-
});
|
|
915
|
-
}
|
|
931
|
+
// tslint:disable-next-line:max-func-body-length
|
|
916
932
|
save(params) {
|
|
917
933
|
return __awaiter(this, void 0, void 0, function* () {
|
|
918
934
|
let doc;
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
935
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
936
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
937
|
+
let savedUnitPriceOffer;
|
|
938
|
+
if (params.id === '') {
|
|
939
|
+
const id = uniqid();
|
|
940
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, params), { id });
|
|
941
|
+
const aggregateOffer = {
|
|
942
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
943
|
+
project: params.project,
|
|
944
|
+
offers: [savedUnitPriceOffer]
|
|
945
|
+
};
|
|
946
|
+
doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: id }));
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
const unitPriceOffers = yield this.searchFromAggregateOffer({
|
|
950
|
+
limit: 1,
|
|
951
|
+
page: 1,
|
|
952
|
+
project: { id: { $eq: params.project.id } },
|
|
953
|
+
id: { $eq: params.id }
|
|
954
|
+
}, { id: 1, identifier: 1, project: 1, typeOf: 1 });
|
|
955
|
+
const originalUnitPriceOffer = unitPriceOffers.shift();
|
|
956
|
+
if (originalUnitPriceOffer === undefined) {
|
|
957
|
+
throw new factory.errors.NotFound(factory.offerType.Offer);
|
|
958
|
+
}
|
|
959
|
+
// 上書き禁止属性を除外
|
|
960
|
+
const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
|
|
961
|
+
savedUnitPriceOffer = Object.assign(Object.assign({}, updateFields), { id: originalUnitPriceOffer.id, identifier: originalUnitPriceOffer.identifier, project: originalUnitPriceOffer.project, typeOf: originalUnitPriceOffer.typeOf });
|
|
962
|
+
doc = yield this.offerModel.findOneAndUpdate({ 'offers.id': params.id }, {
|
|
963
|
+
$set: {
|
|
964
|
+
'offers.$[offer]': savedUnitPriceOffer
|
|
965
|
+
}
|
|
966
|
+
}, {
|
|
967
|
+
upsert: false,
|
|
968
|
+
new: true,
|
|
969
|
+
arrayFilters: [
|
|
970
|
+
{ 'offer.id': { $eq: params.id } }
|
|
971
|
+
]
|
|
972
|
+
})
|
|
973
|
+
.exec();
|
|
974
|
+
}
|
|
975
|
+
if (doc === null) {
|
|
976
|
+
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
977
|
+
}
|
|
978
|
+
// 同期タスク作成(2023-09-05~)
|
|
979
|
+
if (typeof savedUnitPriceOffer.id === 'string') {
|
|
980
|
+
yield this.saveSyncTask({
|
|
981
|
+
project: { id: savedUnitPriceOffer.project.id },
|
|
982
|
+
id: { $in: [savedUnitPriceOffer.id] },
|
|
983
|
+
identifier: { $in: [] },
|
|
984
|
+
isDeleted: false,
|
|
985
|
+
typeOf: factory.offerType.AggregateOffer,
|
|
986
|
+
options: { emitImmediately: true }
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
return savedUnitPriceOffer;
|
|
922
990
|
}
|
|
923
991
|
else {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
992
|
+
if (params.id === '') {
|
|
993
|
+
const id = uniqid();
|
|
994
|
+
doc = yield this.offerModel.create(Object.assign(Object.assign({}, params), { _id: id }));
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
// 上書き禁止属性を除外(2022-08-24~)
|
|
998
|
+
const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
|
|
999
|
+
doc = yield this.offerModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
|
|
1000
|
+
.exec();
|
|
1001
|
+
}
|
|
1002
|
+
if (doc === null) {
|
|
1003
|
+
throw new factory.errors.NotFound(this.offerModel.modelName);
|
|
1004
|
+
}
|
|
1005
|
+
// 同期タスク作成(2023-09-03~)
|
|
1006
|
+
if (typeof doc._id === 'string') {
|
|
1007
|
+
yield this.saveSyncTask({
|
|
1008
|
+
project: { id: params.project.id },
|
|
1009
|
+
id: { $in: [doc._id] },
|
|
1010
|
+
identifier: { $in: [] },
|
|
1011
|
+
isDeleted: false,
|
|
1012
|
+
typeOf: factory.offerType.Offer,
|
|
1013
|
+
options: { emitImmediately: true }
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
return doc.toObject();
|
|
942
1017
|
}
|
|
943
|
-
return doc.toObject();
|
|
944
1018
|
});
|
|
945
1019
|
}
|
|
946
1020
|
/**
|
|
@@ -948,6 +1022,11 @@ class MongoRepository {
|
|
|
948
1022
|
*/
|
|
949
1023
|
saveManyByIdentifier(params) {
|
|
950
1024
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1025
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
1026
|
+
// TODO USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1027
|
+
// if (USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1028
|
+
// } else {
|
|
1029
|
+
// }
|
|
951
1030
|
const bulkWriteOps = [];
|
|
952
1031
|
if (Array.isArray(params)) {
|
|
953
1032
|
params.forEach((p) => {
|
|
@@ -1000,48 +1079,62 @@ class MongoRepository {
|
|
|
1000
1079
|
if (params.addOn.itemOffered.id.$in.length === 0) {
|
|
1001
1080
|
return;
|
|
1002
1081
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1082
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
1083
|
+
// TODO USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1084
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1085
|
+
throw new factory.errors.NotImplemented('USE_AGGREGATE_OFFERS_AS_PRIMARY not implemented');
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
const conditions = {
|
|
1089
|
+
'project.id': { $eq: params.project.id },
|
|
1090
|
+
'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
1091
|
+
};
|
|
1092
|
+
const updatingOffers = yield this.offerModel.find(conditions, { _id: 1 })
|
|
1093
|
+
.exec()
|
|
1094
|
+
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
1095
|
+
const result = yield this.offerModel.updateMany(conditions, {
|
|
1096
|
+
$pull: {
|
|
1097
|
+
addOn: {
|
|
1098
|
+
'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
|
|
1099
|
+
}
|
|
1014
1100
|
}
|
|
1101
|
+
})
|
|
1102
|
+
.exec();
|
|
1103
|
+
// 同期タスク作成(2023-09-03~)
|
|
1104
|
+
if (updatingOffers.length > 0) {
|
|
1105
|
+
yield this.saveSyncTask({
|
|
1106
|
+
project: { id: params.project.id },
|
|
1107
|
+
id: { $in: updatingOffers.map((offer) => offer.id) },
|
|
1108
|
+
identifier: { $in: [] },
|
|
1109
|
+
isDeleted: false,
|
|
1110
|
+
typeOf: factory.offerType.Offer,
|
|
1111
|
+
options: { emitImmediately: true }
|
|
1112
|
+
});
|
|
1015
1113
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1114
|
+
return result;
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
deleteById(params) {
|
|
1119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1120
|
+
// tslint:disable-next-line:no-suspicious-comment
|
|
1121
|
+
// TODO USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1122
|
+
if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
|
|
1123
|
+
throw new factory.errors.NotImplemented('USE_AGGREGATE_OFFERS_AS_PRIMARY not implemented');
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
yield this.offerModel.findOneAndRemove({ _id: params.id }, { projection: { _id: 1 } })
|
|
1127
|
+
.exec();
|
|
1128
|
+
// 同期タスク作成(2023-09-03~)
|
|
1020
1129
|
yield this.saveSyncTask({
|
|
1021
1130
|
project: { id: params.project.id },
|
|
1022
|
-
id: { $in:
|
|
1131
|
+
id: { $in: [params.id] },
|
|
1023
1132
|
identifier: { $in: [] },
|
|
1024
|
-
isDeleted:
|
|
1133
|
+
isDeleted: true,
|
|
1025
1134
|
typeOf: factory.offerType.Offer,
|
|
1026
1135
|
options: { emitImmediately: true }
|
|
1027
1136
|
});
|
|
1028
1137
|
}
|
|
1029
|
-
return result;
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
deleteById(params) {
|
|
1033
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1034
|
-
yield this.offerModel.findOneAndRemove({ _id: params.id }, { projection: { _id: 1 } })
|
|
1035
|
-
.exec();
|
|
1036
|
-
// 同期タスク作成(2023-09-03~)
|
|
1037
|
-
yield this.saveSyncTask({
|
|
1038
|
-
project: { id: params.project.id },
|
|
1039
|
-
id: { $in: [params.id] },
|
|
1040
|
-
identifier: { $in: [] },
|
|
1041
|
-
isDeleted: true,
|
|
1042
|
-
typeOf: factory.offerType.Offer,
|
|
1043
|
-
options: { emitImmediately: true }
|
|
1044
|
-
});
|
|
1045
1138
|
});
|
|
1046
1139
|
}
|
|
1047
1140
|
// public async deleteByProject(params: {
|
|
@@ -1067,8 +1160,9 @@ class MongoRepository {
|
|
|
1067
1160
|
// )
|
|
1068
1161
|
// .exec();
|
|
1069
1162
|
// }
|
|
1163
|
+
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
1070
1164
|
sync2aggregateOffer(params) {
|
|
1071
|
-
var _a, _b;
|
|
1165
|
+
var _a, _b, _c, _d;
|
|
1072
1166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
1167
|
if (params.typeOf === factory.offerType.Offer) {
|
|
1074
1168
|
const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
|
|
@@ -1150,7 +1244,62 @@ class MongoRepository {
|
|
|
1150
1244
|
}
|
|
1151
1245
|
}
|
|
1152
1246
|
else if (params.typeOf === factory.offerType.AggregateOffer) {
|
|
1153
|
-
//
|
|
1247
|
+
// USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
|
|
1248
|
+
const idIn = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$in;
|
|
1249
|
+
const identifierIn = (_d = params.identifier) === null || _d === void 0 ? void 0 : _d.$in;
|
|
1250
|
+
if (params.isDeleted === true) {
|
|
1251
|
+
throw new factory.errors.NotImplemented('USE_AGGREGATE_OFFERS_AS_PRIMARY not implemented');
|
|
1252
|
+
}
|
|
1253
|
+
else {
|
|
1254
|
+
let aggregateOffers = [];
|
|
1255
|
+
if (Array.isArray(idIn) && idIn.length > 0) {
|
|
1256
|
+
aggregateOffers = yield this.aggregateOfferModel.aggregate([
|
|
1257
|
+
{
|
|
1258
|
+
$unwind: {
|
|
1259
|
+
path: '$offers',
|
|
1260
|
+
includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
|
|
1261
|
+
}
|
|
1262
|
+
},
|
|
1263
|
+
{
|
|
1264
|
+
$match: {
|
|
1265
|
+
'project.id': { $eq: params.project.id },
|
|
1266
|
+
'offers.id': { $in: idIn }
|
|
1267
|
+
}
|
|
1268
|
+
},
|
|
1269
|
+
{
|
|
1270
|
+
$project: {
|
|
1271
|
+
_id: 0,
|
|
1272
|
+
offer: '$offers'
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
])
|
|
1276
|
+
.exec();
|
|
1277
|
+
}
|
|
1278
|
+
if (Array.isArray(identifierIn) && identifierIn.length > 0) {
|
|
1279
|
+
throw new factory.errors.NotImplemented('USE_AGGREGATE_OFFERS_AS_PRIMARY not implemented');
|
|
1280
|
+
}
|
|
1281
|
+
const bulkWriteOps = [];
|
|
1282
|
+
if (aggregateOffers.length > 0) {
|
|
1283
|
+
aggregateOffers.forEach((aggregateOffer) => {
|
|
1284
|
+
const savingUnitPriceOffer = Object.assign(Object.assign({}, aggregateOffer.offer), { _id: String(aggregateOffer.offer.id) });
|
|
1285
|
+
const { id } = savingUnitPriceOffer, replacement = __rest(savingUnitPriceOffer, ["id"]);
|
|
1286
|
+
bulkWriteOps.push({
|
|
1287
|
+
replaceOne: {
|
|
1288
|
+
filter: {
|
|
1289
|
+
'project.id': { $eq: savingUnitPriceOffer.project.id },
|
|
1290
|
+
_id: { $eq: savingUnitPriceOffer.id }
|
|
1291
|
+
},
|
|
1292
|
+
replacement,
|
|
1293
|
+
upsert: true
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
if (bulkWriteOps.length > 0) {
|
|
1299
|
+
// console.log('bulkWriteOps:', bulkWriteOps[0].replaceOne);
|
|
1300
|
+
return this.offerModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1154
1303
|
}
|
|
1155
1304
|
});
|
|
1156
1305
|
}
|
|
@@ -1195,5 +1344,33 @@ class MongoRepository {
|
|
|
1195
1344
|
return savedTasks;
|
|
1196
1345
|
});
|
|
1197
1346
|
}
|
|
1347
|
+
searchFromAggregateOffer(params, projection) {
|
|
1348
|
+
var _a;
|
|
1349
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1350
|
+
const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
|
|
1351
|
+
const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
|
|
1352
|
+
const aggregate = this.aggregateOfferModel.aggregate([
|
|
1353
|
+
{
|
|
1354
|
+
$unwind: {
|
|
1355
|
+
path: '$offers',
|
|
1356
|
+
includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
|
|
1357
|
+
}
|
|
1358
|
+
},
|
|
1359
|
+
...matchStages,
|
|
1360
|
+
...(typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) === 'number')
|
|
1361
|
+
? [{ $sort: { 'offers.priceSpecification.price': params.sort['priceSpecification.price'] } }]
|
|
1362
|
+
: [],
|
|
1363
|
+
{ $project: projectStage }
|
|
1364
|
+
]);
|
|
1365
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
1366
|
+
/* istanbul ignore else */
|
|
1367
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
1368
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
1369
|
+
aggregate.limit(params.limit * page)
|
|
1370
|
+
.skip(params.limit * (page - 1));
|
|
1371
|
+
}
|
|
1372
|
+
return aggregate.exec();
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1198
1375
|
}
|
|
1199
1376
|
exports.MongoRepository = MongoRepository;
|
package/lib/chevre/settings.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export declare const USE_DELETE_EVENT_BY_ORDER: boolean;
|
|
|
43
43
|
export declare const USE_CUSTOM_SENDER_EMAIL: boolean;
|
|
44
44
|
export declare const USE_ORDER_PAYMENT_DUE_ON_PLACED: boolean;
|
|
45
45
|
export declare const USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY: boolean;
|
|
46
|
+
export declare const USE_AGGREGATE_OFFERS_AS_PRIMARY: boolean;
|
|
46
47
|
export declare const MONGO_MAX_TIME_MS: number;
|
|
47
48
|
/**
|
|
48
49
|
* グローバル設定
|
package/lib/chevre/settings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.settings = exports.MONGO_MAX_TIME_MS = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_CUSTOM_SENDER_EMAIL = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
|
|
3
|
+
exports.settings = exports.MONGO_MAX_TIME_MS = exports.USE_AGGREGATE_OFFERS_AS_PRIMARY = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_CUSTOM_SENDER_EMAIL = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
|
|
4
4
|
const moment = require("moment");
|
|
5
5
|
const factory = require("./factory");
|
|
6
6
|
const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
|
|
@@ -75,6 +75,7 @@ exports.USE_DELETE_EVENT_BY_ORDER = process.env.USE_DELETE_EVENT_BY_ORDER === '1
|
|
|
75
75
|
exports.USE_CUSTOM_SENDER_EMAIL = process.env.USE_CUSTOM_SENDER_EMAIL === '1';
|
|
76
76
|
exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = process.env.USE_ORDER_PAYMENT_DUE_ON_PLACED === '1';
|
|
77
77
|
exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = process.env.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY === '1';
|
|
78
|
+
exports.USE_AGGREGATE_OFFERS_AS_PRIMARY = process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY === '1';
|
|
78
79
|
exports.MONGO_MAX_TIME_MS = (typeof process.env.MONGO_MAX_TIME_MS === 'string')
|
|
79
80
|
? Number(process.env.MONGO_MAX_TIME_MS)
|
|
80
81
|
// tslint:disable-next-line:no-magic-numbers
|
package/package.json
CHANGED