@chevre/domain 21.19.0-alpha.2 → 21.19.0-alpha.4
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/upsertOffersByIdentifier.ts +15 -13
- package/lib/chevre/repo/offer.d.ts +1 -2
- package/lib/chevre/repo/offer.js +77 -55
- package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.d.ts +13 -0
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +65 -0
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.d.ts +11 -0
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +54 -1
- package/lib/chevre/service/task/onResourceUpdated.js +15 -0
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ import * as mongoose from 'mongoose';
|
|
|
4
4
|
import { chevre } from '../../../lib/index';
|
|
5
5
|
|
|
6
6
|
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
7
|
+
const PRICE = 1234;
|
|
7
8
|
|
|
8
9
|
// tslint:disable-next-line:max-func-body-length
|
|
9
10
|
async function main() {
|
|
@@ -16,18 +17,18 @@ async function main() {
|
|
|
16
17
|
{
|
|
17
18
|
additionalProperty: [],
|
|
18
19
|
addOn: [],
|
|
19
|
-
alternateName: { en: '', ja: '
|
|
20
|
+
alternateName: { en: '', ja: '20231223' },
|
|
20
21
|
availability: chevre.factory.itemAvailability.InStock,
|
|
21
22
|
availableAtOrFrom: [],
|
|
22
23
|
itemOffered: {
|
|
23
24
|
typeOf: chevre.factory.product.ProductType.EventService,
|
|
24
25
|
serviceOutput: {}
|
|
25
26
|
},
|
|
26
|
-
name: { ja: '
|
|
27
|
+
name: { ja: '20231223', en: '20231223' },
|
|
27
28
|
priceCurrency: chevre.factory.priceCurrency.JPY,
|
|
28
29
|
priceSpecification: {
|
|
29
|
-
name: { en: '
|
|
30
|
-
price:
|
|
30
|
+
name: { en: '20231223', ja: '20231223' },
|
|
31
|
+
price: PRICE,
|
|
31
32
|
priceCurrency: chevre.factory.priceCurrency.JPY,
|
|
32
33
|
referenceQuantity: {
|
|
33
34
|
typeOf: 'QuantitativeValue',
|
|
@@ -38,31 +39,31 @@ async function main() {
|
|
|
38
39
|
valueAddedTaxIncluded: true,
|
|
39
40
|
accounting: {
|
|
40
41
|
typeOf: 'Accounting',
|
|
41
|
-
accountsReceivable:
|
|
42
|
+
accountsReceivable: PRICE
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
settings: { ignoreCategoryCodeChargeSpec: false },
|
|
45
46
|
description: { en: '', ja: '' },
|
|
46
47
|
hasMerchantReturnPolicy: [],
|
|
47
|
-
identifier: '
|
|
48
|
+
identifier: '20231223',
|
|
48
49
|
project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
|
|
49
50
|
typeOf: chevre.factory.offerType.Offer
|
|
50
51
|
},
|
|
51
52
|
{
|
|
52
53
|
additionalProperty: [],
|
|
53
54
|
addOn: [],
|
|
54
|
-
alternateName: { en: '', ja: '
|
|
55
|
+
alternateName: { en: '', ja: '2023122302' },
|
|
55
56
|
availability: chevre.factory.itemAvailability.InStock,
|
|
56
57
|
availableAtOrFrom: [],
|
|
57
58
|
itemOffered: {
|
|
58
59
|
typeOf: chevre.factory.product.ProductType.EventService,
|
|
59
60
|
serviceOutput: {}
|
|
60
61
|
},
|
|
61
|
-
name: { ja: '
|
|
62
|
+
name: { ja: '2023122302', en: '2023122302' },
|
|
62
63
|
priceCurrency: chevre.factory.priceCurrency.JPY,
|
|
63
64
|
priceSpecification: {
|
|
64
|
-
name: { en: '
|
|
65
|
-
price:
|
|
65
|
+
name: { en: '2023122302', ja: '2023122302' },
|
|
66
|
+
price: PRICE,
|
|
66
67
|
priceCurrency: chevre.factory.priceCurrency.JPY,
|
|
67
68
|
referenceQuantity: {
|
|
68
69
|
typeOf: 'QuantitativeValue',
|
|
@@ -73,20 +74,21 @@ async function main() {
|
|
|
73
74
|
valueAddedTaxIncluded: true,
|
|
74
75
|
accounting: {
|
|
75
76
|
typeOf: 'Accounting',
|
|
76
|
-
accountsReceivable:
|
|
77
|
+
accountsReceivable: PRICE
|
|
77
78
|
}
|
|
78
79
|
},
|
|
79
80
|
settings: { ignoreCategoryCodeChargeSpec: false },
|
|
80
81
|
description: { en: '', ja: '' },
|
|
81
82
|
hasMerchantReturnPolicy: [],
|
|
82
|
-
identifier: '
|
|
83
|
+
identifier: '2023122302',
|
|
83
84
|
project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
|
|
84
85
|
typeOf: chevre.factory.offerType.Offer
|
|
85
86
|
}
|
|
86
87
|
]
|
|
87
88
|
// { replace: true }
|
|
88
89
|
);
|
|
89
|
-
|
|
90
|
+
// tslint:disable-next-line:no-null-keyword
|
|
91
|
+
console.dir(result, { depth: null });
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
main()
|
|
@@ -159,7 +159,6 @@ export declare class MongoRepository {
|
|
|
159
159
|
* コードをキーにして冪等置換(2023-12-13~)
|
|
160
160
|
*/
|
|
161
161
|
upsertByIdentifier(params: Omit<factory.unitPriceOffer.IUnitPriceOffer, 'id'>[]): Promise<{
|
|
162
|
-
bulkWriteResult4insert: BulkWriteResult;
|
|
163
162
|
bulkWriteResult: BulkWriteResult;
|
|
164
163
|
modifiedOffers: {
|
|
165
164
|
id: string;
|
|
@@ -168,7 +167,7 @@ export declare class MongoRepository {
|
|
|
168
167
|
/**
|
|
169
168
|
* sskts専用オファー保管
|
|
170
169
|
*/
|
|
171
|
-
|
|
170
|
+
saveManyByIdentifier4sskts(params: {
|
|
172
171
|
project: {
|
|
173
172
|
id: string;
|
|
174
173
|
};
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -848,7 +848,7 @@ class MongoRepository {
|
|
|
848
848
|
return __awaiter(this, void 0, void 0, function* () {
|
|
849
849
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
850
850
|
const insertBulkWriteOps = [];
|
|
851
|
-
const updateBulkWriteOps = [];
|
|
851
|
+
// const updateBulkWriteOps: AnyBulkWriteOperation<factory.aggregateOffer.IAggregateOffer>[] = [];
|
|
852
852
|
const queryFilters = [];
|
|
853
853
|
if (Array.isArray(params)) {
|
|
854
854
|
params.forEach((p) => {
|
|
@@ -870,8 +870,16 @@ class MongoRepository {
|
|
|
870
870
|
typeOf: factory.offerType.AggregateOffer,
|
|
871
871
|
offers: [subOffer]
|
|
872
872
|
};
|
|
873
|
-
const setOnInsert =
|
|
874
|
-
|
|
873
|
+
const setOnInsert = {
|
|
874
|
+
// ...aggregateOffer,
|
|
875
|
+
project: aggregateOffer.project,
|
|
876
|
+
typeOf: aggregateOffer.typeOf,
|
|
877
|
+
_id: newOfferId
|
|
878
|
+
};
|
|
879
|
+
const updateFilter = {
|
|
880
|
+
$setOnInsert: setOnInsert,
|
|
881
|
+
$set: { offers: aggregateOffer.offers }
|
|
882
|
+
};
|
|
875
883
|
const updateOneOnInsert = {
|
|
876
884
|
filter,
|
|
877
885
|
update: updateFilter,
|
|
@@ -881,39 +889,40 @@ class MongoRepository {
|
|
|
881
889
|
});
|
|
882
890
|
}
|
|
883
891
|
if (insertBulkWriteOps.length > 0) {
|
|
884
|
-
const
|
|
892
|
+
const bulkWriteResult = yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
|
|
885
893
|
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
886
894
|
const modifiedOffers = yield this.aggregateOfferModel.find({ $or: queryFilters }, { _id: 1, 'offers.identifier': 1 })
|
|
887
895
|
.exec()
|
|
888
896
|
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
889
|
-
params.forEach((p) => {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
});
|
|
913
|
-
if (updateBulkWriteOps.length > 0) {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
}
|
|
897
|
+
// params.forEach((p) => {
|
|
898
|
+
// const originalAggregateOffer = modifiedOffers.find(((offer) => offer.offers[0]?.identifier === p.identifier));
|
|
899
|
+
// if (originalAggregateOffer === undefined) {
|
|
900
|
+
// // upsert後なので、必ず存在するはず
|
|
901
|
+
// throw new factory.errors.NotFound(`${factory.offerType.AggregateOffer} [${p.identifier}]`);
|
|
902
|
+
// }
|
|
903
|
+
// // リソースのユニークネスを保証するfilter
|
|
904
|
+
// const filter: Filter<factory.aggregateOffer.IAggregateOffer> = {
|
|
905
|
+
// 'project.id': { $eq: p.project.id },
|
|
906
|
+
// 'offers.identifier': { $exists: true, $eq: p.identifier }
|
|
907
|
+
// };
|
|
908
|
+
// // サブオファー最適化(2023-12-22~)
|
|
909
|
+
// // const unitPriceOffer: factory.unitPriceOffer.IUnitPriceOffer = { ...p, id: originalAggregateOffer.id };
|
|
910
|
+
// const { project, ...subOffer } = p;
|
|
911
|
+
// const setOnUpdate: MatchKeysAndValues<factory.aggregateOffer.IAggregateOffer> = {
|
|
912
|
+
// 'offers.0': subOffer
|
|
913
|
+
// };
|
|
914
|
+
// const updateOne: UpdateOneModel<factory.aggregateOffer.IAggregateOffer> = {
|
|
915
|
+
// filter,
|
|
916
|
+
// update: { $set: setOnUpdate },
|
|
917
|
+
// upsert: false
|
|
918
|
+
// };
|
|
919
|
+
// updateBulkWriteOps.push({ updateOne });
|
|
920
|
+
// });
|
|
921
|
+
// if (updateBulkWriteOps.length > 0) {
|
|
922
|
+
// const bulkWriteResult = await this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
|
|
923
|
+
// return { bulkWriteResult4insert, bulkWriteResult, modifiedOffers };
|
|
924
|
+
// }
|
|
925
|
+
return { bulkWriteResult, modifiedOffers };
|
|
917
926
|
}
|
|
918
927
|
});
|
|
919
928
|
}
|
|
@@ -921,17 +930,17 @@ class MongoRepository {
|
|
|
921
930
|
* sskts専用オファー保管
|
|
922
931
|
*/
|
|
923
932
|
// tslint:disable-next-line:max-func-body-length
|
|
924
|
-
|
|
933
|
+
saveManyByIdentifier4sskts(params) {
|
|
925
934
|
return __awaiter(this, void 0, void 0, function* () {
|
|
926
935
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
927
936
|
const insertBulkWriteOps = [];
|
|
928
|
-
const updateBulkWriteOps = [];
|
|
937
|
+
// const updateBulkWriteOps: AnyBulkWriteOperation[] = [];
|
|
929
938
|
if (Array.isArray(params)) {
|
|
930
939
|
params.forEach((p) => {
|
|
931
940
|
const newOfferId = uniqid();
|
|
932
941
|
// サブオファー最適化(2023-12-22~)
|
|
933
942
|
// const unitPriceOffer: factory.aggregateOffer.ISubOffer = { ...p.attributes, id: newOfferId };
|
|
934
|
-
const subOffer =
|
|
943
|
+
const subOffer = p.attributes;
|
|
935
944
|
const aggregateOffer = {
|
|
936
945
|
project: { id: p.project.id, typeOf: factory.organizationType.Project },
|
|
937
946
|
typeOf: factory.offerType.AggregateOffer,
|
|
@@ -944,34 +953,47 @@ class MongoRepository {
|
|
|
944
953
|
'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
|
|
945
954
|
},
|
|
946
955
|
update: {
|
|
947
|
-
$setOnInsert:
|
|
956
|
+
$setOnInsert: {
|
|
957
|
+
// ...aggregateOffer,
|
|
958
|
+
project: aggregateOffer.project,
|
|
959
|
+
typeOf: aggregateOffer.typeOf,
|
|
960
|
+
_id: newOfferId
|
|
961
|
+
},
|
|
962
|
+
$set: { offers: aggregateOffer.offers } // サブオファー最適化(2023-12-22~)
|
|
948
963
|
},
|
|
949
964
|
upsert: true
|
|
950
965
|
}
|
|
951
966
|
});
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
967
|
+
// updateBulkWriteOps.push({
|
|
968
|
+
// updateOne: {
|
|
969
|
+
// filter: {
|
|
970
|
+
// 'project.id': { $eq: aggregateOffer.project.id },
|
|
971
|
+
// 'offers.identifier': { $exists: true, $eq: subOffer.identifier }
|
|
972
|
+
// },
|
|
973
|
+
// update: {
|
|
974
|
+
// // 特定の属性のみ更新する(IDを上書きできないので)
|
|
975
|
+
// $set: {
|
|
976
|
+
// 'offers.0.name': subOffer.name,
|
|
977
|
+
// 'offers.0.description': subOffer.description,
|
|
978
|
+
// 'offers.0.alternateName': subOffer.alternateName,
|
|
979
|
+
// 'offers.0.priceSpecification': subOffer.priceSpecification,
|
|
980
|
+
// 'offers.0.additionalProperty': subOffer.additionalProperty,
|
|
981
|
+
// ...(Array.isArray(subOffer.eligibleMembershipType))
|
|
982
|
+
// ? { 'offers.0.eligibleMembershipType': subOffer.eligibleMembershipType }
|
|
983
|
+
// : undefined,
|
|
984
|
+
// ...(Array.isArray(subOffer.eligibleMonetaryAmount))
|
|
985
|
+
// ? { 'offers.0.eligibleMonetaryAmount': subOffer.eligibleMonetaryAmount }
|
|
986
|
+
// : undefined
|
|
987
|
+
// },
|
|
988
|
+
// },
|
|
989
|
+
// upsert: false
|
|
990
|
+
// }
|
|
991
|
+
// });
|
|
970
992
|
});
|
|
971
993
|
}
|
|
972
994
|
if (insertBulkWriteOps.length > 0) {
|
|
973
995
|
yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
|
|
974
|
-
|
|
996
|
+
// await this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
|
|
975
997
|
}
|
|
976
998
|
});
|
|
977
999
|
}
|
|
@@ -42,7 +42,7 @@ function importFromCOA(params) {
|
|
|
42
42
|
});
|
|
43
43
|
return { attributes: offer, upsert: true, project: { id: params.project.id } };
|
|
44
44
|
});
|
|
45
|
-
yield repos.offer.
|
|
45
|
+
yield repos.offer.saveManyByIdentifier4sskts(saveParams);
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
48
48
|
let throwsError = true;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as factory from '../../../factory';
|
|
2
|
+
import type { MongoRepository as OfferRepo } from '../../../repo/offer';
|
|
3
|
+
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
4
|
+
export declare function createInformOfferTasks(params: {
|
|
5
|
+
project: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
ids: string[];
|
|
9
|
+
typeOf: factory.offerType.AggregateOffer;
|
|
10
|
+
}): (repos: {
|
|
11
|
+
offer: OfferRepo;
|
|
12
|
+
task: TaskRepo;
|
|
13
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createInformOfferTasks = void 0;
|
|
13
|
+
const factory = require("../../../factory");
|
|
14
|
+
const settings_1 = require("../../../settings");
|
|
15
|
+
const informResources = settings_1.settings.onResourceUpdated.informResource;
|
|
16
|
+
function createInformOfferTasks(params) {
|
|
17
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (params.ids.length === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const offers = yield repos.offer.search({
|
|
22
|
+
id: { $in: params.ids }
|
|
23
|
+
}, { typeOf: 1, name: 1, priceSpecification: 1, additionalProperty: 1 });
|
|
24
|
+
const offers4inform = offers.map(({ id, typeOf, name, priceSpecification, additionalProperty, identifier }) => {
|
|
25
|
+
return { id, typeOf, name, priceSpecification, additionalProperty, identifier };
|
|
26
|
+
});
|
|
27
|
+
if (offers4inform.length > 0) {
|
|
28
|
+
const taskRunsAt = new Date();
|
|
29
|
+
const informTasks = [];
|
|
30
|
+
informResources === null || informResources === void 0 ? void 0 : informResources.forEach((informResource) => {
|
|
31
|
+
var _a;
|
|
32
|
+
const informUrl = String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.url);
|
|
33
|
+
offers4inform.forEach((offer4inform) => {
|
|
34
|
+
var _a;
|
|
35
|
+
const informActionAttributes = {
|
|
36
|
+
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
37
|
+
object: offer4inform,
|
|
38
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
39
|
+
recipient: {
|
|
40
|
+
id: '',
|
|
41
|
+
name: String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.name),
|
|
42
|
+
typeOf: factory.creativeWorkType.WebApplication,
|
|
43
|
+
url: informUrl
|
|
44
|
+
},
|
|
45
|
+
typeOf: factory.actionType.InformAction
|
|
46
|
+
};
|
|
47
|
+
informTasks.push({
|
|
48
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
49
|
+
name: factory.taskName.TriggerWebhook,
|
|
50
|
+
status: factory.taskStatus.Ready,
|
|
51
|
+
runsAt: taskRunsAt,
|
|
52
|
+
remainingNumberOfTries: 10,
|
|
53
|
+
numberOfTried: 0,
|
|
54
|
+
executionResults: [],
|
|
55
|
+
data: informActionAttributes
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
if (informTasks.length > 0) {
|
|
60
|
+
yield repos.task.saveMany(informTasks, { emitImmediately: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.createInformOfferTasks = createInformOfferTasks;
|
|
@@ -2,6 +2,17 @@ import * as factory from '../../../factory';
|
|
|
2
2
|
import type { MongoRepository as AggregateOfferRepo } from '../../../repo/aggregateOffer';
|
|
3
3
|
import type { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
|
|
4
4
|
import type { MongoRepository as OfferCatalogItemRepo } from '../../../repo/offerCatalogItem';
|
|
5
|
+
import type { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
6
|
+
export declare function createInformOfferCatalogTasks(params: {
|
|
7
|
+
project: {
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
ids: string[];
|
|
11
|
+
typeOf: factory.offerCatalog.IOfferCatalog['typeOf'];
|
|
12
|
+
}): (repos: {
|
|
13
|
+
offerCatalog: OfferCatalogRepo;
|
|
14
|
+
task: TaskRepo;
|
|
15
|
+
}) => Promise<void>;
|
|
5
16
|
/**
|
|
6
17
|
* オファーカタログ変更時処理
|
|
7
18
|
*/
|
|
@@ -9,8 +9,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.onOfferCatalogUpdated = void 0;
|
|
12
|
+
exports.onOfferCatalogUpdated = exports.createInformOfferCatalogTasks = void 0;
|
|
13
|
+
const factory = require("../../../factory");
|
|
13
14
|
const syncOfferCatalog_1 = require("./syncOfferCatalog");
|
|
15
|
+
const settings_1 = require("../../../settings");
|
|
16
|
+
const informResources = settings_1.settings.onResourceUpdated.informResource;
|
|
17
|
+
function createInformOfferCatalogTasks(params) {
|
|
18
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
if (params.ids.length === 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const offerCatalogs = yield repos.offerCatalog.search({
|
|
23
|
+
id: { $in: params.ids }
|
|
24
|
+
});
|
|
25
|
+
const offerCatalogs4inform = offerCatalogs.map(({ id, typeOf, name, identifier }) => {
|
|
26
|
+
return { id, typeOf, name, identifier };
|
|
27
|
+
});
|
|
28
|
+
if (offerCatalogs4inform.length > 0) {
|
|
29
|
+
const taskRunsAt = new Date();
|
|
30
|
+
const informTasks = [];
|
|
31
|
+
informResources === null || informResources === void 0 ? void 0 : informResources.forEach((informResource) => {
|
|
32
|
+
var _a;
|
|
33
|
+
const informUrl = String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.url);
|
|
34
|
+
offerCatalogs4inform.forEach((offerCatalog4inform) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const informActionAttributes = {
|
|
37
|
+
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
38
|
+
object: offerCatalog4inform,
|
|
39
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
40
|
+
recipient: {
|
|
41
|
+
id: '',
|
|
42
|
+
name: String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.name),
|
|
43
|
+
typeOf: factory.creativeWorkType.WebApplication,
|
|
44
|
+
url: informUrl
|
|
45
|
+
},
|
|
46
|
+
typeOf: factory.actionType.InformAction
|
|
47
|
+
};
|
|
48
|
+
informTasks.push({
|
|
49
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
50
|
+
name: factory.taskName.TriggerWebhook,
|
|
51
|
+
status: factory.taskStatus.Ready,
|
|
52
|
+
runsAt: taskRunsAt,
|
|
53
|
+
remainingNumberOfTries: 10,
|
|
54
|
+
numberOfTried: 0,
|
|
55
|
+
executionResults: [],
|
|
56
|
+
data: informActionAttributes
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
if (informTasks.length > 0) {
|
|
61
|
+
yield repos.task.saveMany(informTasks, { emitImmediately: true });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.createInformOfferCatalogTasks = createInformOfferCatalogTasks;
|
|
14
67
|
/**
|
|
15
68
|
* オファーカタログ変更時処理
|
|
16
69
|
*/
|
|
@@ -27,6 +27,7 @@ const hasPOS_1 = require("../../repo/place/hasPOS");
|
|
|
27
27
|
const product_1 = require("../../repo/product");
|
|
28
28
|
const productOffer_1 = require("../../repo/productOffer");
|
|
29
29
|
const task_1 = require("../../repo/task");
|
|
30
|
+
const onAggregateOfferUpdated_1 = require("./onResourceUpdated/onAggregateOfferUpdated");
|
|
30
31
|
const onHasPOSUpdated_1 = require("./onResourceUpdated/onHasPOSUpdated");
|
|
31
32
|
const onOfferCatalogUpdated_1 = require("./onResourceUpdated/onOfferCatalogUpdated");
|
|
32
33
|
const onResourceDeleted_1 = require("./onResourceUpdated/onResourceDeleted");
|
|
@@ -110,6 +111,20 @@ function onResourceUpdated(params) {
|
|
|
110
111
|
typeOf: factory.placeType.MovieTheater
|
|
111
112
|
})(repos);
|
|
112
113
|
break;
|
|
114
|
+
case factory.offerType.AggregateOffer:
|
|
115
|
+
yield (0, onAggregateOfferUpdated_1.createInformOfferTasks)({
|
|
116
|
+
project: { id: params.project.id },
|
|
117
|
+
ids: params.id,
|
|
118
|
+
typeOf: params.typeOf
|
|
119
|
+
})(repos);
|
|
120
|
+
break;
|
|
121
|
+
case 'OfferCatalog':
|
|
122
|
+
yield (0, onOfferCatalogUpdated_1.createInformOfferCatalogTasks)({
|
|
123
|
+
project: { id: params.project.id },
|
|
124
|
+
ids: params.id,
|
|
125
|
+
typeOf: params.typeOf
|
|
126
|
+
})(repos);
|
|
127
|
+
break;
|
|
113
128
|
default:
|
|
114
129
|
// no op
|
|
115
130
|
}
|
package/package.json
CHANGED