@chevre/domain 21.19.0-alpha.3 → 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/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
|
@@ -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