@chevre/domain 20.1.0-alpha.36 → 20.1.0-alpha.38
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/migrateEventProjectAttributes.ts +57 -0
- package/lib/chevre/repo/event.d.ts +3 -0
- package/lib/chevre/repo/event.js +15 -0
- package/lib/chevre/service/reserve/confirmReservation.js +55 -33
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +67 -30
- package/package.json +1 -1
- package/example/src/chevre/migrateEventAdditionalProperties.ts +0 -96
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
13
|
+
|
|
14
|
+
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = eventRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
// 'project.id': { $eq: project.id },
|
|
19
|
+
'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
20
|
+
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
|
|
21
|
+
// typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
|
|
22
|
+
startDate: {
|
|
23
|
+
$gte: moment()
|
|
24
|
+
.add(-1, 'month')
|
|
25
|
+
.toDate()
|
|
26
|
+
}
|
|
27
|
+
// _id: { $eq: 'al6aff83w' }
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
// _id: 1,
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
console.log('events found');
|
|
34
|
+
|
|
35
|
+
let i = 0;
|
|
36
|
+
let updateCount = 0;
|
|
37
|
+
await cursor.eachAsync(async (doc) => {
|
|
38
|
+
i += 1;
|
|
39
|
+
const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
|
|
40
|
+
|
|
41
|
+
const locationProjectId = (<any>event.location).project?.id;
|
|
42
|
+
if (typeof locationProjectId !== 'string') {
|
|
43
|
+
console.log('already deleted', event.id, event.startDate, event.project.id, i);
|
|
44
|
+
} else {
|
|
45
|
+
updateCount += 1;
|
|
46
|
+
console.log('deleting project...', event.id, event.startDate, event.project.id, i);
|
|
47
|
+
await eventRepo.deleteUnnecessaryProjectAttributesById({ id: event.id });
|
|
48
|
+
console.log('project deleted', event.id, event.startDate, event.project.id, i);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
console.log(i, 'events checked');
|
|
52
|
+
console.log(updateCount, 'events updated');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main()
|
|
56
|
+
.then()
|
|
57
|
+
.catch(console.error);
|
|
@@ -106,4 +106,7 @@ export declare class MongoRepository {
|
|
|
106
106
|
}, update: IUpdateAggregateReservationParams | IUpdateAggregateUseActionsParams): Promise<factory.event.IEvent<T>>;
|
|
107
107
|
bulkWrite(bulkWriteOps: any[]): Promise<import("mongodb").BulkWriteOpResultObject>;
|
|
108
108
|
getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
|
|
109
|
+
deleteUnnecessaryProjectAttributesById(params: {
|
|
110
|
+
id: string;
|
|
111
|
+
}): Promise<void>;
|
|
109
112
|
}
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -649,5 +649,20 @@ class MongoRepository {
|
|
|
649
649
|
.sort({ startDate: factory.sortType.Descending })
|
|
650
650
|
.cursor();
|
|
651
651
|
}
|
|
652
|
+
deleteUnnecessaryProjectAttributesById(params) {
|
|
653
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
654
|
+
yield this.eventModel.updateOne({
|
|
655
|
+
_id: { $eq: params.id }
|
|
656
|
+
}, {
|
|
657
|
+
$unset: {
|
|
658
|
+
'location.project': 1,
|
|
659
|
+
'workPerformed.project': 1,
|
|
660
|
+
'superEvent.location.project': 1,
|
|
661
|
+
'superEvent.workPerformed.project': 1
|
|
662
|
+
}
|
|
663
|
+
})
|
|
664
|
+
.exec();
|
|
665
|
+
});
|
|
666
|
+
}
|
|
652
667
|
}
|
|
653
668
|
exports.MongoRepository = MongoRepository;
|
|
@@ -10,49 +10,71 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.confirmReservation = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* 予約サービス
|
|
15
|
+
*/
|
|
16
|
+
const factory = require("../../factory");
|
|
13
17
|
const onReservationConfirmed_1 = require("./potentialActions/onReservationConfirmed");
|
|
14
18
|
/**
|
|
15
19
|
* 予約を確定する
|
|
16
20
|
*/
|
|
17
21
|
function confirmReservation(actionAttributesList) {
|
|
18
22
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// 予約を確定状態に変更する
|
|
25
|
-
reservation = yield repos.reservation.confirm({
|
|
26
|
-
// 更新属性をwhitelist化(2022-06-13~)
|
|
27
|
-
// ...actionAttributes.object,
|
|
28
|
-
id: reservation.id,
|
|
29
|
-
previousReservationStatus: reservation.reservationStatus,
|
|
30
|
-
underName: reservation.underName,
|
|
31
|
-
reservedTicket: reservation.reservedTicket
|
|
32
|
-
});
|
|
33
|
-
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
34
|
-
delete reservation._id;
|
|
35
|
-
confirmedReservations.push(reservation);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
// actionにエラー結果を追加
|
|
23
|
+
let confirmedReservations = [];
|
|
24
|
+
if (actionAttributesList.length > 0) {
|
|
25
|
+
yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const reservation = actionAttributes.object;
|
|
27
|
+
const action = yield repos.action.start(actionAttributes);
|
|
39
28
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
// 予約を確定状態に変更する
|
|
30
|
+
// reservation = await repos.reservation.confirm<factory.reservationType.EventReservation>({
|
|
31
|
+
yield repos.reservation.confirm({
|
|
32
|
+
// 更新属性をwhitelist化(2022-06-13~)
|
|
33
|
+
// ...actionAttributes.object,
|
|
34
|
+
id: reservation.id,
|
|
35
|
+
previousReservationStatus: reservation.reservationStatus,
|
|
36
|
+
underName: reservation.underName
|
|
37
|
+
// issuedThroughは予約取引開始時に確定しているので更新不要(2022-12-21~)
|
|
38
|
+
// reservedTicket: reservation.reservedTicket
|
|
39
|
+
});
|
|
40
|
+
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
41
|
+
// delete (<any>reservation)._id;
|
|
42
|
+
// confirmedReservations.push(reservation);
|
|
42
43
|
}
|
|
43
|
-
catch (
|
|
44
|
-
//
|
|
44
|
+
catch (error) {
|
|
45
|
+
// actionにエラー結果を追加
|
|
46
|
+
try {
|
|
47
|
+
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
48
|
+
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
|
|
49
|
+
}
|
|
50
|
+
catch (__) {
|
|
51
|
+
// 失敗したら仕方ない
|
|
52
|
+
}
|
|
53
|
+
throw error;
|
|
45
54
|
}
|
|
46
|
-
|
|
55
|
+
// アクション完了
|
|
56
|
+
const actionResult = {
|
|
57
|
+
confirmedReservationId: reservation.id
|
|
58
|
+
};
|
|
59
|
+
yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
60
|
+
yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes)({ task: repos.task });
|
|
61
|
+
})));
|
|
62
|
+
// 確定予約通知タスクを予約番号単位で作成する(2022-12-21~)
|
|
63
|
+
const reservationNumber = actionAttributesList[0].object.reservationNumber;
|
|
64
|
+
if (typeof reservationNumber === 'string' && reservationNumber.length > 0) {
|
|
65
|
+
// 最新のconfirmedReservationsを検索
|
|
66
|
+
confirmedReservations = yield repos.reservation.search({
|
|
67
|
+
reservationNumber: { $eq: reservationNumber },
|
|
68
|
+
typeOf: factory.reservationType.EventReservation
|
|
69
|
+
});
|
|
70
|
+
confirmedReservations = confirmedReservations.map((r) => {
|
|
71
|
+
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
72
|
+
delete r._id;
|
|
73
|
+
return r;
|
|
74
|
+
});
|
|
47
75
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
confirmedReservationId: reservation.id
|
|
51
|
-
};
|
|
52
|
-
yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
53
|
-
yield (0, onReservationConfirmed_1.onReservationConfirmedByAction)(actionAttributes, reservation)({ task: repos.task });
|
|
54
|
-
})));
|
|
55
|
-
yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
|
|
76
|
+
yield (0, onReservationConfirmed_1.onReservationConfirmed)(confirmedReservations)({ task: repos.task });
|
|
77
|
+
}
|
|
56
78
|
});
|
|
57
79
|
}
|
|
58
80
|
exports.confirmReservation = confirmReservation;
|
|
@@ -7,7 +7,7 @@ declare type IEventReservation = factory.reservation.IReservation<factory.reserv
|
|
|
7
7
|
/**
|
|
8
8
|
* 予約確定後のアクション
|
|
9
9
|
*/
|
|
10
|
-
export declare function onReservationConfirmedByAction(actionAttributes: factory.action.reserve.IAttributes
|
|
10
|
+
export declare function onReservationConfirmedByAction(actionAttributes: factory.action.reserve.IAttributes): (repos: {
|
|
11
11
|
task: TaskRepo;
|
|
12
12
|
}) => Promise<void>;
|
|
13
13
|
export declare function onReservationConfirmed(confirmedReservations: IEventReservation[]): (repos: {
|
|
@@ -21,7 +21,9 @@ const informReservations = settings_1.settings.onReservationStatusChanged.inform
|
|
|
21
21
|
/**
|
|
22
22
|
* 予約確定後のアクション
|
|
23
23
|
*/
|
|
24
|
-
function onReservationConfirmedByAction(actionAttributes
|
|
24
|
+
function onReservationConfirmedByAction(actionAttributes
|
|
25
|
+
// confirmedReservation: IEventReservation
|
|
26
|
+
) {
|
|
25
27
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
26
28
|
const potentialActions = actionAttributes.potentialActions;
|
|
27
29
|
const now = new Date();
|
|
@@ -45,35 +47,34 @@ function onReservationConfirmedByAction(actionAttributes, confirmedReservation)
|
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
// inform galobally
|
|
48
|
-
if (Array.isArray(informReservations)) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
50
|
+
// if (Array.isArray(informReservations)) {
|
|
51
|
+
// const reservation4inform: IReservation4informConfirmed = maskUnderName(confirmedReservation);
|
|
52
|
+
// taskAttributes.push(...informReservations.map<ITriggerWebhookTaskAttributes>((informReservation) => {
|
|
53
|
+
// const informUrl: string = String(informReservation.recipient?.url);
|
|
54
|
+
// const informReservationAttributes: InformReservationActionattributes = {
|
|
55
|
+
// agent: confirmedReservation.project,
|
|
56
|
+
// object: [reservation4inform],
|
|
57
|
+
// project: confirmedReservation.project,
|
|
58
|
+
// recipient: {
|
|
59
|
+
// id: '',
|
|
60
|
+
// name: informUrl,
|
|
61
|
+
// typeOf: factory.creativeWorkType.WebApplication,
|
|
62
|
+
// url: informUrl
|
|
63
|
+
// },
|
|
64
|
+
// typeOf: factory.actionType.InformAction
|
|
65
|
+
// };
|
|
66
|
+
// return {
|
|
67
|
+
// project: actionAttributes.project,
|
|
68
|
+
// name: factory.taskName.TriggerWebhook,
|
|
69
|
+
// status: factory.taskStatus.Ready,
|
|
70
|
+
// runsAt: now,
|
|
71
|
+
// remainingNumberOfTries: NUM_TRY_INFORM_RESERVATION,
|
|
72
|
+
// numberOfTried: 0,
|
|
73
|
+
// executionResults: [],
|
|
74
|
+
// data: informReservationAttributes
|
|
75
|
+
// };
|
|
76
|
+
// }));
|
|
77
|
+
// }
|
|
77
78
|
// タスク保管
|
|
78
79
|
if (taskAttributes.length > 0) {
|
|
79
80
|
yield repos.task.saveMany(taskAttributes);
|
|
@@ -88,6 +89,42 @@ function onReservationConfirmed(confirmedReservations) {
|
|
|
88
89
|
project: confirmedReservations[0].project,
|
|
89
90
|
reservationFor: { id: confirmedReservations[0].reservationFor.id }
|
|
90
91
|
})({ task: repos.task });
|
|
92
|
+
const now = new Date();
|
|
93
|
+
const taskAttributes = [];
|
|
94
|
+
// inform galobally
|
|
95
|
+
if (Array.isArray(informReservations)) {
|
|
96
|
+
taskAttributes.push(...informReservations.map((informReservation) => {
|
|
97
|
+
var _a;
|
|
98
|
+
const informUrl = String((_a = informReservation.recipient) === null || _a === void 0 ? void 0 : _a.url);
|
|
99
|
+
const informObject = confirmedReservations.map(factory_1.maskUnderName);
|
|
100
|
+
const informReservationAttributes = {
|
|
101
|
+
agent: confirmedReservations[0].project,
|
|
102
|
+
object: informObject,
|
|
103
|
+
project: confirmedReservations[0].project,
|
|
104
|
+
recipient: {
|
|
105
|
+
id: '',
|
|
106
|
+
name: informUrl,
|
|
107
|
+
typeOf: factory.creativeWorkType.WebApplication,
|
|
108
|
+
url: informUrl
|
|
109
|
+
},
|
|
110
|
+
typeOf: factory.actionType.InformAction
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
project: confirmedReservations[0].project,
|
|
114
|
+
name: factory.taskName.TriggerWebhook,
|
|
115
|
+
status: factory.taskStatus.Ready,
|
|
116
|
+
runsAt: now,
|
|
117
|
+
remainingNumberOfTries: factory_1.NUM_TRY_INFORM_RESERVATION,
|
|
118
|
+
numberOfTried: 0,
|
|
119
|
+
executionResults: [],
|
|
120
|
+
data: informReservationAttributes
|
|
121
|
+
};
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
// タスク保管
|
|
125
|
+
if (taskAttributes.length > 0) {
|
|
126
|
+
yield repos.task.saveMany(taskAttributes);
|
|
127
|
+
}
|
|
91
128
|
}
|
|
92
129
|
});
|
|
93
130
|
}
|
package/package.json
CHANGED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
-
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
-
|
|
10
|
-
// tslint:disable-next-line:max-func-body-length
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
13
|
-
|
|
14
|
-
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
15
|
-
const additionalPropertyRepo = new chevre.repository.AdditionalProperty(mongoose.connection);
|
|
16
|
-
|
|
17
|
-
const cursor = eventRepo.getCursor(
|
|
18
|
-
{
|
|
19
|
-
// 'project.id': { $eq: project.id },
|
|
20
|
-
'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
21
|
-
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
|
|
22
|
-
startDate: {
|
|
23
|
-
$gte: moment()
|
|
24
|
-
.add(-1, 'month')
|
|
25
|
-
.toDate()
|
|
26
|
-
}
|
|
27
|
-
// _id: { $eq: 'al6aff83w' }
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
// _id: 1,
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
console.log('events found');
|
|
34
|
-
|
|
35
|
-
const additionalPropertyNames: string[] = [];
|
|
36
|
-
const projectIds: string[] = [];
|
|
37
|
-
|
|
38
|
-
let i = 0;
|
|
39
|
-
let updateCount = 0;
|
|
40
|
-
await cursor.eachAsync(async (doc) => {
|
|
41
|
-
i += 1;
|
|
42
|
-
const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
|
|
43
|
-
|
|
44
|
-
const additionalPropertyNamesOnEvent = event.additionalProperty?.map((p) => p.name);
|
|
45
|
-
if (Array.isArray(additionalPropertyNamesOnEvent) && additionalPropertyNamesOnEvent.length > 0) {
|
|
46
|
-
console.log(additionalPropertyNamesOnEvent.length, 'additionalPropertyNamesOnEvent found', event.startDate, event.project.id);
|
|
47
|
-
additionalPropertyNames.push(...additionalPropertyNamesOnEvent);
|
|
48
|
-
projectIds.push(event.project.id);
|
|
49
|
-
additionalPropertyNamesOnEvent.forEach((name) => {
|
|
50
|
-
if (!name.match(/^[a-zA-Z]*$/)) {
|
|
51
|
-
throw new Error(`not matched ${event.project.id} ${event.id}`);
|
|
52
|
-
}
|
|
53
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
54
|
-
if (name.length < 8) {
|
|
55
|
-
throw new Error(`length matched ${event.project.id} ${event.id} ${name}`);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
for (const additionalPropertyNameOnEvent of additionalPropertyNamesOnEvent) {
|
|
60
|
-
const existings = await additionalPropertyRepo.search({
|
|
61
|
-
project: { id: { $eq: event.project.id } },
|
|
62
|
-
limit: 1,
|
|
63
|
-
page: 1,
|
|
64
|
-
name: { $regex: `^${additionalPropertyNameOnEvent}$` },
|
|
65
|
-
inCodeSet: { identifier: { $eq: event.typeOf } }
|
|
66
|
-
});
|
|
67
|
-
if (existings.length > 0) {
|
|
68
|
-
console.log('already existed', additionalPropertyNameOnEvent, event.id, event.startDate, event.project.id);
|
|
69
|
-
} else {
|
|
70
|
-
updateCount += 1;
|
|
71
|
-
await additionalPropertyRepo.save({
|
|
72
|
-
attributes: {
|
|
73
|
-
project: event.project,
|
|
74
|
-
typeOf: 'CategoryCode',
|
|
75
|
-
codeValue: additionalPropertyNameOnEvent,
|
|
76
|
-
inCodeSet: {
|
|
77
|
-
typeOf: 'CategoryCodeSet',
|
|
78
|
-
identifier: <any>event.typeOf
|
|
79
|
-
},
|
|
80
|
-
name: { ja: additionalPropertyNameOnEvent }
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
console.log('created', additionalPropertyNameOnEvent, event.id, event.startDate, event.project.id);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
console.log(i, 'events checked');
|
|
89
|
-
console.log(updateCount, 'events updated');
|
|
90
|
-
console.log([...new Set(additionalPropertyNames)]);
|
|
91
|
-
console.log([...new Set(projectIds)]);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
main()
|
|
95
|
-
.then()
|
|
96
|
-
.catch(console.error);
|