@chevre/domain 21.19.0-alpha.0 → 21.19.0-alpha.2
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/optimizeOffers.ts +16 -0
- package/lib/chevre/repo/aggregateOffer.d.ts +4 -0
- package/lib/chevre/repo/aggregateOffer.js +14 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +9 -8
- package/lib/chevre/repo/offer.d.ts +7 -2
- package/lib/chevre/repo/offer.js +35 -19
- package/lib/chevre/service/offer/event/factory.d.ts +1 -4
- package/lib/chevre/service/offer/event/factory.js +3 -1
- package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const aggregateOfferRepo = await chevre.repository.AggregateOffer.createInstance(mongoose.connection);
|
|
10
|
+
const result = await aggregateOfferRepo.optimizeOffers();
|
|
11
|
+
console.log('result:', result);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main()
|
|
15
|
+
.then(console.log)
|
|
16
|
+
.catch(console.error);
|
|
@@ -562,5 +562,19 @@ class MongoRepository {
|
|
|
562
562
|
.exec();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
|
+
/**
|
|
566
|
+
* 単価オファー最適化作業における一時的な処理
|
|
567
|
+
*/
|
|
568
|
+
optimizeOffers() {
|
|
569
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
570
|
+
return this.aggregateOfferModel.updateMany({
|
|
571
|
+
$or: [
|
|
572
|
+
{ 'offers.id': { $exists: true } },
|
|
573
|
+
{ 'offers.project': { $exists: true } }
|
|
574
|
+
]
|
|
575
|
+
}, { $set: {} })
|
|
576
|
+
.exec();
|
|
577
|
+
});
|
|
578
|
+
}
|
|
565
579
|
}
|
|
566
580
|
exports.MongoRepository = MongoRepository;
|
|
@@ -52,14 +52,15 @@ const indexes = [
|
|
|
52
52
|
{ 'offers.priceSpecification.price': 1 },
|
|
53
53
|
{ name: 'searchByOffersPriceSpecificationPrice' }
|
|
54
54
|
],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
// ↓サブオファー最適化につき廃止(2023-12-22~)
|
|
56
|
+
// [
|
|
57
|
+
// // オファーIDはグローバルユニーク
|
|
58
|
+
// { 'offers.id': 1 },
|
|
59
|
+
// {
|
|
60
|
+
// name: 'uniqueOfferId',
|
|
61
|
+
// unique: true
|
|
62
|
+
// }
|
|
63
|
+
// ],
|
|
63
64
|
[
|
|
64
65
|
// オファーコードはプロジェクト内ユニーク
|
|
65
66
|
{ 'offers.identifier': 1, 'project.id': 1 },
|
|
@@ -152,7 +152,9 @@ export declare class MongoRepository {
|
|
|
152
152
|
}[]>;
|
|
153
153
|
count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
|
|
154
154
|
search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IUnitPriceOfferFromAggregateOffer[]>;
|
|
155
|
-
save(params: factory.unitPriceOffer.IUnitPriceOffer & {}): Promise<
|
|
155
|
+
save(params: factory.unitPriceOffer.IUnitPriceOffer & {}): Promise<{
|
|
156
|
+
id: string;
|
|
157
|
+
}>;
|
|
156
158
|
/**
|
|
157
159
|
* コードをキーにして冪等置換(2023-12-13~)
|
|
158
160
|
*/
|
|
@@ -167,7 +169,10 @@ export declare class MongoRepository {
|
|
|
167
169
|
* sskts専用オファー保管
|
|
168
170
|
*/
|
|
169
171
|
saveManyByIdentifier(params: {
|
|
170
|
-
|
|
172
|
+
project: {
|
|
173
|
+
id: string;
|
|
174
|
+
};
|
|
175
|
+
attributes: factory.aggregateOffer.ISubOffer;
|
|
171
176
|
upsert?: boolean;
|
|
172
177
|
}[]): Promise<void>;
|
|
173
178
|
/**
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -775,21 +775,26 @@ class MongoRepository {
|
|
|
775
775
|
save(params) {
|
|
776
776
|
return __awaiter(this, void 0, void 0, function* () {
|
|
777
777
|
let doc;
|
|
778
|
+
let aggregateOfferId;
|
|
778
779
|
// const { $unset, ...paramsWithoutUnset } = params;
|
|
779
780
|
const paramsWithoutUnset = __rest(params, []);
|
|
780
|
-
let savedUnitPriceOffer;
|
|
781
|
-
if (params.id
|
|
781
|
+
// let savedUnitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer;
|
|
782
|
+
if (typeof params.id !== 'string' || params.id.length === 0) {
|
|
782
783
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
783
|
-
const
|
|
784
|
-
|
|
784
|
+
const newId = uniqid();
|
|
785
|
+
aggregateOfferId = newId;
|
|
786
|
+
// サブオファー最適化(2023-12-22~)
|
|
787
|
+
// savedUnitPriceOffer = { ...paramsWithoutUnset, id };
|
|
788
|
+
const { id, project } = paramsWithoutUnset, savedUnitPriceOffer = __rest(paramsWithoutUnset, ["id", "project"]);
|
|
785
789
|
const aggregateOffer = {
|
|
786
790
|
typeOf: factory.offerType.AggregateOffer,
|
|
787
791
|
project: params.project,
|
|
788
792
|
offers: [savedUnitPriceOffer]
|
|
789
793
|
};
|
|
790
|
-
doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id:
|
|
794
|
+
doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: newId }));
|
|
791
795
|
}
|
|
792
796
|
else {
|
|
797
|
+
aggregateOfferId = params.id;
|
|
793
798
|
const unitPriceOffers = yield this.search({
|
|
794
799
|
limit: 1,
|
|
795
800
|
page: 1,
|
|
@@ -802,14 +807,19 @@ class MongoRepository {
|
|
|
802
807
|
}
|
|
803
808
|
// 上書き禁止属性を除外
|
|
804
809
|
const { id, identifier, project, typeOf } = paramsWithoutUnset, updateFields = __rest(paramsWithoutUnset, ["id", "identifier", "project", "typeOf"]);
|
|
805
|
-
|
|
810
|
+
// サブオファー最適化(2023-12-22~)
|
|
811
|
+
const subOffer = Object.assign(Object.assign({}, updateFields), {
|
|
812
|
+
// id: originalUnitPriceOffer.id,
|
|
813
|
+
identifier: originalUnitPriceOffer.identifier,
|
|
814
|
+
// project: originalUnitPriceOffer.project,
|
|
815
|
+
typeOf: originalUnitPriceOffer.typeOf });
|
|
806
816
|
doc = yield this.aggregateOfferModel.findOneAndUpdate(
|
|
807
817
|
// { 'offers.id': params.id },
|
|
808
818
|
{ _id: params.id }, // _idに変更(2023-12-22~)
|
|
809
819
|
{
|
|
810
820
|
$set: {
|
|
811
821
|
// 'offers.$[offer]': savedUnitPriceOffer
|
|
812
|
-
'offers.0':
|
|
822
|
+
'offers.0': subOffer // _idに変更(2023-12-22~)
|
|
813
823
|
}
|
|
814
824
|
}, {
|
|
815
825
|
upsert: false,
|
|
@@ -824,7 +834,7 @@ class MongoRepository {
|
|
|
824
834
|
if (doc === null) {
|
|
825
835
|
throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
|
|
826
836
|
}
|
|
827
|
-
return
|
|
837
|
+
return { id: aggregateOfferId };
|
|
828
838
|
});
|
|
829
839
|
}
|
|
830
840
|
/**
|
|
@@ -852,11 +862,13 @@ class MongoRepository {
|
|
|
852
862
|
'offers.identifier': { $exists: true, $eq: p.identifier }
|
|
853
863
|
});
|
|
854
864
|
const newOfferId = uniqid(); // setOnInsert時のみに利用する新ID
|
|
855
|
-
|
|
865
|
+
// サブオファー最適化(2023-12-22~)
|
|
866
|
+
// const subOffer: factory.aggregateOffer.ISubOffer = { ...p, id: newOfferId };
|
|
867
|
+
const { project } = p, subOffer = __rest(p, ["project"]);
|
|
856
868
|
const aggregateOffer = {
|
|
857
869
|
project: p.project,
|
|
858
870
|
typeOf: factory.offerType.AggregateOffer,
|
|
859
|
-
offers: [
|
|
871
|
+
offers: [subOffer]
|
|
860
872
|
};
|
|
861
873
|
const setOnInsert = Object.assign(Object.assign({}, aggregateOffer), { _id: newOfferId });
|
|
862
874
|
const updateFilter = { $setOnInsert: setOnInsert };
|
|
@@ -885,9 +897,11 @@ class MongoRepository {
|
|
|
885
897
|
'project.id': { $eq: p.project.id },
|
|
886
898
|
'offers.identifier': { $exists: true, $eq: p.identifier }
|
|
887
899
|
};
|
|
888
|
-
|
|
900
|
+
// サブオファー最適化(2023-12-22~)
|
|
901
|
+
// const unitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer = { ...p, id: originalAggregateOffer.id };
|
|
902
|
+
const { project } = p, subOffer = __rest(p, ["project"]);
|
|
889
903
|
const setOnUpdate = {
|
|
890
|
-
'offers.0':
|
|
904
|
+
'offers.0': subOffer
|
|
891
905
|
};
|
|
892
906
|
const updateOne = {
|
|
893
907
|
filter,
|
|
@@ -915,16 +929,18 @@ class MongoRepository {
|
|
|
915
929
|
if (Array.isArray(params)) {
|
|
916
930
|
params.forEach((p) => {
|
|
917
931
|
const newOfferId = uniqid();
|
|
918
|
-
|
|
932
|
+
// サブオファー最適化(2023-12-22~)
|
|
933
|
+
// const unitPriceOffer: factory.aggregateOffer.ISubOffer = { ...p.attributes, id: newOfferId };
|
|
934
|
+
const subOffer = Object.assign({}, p.attributes);
|
|
919
935
|
const aggregateOffer = {
|
|
920
|
-
project: p.
|
|
936
|
+
project: { id: p.project.id, typeOf: factory.organizationType.Project },
|
|
921
937
|
typeOf: factory.offerType.AggregateOffer,
|
|
922
|
-
offers: [
|
|
938
|
+
offers: [subOffer]
|
|
923
939
|
};
|
|
924
940
|
insertBulkWriteOps.push({
|
|
925
941
|
updateOne: {
|
|
926
942
|
filter: {
|
|
927
|
-
'project.id': { $eq: p.
|
|
943
|
+
'project.id': { $eq: p.project.id },
|
|
928
944
|
'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
|
|
929
945
|
},
|
|
930
946
|
update: {
|
|
@@ -933,12 +949,12 @@ class MongoRepository {
|
|
|
933
949
|
upsert: true
|
|
934
950
|
}
|
|
935
951
|
});
|
|
936
|
-
const
|
|
952
|
+
const $set = __rest(subOffer, []);
|
|
937
953
|
updateBulkWriteOps.push({
|
|
938
954
|
updateOne: {
|
|
939
955
|
filter: {
|
|
940
|
-
'project.id': { $eq:
|
|
941
|
-
'offers.identifier': { $exists: true, $eq:
|
|
956
|
+
'project.id': { $eq: aggregateOffer.project.id },
|
|
957
|
+
'offers.identifier': { $exists: true, $eq: subOffer.identifier }
|
|
942
958
|
},
|
|
943
959
|
update: {
|
|
944
960
|
// 特定の属性のみ更新する(IDを上書きできないので)
|
|
@@ -37,12 +37,9 @@ export declare function responseBody2acceptedOffers4result(params: {
|
|
|
37
37
|
seller: factory.transaction.placeOrder.ISeller;
|
|
38
38
|
}): IResultAcceptedOffer[];
|
|
39
39
|
export declare function coaTicket2offer(params: {
|
|
40
|
-
project: {
|
|
41
|
-
id: string;
|
|
42
|
-
};
|
|
43
40
|
theaterCode: string;
|
|
44
41
|
ticketResult: COA.factory.master.ITicketResult;
|
|
45
42
|
defaultCurrencyType?: factory.categoryCode.ICategoryCode;
|
|
46
43
|
defaultMembershipType?: factory.categoryCode.ICategoryCode;
|
|
47
|
-
}):
|
|
44
|
+
}): factory.aggregateOffer.ISubOffer;
|
|
48
45
|
export {};
|
|
@@ -340,7 +340,9 @@ function coaTicket2offer(params) {
|
|
|
340
340
|
? params.ticketResult.ticketNameEng
|
|
341
341
|
: ''
|
|
342
342
|
};
|
|
343
|
-
return Object.assign(Object.assign(Object.assign({
|
|
343
|
+
return Object.assign(Object.assign(Object.assign({
|
|
344
|
+
// project: { typeOf: factory.organizationType.Project, id: params.project.id },
|
|
345
|
+
typeOf: factory.offerType.Offer, priceCurrency: factory.priceCurrency.JPY,
|
|
344
346
|
// id: '',
|
|
345
347
|
identifier: identifier, name: offerName, description: {
|
|
346
348
|
ja: '',
|
|
@@ -34,13 +34,13 @@ function importFromCOA(params) {
|
|
|
34
34
|
const ticketResults = yield repos.masterService.ticket({ theaterCode: params.theaterCode });
|
|
35
35
|
const saveParams = ticketResults.map((ticketResult) => {
|
|
36
36
|
const offer = (0, factory_1.coaTicket2offer)({
|
|
37
|
-
project: params.project,
|
|
37
|
+
// project: params.project,
|
|
38
38
|
theaterCode: params.theaterCode,
|
|
39
39
|
ticketResult: ticketResult,
|
|
40
40
|
defaultCurrencyType,
|
|
41
41
|
defaultMembershipType
|
|
42
42
|
});
|
|
43
|
-
return { attributes: offer, upsert: true };
|
|
43
|
+
return { attributes: offer, upsert: true, project: { id: params.project.id } };
|
|
44
44
|
});
|
|
45
45
|
yield repos.offer.saveManyByIdentifier(saveParams);
|
|
46
46
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/credential-providers": "3.433.0",
|
|
13
|
-
"@chevre/factory": "4.
|
|
13
|
+
"@chevre/factory": "4.348.0-alpha.0",
|
|
14
14
|
"@cinerino/sdk": "5.5.0",
|
|
15
15
|
"@motionpicture/coa-service": "9.2.0",
|
|
16
16
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "21.19.0-alpha.
|
|
118
|
+
"version": "21.19.0-alpha.2"
|
|
119
119
|
}
|