@chevre/domain 21.5.0 → 21.6.0-alpha.1
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/migrateEventOrganizer.ts +78 -49
- package/example/src/chevre/migrateMovieAvailabilityStarts.ts +70 -0
- package/lib/chevre/repo/event.d.ts +15 -0
- package/lib/chevre/repo/event.js +12 -0
- package/lib/chevre/repo/offer.d.ts +15 -0
- package/lib/chevre/repo/offer.js +21 -0
- package/lib/chevre/repo/offerCatalog.d.ts +14 -0
- package/lib/chevre/repo/offerCatalog.js +21 -0
- package/lib/chevre/repo/product.d.ts +8 -0
- package/lib/chevre/repo/product.js +9 -0
- package/lib/chevre/service/event/createEvent.js +7 -2
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +4 -0
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +106 -1
- package/lib/chevre/service/task/onResourceUpdated.js +4 -0
- package/package.json +3 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// tslint:disable:no-console
|
|
2
|
-
|
|
2
|
+
import * as moment from 'moment';
|
|
3
3
|
import * as mongoose from 'mongoose';
|
|
4
4
|
|
|
5
5
|
import { chevre } from '../../../lib/index';
|
|
6
6
|
|
|
7
7
|
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
-
|
|
8
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
9
|
|
|
10
10
|
// tslint:disable-next-line:max-func-body-length
|
|
11
11
|
async function main() {
|
|
@@ -17,20 +17,20 @@ async function main() {
|
|
|
17
17
|
const cursor = eventRepo.getCursor(
|
|
18
18
|
{
|
|
19
19
|
// 'project.id': { $eq: project.id },
|
|
20
|
-
|
|
20
|
+
'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
21
21
|
typeOf: {
|
|
22
22
|
$in: [
|
|
23
|
-
chevre.factory.eventType.ScreeningEvent,
|
|
23
|
+
// chevre.factory.eventType.ScreeningEvent,
|
|
24
24
|
chevre.factory.eventType.ScreeningEventSeries
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
|
-
organizer: { $exists:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
organizer: { $exists: true },
|
|
28
|
+
startDate: {
|
|
29
|
+
$gte: moment()
|
|
30
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
31
|
+
.add(-3, 'months')
|
|
32
|
+
.toDate()
|
|
33
|
+
}
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
_id: 1,
|
|
@@ -46,6 +46,7 @@ async function main() {
|
|
|
46
46
|
|
|
47
47
|
let i = 0;
|
|
48
48
|
let updateCount = 0;
|
|
49
|
+
let invalidOrganizerCount = 0;
|
|
49
50
|
await cursor.eachAsync(async (doc) => {
|
|
50
51
|
i += 1;
|
|
51
52
|
const event: Pick<
|
|
@@ -57,48 +58,54 @@ async function main() {
|
|
|
57
58
|
> = doc.toObject();
|
|
58
59
|
|
|
59
60
|
const organizerId = event.organizer?.id;
|
|
61
|
+
|
|
62
|
+
let movieTheaterId: string;
|
|
63
|
+
let movieTheaterBranchCode: string;
|
|
64
|
+
if (event.typeOf === chevre.factory.eventType.ScreeningEventSeries) {
|
|
65
|
+
movieTheaterId = event.location.id;
|
|
66
|
+
movieTheaterBranchCode = event.location.branchCode;
|
|
67
|
+
} else {
|
|
68
|
+
movieTheaterId = event.superEvent.location.id;
|
|
69
|
+
movieTheaterBranchCode = event.superEvent.location.branchCode;
|
|
70
|
+
}
|
|
71
|
+
const movieTheaters = <Pick<
|
|
72
|
+
chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom,
|
|
73
|
+
'parentOrganization' | 'branchCode'
|
|
74
|
+
>[]>
|
|
75
|
+
await placeRepo.searchMovieTheaters(
|
|
76
|
+
{
|
|
77
|
+
limit: 1,
|
|
78
|
+
page: 1,
|
|
79
|
+
project: { id: { $eq: event.project.id } },
|
|
80
|
+
id: { $eq: movieTheaterId }
|
|
81
|
+
},
|
|
82
|
+
['parentOrganization', 'branchCode'],
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
const movieTheater = movieTheaters.shift();
|
|
86
|
+
const sellerId = movieTheater?.parentOrganization?.id;
|
|
87
|
+
console.log(
|
|
88
|
+
'movieTheater found',
|
|
89
|
+
event.project.id, event.id, event.startDate, 'sellerId:', sellerId,
|
|
90
|
+
'movieTheaterId:', movieTheaterId,
|
|
91
|
+
'movieTheaterBranchCode:', movieTheaterBranchCode,
|
|
92
|
+
i
|
|
93
|
+
);
|
|
94
|
+
|
|
60
95
|
const alreadyMigrated = typeof organizerId === 'string';
|
|
61
96
|
|
|
62
97
|
if (alreadyMigrated) {
|
|
63
98
|
console.log('already exist...', event.project.id, event.id, event.startDate, organizerId, i);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let movieTheaterBranchCode: string;
|
|
67
|
-
if (event.typeOf === chevre.factory.eventType.ScreeningEventSeries) {
|
|
68
|
-
movieTheaterId = event.location.id;
|
|
69
|
-
movieTheaterBranchCode = event.location.branchCode;
|
|
99
|
+
if (organizerId === sellerId) {
|
|
100
|
+
console.log('organizerId is valid', event.project.id, event.id, event.startDate, organizerId, i);
|
|
70
101
|
} else {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await placeRepo.searchMovieTheaters(
|
|
79
|
-
{
|
|
80
|
-
limit: 1,
|
|
81
|
-
page: 1,
|
|
82
|
-
project: { id: { $eq: event.project.id } },
|
|
83
|
-
id: { $eq: movieTheaterId }
|
|
84
|
-
},
|
|
85
|
-
['parentOrganization', 'branchCode'],
|
|
86
|
-
[]
|
|
87
|
-
);
|
|
88
|
-
const movieTheater = movieTheaters.shift();
|
|
89
|
-
const sellerId = movieTheater?.parentOrganization?.id;
|
|
90
|
-
console.log(
|
|
91
|
-
'movieTheater found',
|
|
92
|
-
event.project.id, event.id, event.startDate, 'sellerId:', sellerId,
|
|
93
|
-
'movieTheaterId:', movieTheaterId,
|
|
94
|
-
'movieTheaterBranchCode:', movieTheaterBranchCode,
|
|
95
|
-
i
|
|
96
|
-
);
|
|
97
|
-
// if (typeof sellerId !== 'string') {
|
|
98
|
-
// throw new Error('movieTheater not found');
|
|
99
|
-
// }
|
|
100
|
-
if (typeof sellerId === 'string') {
|
|
101
|
-
const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
|
|
102
|
+
invalidOrganizerCount += 1;
|
|
103
|
+
|
|
104
|
+
// organizerを修正する
|
|
105
|
+
if (typeof sellerId !== 'string') {
|
|
106
|
+
throw new Error('movieTheater not found');
|
|
107
|
+
}
|
|
108
|
+
const fixedOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
|
|
102
109
|
id: sellerId
|
|
103
110
|
};
|
|
104
111
|
console.log('updating event...', event.project.id, event.id, event.startDate, i);
|
|
@@ -107,17 +114,39 @@ async function main() {
|
|
|
107
114
|
id: event.id,
|
|
108
115
|
attributes: <any>{
|
|
109
116
|
typeOf: event.typeOf,
|
|
110
|
-
organizer:
|
|
117
|
+
organizer: fixedOrganizer
|
|
111
118
|
}
|
|
112
119
|
});
|
|
113
120
|
updateCount += 1;
|
|
114
121
|
console.log('updated.', event.project.id, event.id, event.startDate, i);
|
|
115
122
|
}
|
|
123
|
+
} else {
|
|
124
|
+
throw new Error('organizer not found');
|
|
125
|
+
// if (typeof sellerId !== 'string') {
|
|
126
|
+
// throw new Error('movieTheater not found');
|
|
127
|
+
// }
|
|
128
|
+
// if (typeof sellerId === 'string') {
|
|
129
|
+
// const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
|
|
130
|
+
// id: sellerId
|
|
131
|
+
// };
|
|
132
|
+
// console.log('updating event...', event.project.id, event.id, event.startDate, i);
|
|
133
|
+
// await eventRepo.updatePartiallyById({
|
|
134
|
+
// project: { id: event.project.id },
|
|
135
|
+
// id: event.id,
|
|
136
|
+
// attributes: <any>{
|
|
137
|
+
// typeOf: event.typeOf,
|
|
138
|
+
// organizer: newOrganizer
|
|
139
|
+
// }
|
|
140
|
+
// });
|
|
141
|
+
// updateCount += 1;
|
|
142
|
+
// console.log('updated.', event.project.id, event.id, event.startDate, i);
|
|
143
|
+
// }
|
|
116
144
|
}
|
|
117
145
|
});
|
|
118
146
|
|
|
119
147
|
console.log(i, 'events checked');
|
|
120
148
|
console.log(updateCount, 'events updated');
|
|
149
|
+
console.log(invalidOrganizerCount, 'invalid');
|
|
121
150
|
}
|
|
122
151
|
|
|
123
152
|
main()
|
|
@@ -0,0 +1,70 @@
|
|
|
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, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const creativeWorkRepo = new chevre.repository.CreativeWork(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = creativeWorkRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'offers.availabilityEnds': { $exists: true }
|
|
19
|
+
},
|
|
20
|
+
{}
|
|
21
|
+
);
|
|
22
|
+
console.log('creativeWorks found');
|
|
23
|
+
|
|
24
|
+
let i = 0;
|
|
25
|
+
let updateCount = 0;
|
|
26
|
+
let datePublishedUndefinedCount = 0;
|
|
27
|
+
await cursor.eachAsync(async (doc) => {
|
|
28
|
+
i += 1;
|
|
29
|
+
const movie: chevre.factory.creativeWork.movie.ICreativeWork = doc.toObject();
|
|
30
|
+
|
|
31
|
+
const availabilityEnds = movie.offers.availabilityEnds;
|
|
32
|
+
let availabilityStarts = movie.offers.availabilityStarts;
|
|
33
|
+
const createdAt: Date = (<any>movie).createdAt;
|
|
34
|
+
if (!(createdAt instanceof Date)) {
|
|
35
|
+
throw new Error('createdAt not Date');
|
|
36
|
+
}
|
|
37
|
+
const alreadyMigrated = availabilityStarts instanceof Date;
|
|
38
|
+
|
|
39
|
+
if (alreadyMigrated) {
|
|
40
|
+
console.log('already exist...', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, i);
|
|
41
|
+
} else {
|
|
42
|
+
if (movie.datePublished === undefined) {
|
|
43
|
+
console.error('movie.datePublished undefined', movie.project.id, movie.id, movie.identifier, i);
|
|
44
|
+
// throw new Error('movie.datePublished undefined');
|
|
45
|
+
datePublishedUndefinedCount += 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
availabilityStarts = (movie.datePublished !== undefined)
|
|
49
|
+
? moment(movie.datePublished)
|
|
50
|
+
.toDate()
|
|
51
|
+
: moment(createdAt)
|
|
52
|
+
.toDate();
|
|
53
|
+
console.log('updating movie...', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, i);
|
|
54
|
+
await creativeWorkRepo.saveMovie(<any>{
|
|
55
|
+
id: String(movie.id),
|
|
56
|
+
'offers.availabilityStarts': availabilityStarts
|
|
57
|
+
});
|
|
58
|
+
updateCount += 1;
|
|
59
|
+
console.log('updated.', movie.project.id, movie.id, movie.identifier, availabilityStarts, availabilityEnds, i);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
console.log(i, 'creativeWorks checked');
|
|
64
|
+
console.log(updateCount, 'creativeWorks updated');
|
|
65
|
+
console.log(datePublishedUndefinedCount, 'datePublishedUndefinedCount');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
main()
|
|
69
|
+
.then()
|
|
70
|
+
.catch(console.error);
|
|
@@ -237,6 +237,21 @@ export declare class MongoRepository {
|
|
|
237
237
|
};
|
|
238
238
|
};
|
|
239
239
|
}): Promise<import("mongodb").DeleteResult>;
|
|
240
|
+
/**
|
|
241
|
+
* 興行(プロダクト)から削除する
|
|
242
|
+
*/
|
|
243
|
+
deleteManyByItemOfferedId(params: {
|
|
244
|
+
project: {
|
|
245
|
+
id: string;
|
|
246
|
+
};
|
|
247
|
+
offers: {
|
|
248
|
+
itemOffered: {
|
|
249
|
+
id: {
|
|
250
|
+
$in: string[];
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
}): Promise<import("mongodb").DeleteResult>;
|
|
240
255
|
deleteByProject(params: {
|
|
241
256
|
project: {
|
|
242
257
|
id: string;
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -954,6 +954,18 @@ class MongoRepository {
|
|
|
954
954
|
.exec();
|
|
955
955
|
});
|
|
956
956
|
}
|
|
957
|
+
/**
|
|
958
|
+
* 興行(プロダクト)から削除する
|
|
959
|
+
*/
|
|
960
|
+
deleteManyByItemOfferedId(params) {
|
|
961
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
962
|
+
return this.eventModel.deleteMany({
|
|
963
|
+
'project.id': { $eq: params.project.id },
|
|
964
|
+
'offers.itemOffered.id': { $exists: true, $in: params.offers.itemOffered.id.$in }
|
|
965
|
+
})
|
|
966
|
+
.exec();
|
|
967
|
+
});
|
|
968
|
+
}
|
|
957
969
|
deleteByProject(params) {
|
|
958
970
|
return __awaiter(this, void 0, void 0, function* () {
|
|
959
971
|
yield this.eventModel.deleteMany({
|
|
@@ -71,6 +71,21 @@ export declare class MongoRepository {
|
|
|
71
71
|
attributes: factory.unitPriceOffer.IUnitPriceOffer;
|
|
72
72
|
upsert?: boolean;
|
|
73
73
|
}[]): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* プロダクトIDからアドオンを除外する
|
|
76
|
+
*/
|
|
77
|
+
pullAddOns(params: {
|
|
78
|
+
project: {
|
|
79
|
+
id: string;
|
|
80
|
+
};
|
|
81
|
+
addOn: {
|
|
82
|
+
itemOffered: {
|
|
83
|
+
id: {
|
|
84
|
+
$in: string[];
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}): Promise<import("mongodb").UpdateResult | undefined>;
|
|
74
89
|
deleteById(params: {
|
|
75
90
|
id: string;
|
|
76
91
|
}): Promise<void>;
|
package/lib/chevre/repo/offer.js
CHANGED
|
@@ -494,6 +494,27 @@ class MongoRepository {
|
|
|
494
494
|
}
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* プロダクトIDからアドオンを除外する
|
|
499
|
+
*/
|
|
500
|
+
pullAddOns(params) {
|
|
501
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
if (params.addOn.itemOffered.id.$in.length === 0) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
return this.offerModel.updateMany({
|
|
506
|
+
'project.id': { $eq: params.project.id },
|
|
507
|
+
'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
|
|
508
|
+
}, {
|
|
509
|
+
$pull: {
|
|
510
|
+
addOn: {
|
|
511
|
+
'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
})
|
|
515
|
+
.exec();
|
|
516
|
+
});
|
|
517
|
+
}
|
|
497
518
|
deleteById(params) {
|
|
498
519
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
520
|
yield this.offerModel.findOneAndRemove({ _id: params.id })
|
|
@@ -52,6 +52,20 @@ export declare class MongoRepository {
|
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
}): Promise<void>;
|
|
55
|
+
pullItemListElement(params: {
|
|
56
|
+
project: {
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
$pull: {
|
|
60
|
+
itemListElement: {
|
|
61
|
+
$elemMatch: {
|
|
62
|
+
id: {
|
|
63
|
+
$in: string[];
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}): Promise<import("mongodb").UpdateResult | undefined>;
|
|
55
69
|
search(params: factory.offerCatalog.ISearchConditions): Promise<(Omit<factory.offerCatalog.IOfferCatalog, 'itemListElement'> & {
|
|
56
70
|
numberOfItems?: number;
|
|
57
71
|
})[]>;
|
|
@@ -178,6 +178,27 @@ class MongoRepository {
|
|
|
178
178
|
.exec();
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
|
+
pullItemListElement(params) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
if (params.$pull.itemListElement.$elemMatch.id.$in.length === 0) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
return this.offerCatalogModel.updateMany({
|
|
187
|
+
'project.id': { $eq: params.project.id },
|
|
188
|
+
'itemListElement.id': {
|
|
189
|
+
$exists: true,
|
|
190
|
+
$in: params.$pull.itemListElement.$elemMatch.id.$in
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
$pull: {
|
|
194
|
+
itemListElement: {
|
|
195
|
+
id: { $in: params.$pull.itemListElement.$elemMatch.id.$in }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
})
|
|
199
|
+
.exec();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
181
202
|
search(params) {
|
|
182
203
|
var _a;
|
|
183
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -68,6 +68,14 @@ export declare class MongoRepository {
|
|
|
68
68
|
*/
|
|
69
69
|
createIfNotExist?: boolean;
|
|
70
70
|
}): Promise<factory.product.IProduct>;
|
|
71
|
+
deleteByHasOfferCatalog(params: {
|
|
72
|
+
project: {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
hasOfferCatalog: {
|
|
76
|
+
id: string;
|
|
77
|
+
};
|
|
78
|
+
}): Promise<import("mongodb").DeleteResult>;
|
|
71
79
|
/**
|
|
72
80
|
* プロジェクト指定で削除する
|
|
73
81
|
*/
|
|
@@ -371,6 +371,15 @@ class MongoRepository {
|
|
|
371
371
|
return doc.toObject();
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
|
+
deleteByHasOfferCatalog(params) {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
return this.productModel.deleteMany({
|
|
377
|
+
'project.id': { $eq: params.project.id },
|
|
378
|
+
'hasOfferCatalog.id': { $exists: true, $eq: params.hasOfferCatalog.id }
|
|
379
|
+
})
|
|
380
|
+
.exec();
|
|
381
|
+
});
|
|
382
|
+
}
|
|
374
383
|
/**
|
|
375
384
|
* プロジェクト指定で削除する
|
|
376
385
|
*/
|
|
@@ -37,7 +37,7 @@ function createEvent(params) {
|
|
|
37
37
|
const firstCreatingEventParams = creatingEventParams[0];
|
|
38
38
|
const movieTheaters = yield repos.place.searchMovieTheaters({
|
|
39
39
|
project: { id: { $eq: actionAttributes.project.id } }
|
|
40
|
-
}, ['_id', 'branchCode', 'kanaName', 'name'], []);
|
|
40
|
+
}, ['_id', 'branchCode', 'kanaName', 'name', 'parentOrganization'], []);
|
|
41
41
|
creatingEventParams = movieTheaters.map((movieTheater) => {
|
|
42
42
|
const location = {
|
|
43
43
|
branchCode: movieTheater.branchCode,
|
|
@@ -46,8 +46,13 @@ function createEvent(params) {
|
|
|
46
46
|
name: movieTheater.name,
|
|
47
47
|
typeOf: factory.placeType.MovieTheater
|
|
48
48
|
};
|
|
49
|
+
const organizer = {
|
|
50
|
+
id: movieTheater.parentOrganization.id
|
|
51
|
+
};
|
|
49
52
|
return {
|
|
50
|
-
attributes: Object.assign(Object.assign({}, firstCreatingEventParams.attributes), { location
|
|
53
|
+
attributes: Object.assign(Object.assign({}, firstCreatingEventParams.attributes), { location,
|
|
54
|
+
// organizerがfirstCreatingEventParamsにそろってしまうbug対応(2023-08-03~)
|
|
55
|
+
organizer })
|
|
51
56
|
};
|
|
52
57
|
});
|
|
53
58
|
}
|
|
@@ -5,6 +5,8 @@ import { MongoRepository as CategoryCodeRepo } from '../../../repo/categoryCode'
|
|
|
5
5
|
import { MongoRepository as CreativeWorkRepo } from '../../../repo/creativeWork';
|
|
6
6
|
import { MongoRepository as EventRepo } from '../../../repo/event';
|
|
7
7
|
import { MongoRepository as MemberRepo } from '../../../repo/member';
|
|
8
|
+
import { MongoRepository as OfferRepo } from '../../../repo/offer';
|
|
9
|
+
import { MongoRepository as OfferCatalogRepo } from '../../../repo/offerCatalog';
|
|
8
10
|
import { MongoRepository as PaymentServiceProviderRepo } from '../../../repo/paymentServiceProvider';
|
|
9
11
|
import { MongoRepository as PlaceRepo } from '../../../repo/place';
|
|
10
12
|
import { MongoRepository as ProductRepo } from '../../../repo/product';
|
|
@@ -18,6 +20,8 @@ export declare function onResourceDeleted(params: factory.task.onResourceUpdated
|
|
|
18
20
|
event: EventRepo;
|
|
19
21
|
member: MemberRepo;
|
|
20
22
|
paymentServiceProvider: PaymentServiceProviderRepo;
|
|
23
|
+
offer: OfferRepo;
|
|
24
|
+
offerCatalog: OfferCatalogRepo;
|
|
21
25
|
place: PlaceRepo;
|
|
22
26
|
product: ProductRepo;
|
|
23
27
|
productOffer: ProductOfferRepo;
|
|
@@ -41,8 +41,21 @@ function onResourceDeleted(params) {
|
|
|
41
41
|
ids: params.id
|
|
42
42
|
})(repos);
|
|
43
43
|
break;
|
|
44
|
+
case factory.offerType.Offer:
|
|
45
|
+
yield deleteResourcesByOffer({
|
|
46
|
+
project: { id: params.project.id },
|
|
47
|
+
ids: params.id
|
|
48
|
+
})(repos);
|
|
49
|
+
break;
|
|
50
|
+
case 'OfferCatalog':
|
|
51
|
+
yield deleteResourcesByOfferCatalog({
|
|
52
|
+
project: { id: params.project.id },
|
|
53
|
+
ids: params.id
|
|
54
|
+
})(repos);
|
|
55
|
+
break;
|
|
44
56
|
default:
|
|
45
|
-
|
|
57
|
+
// no op
|
|
58
|
+
throw new factory.errors.NotImplemented(`${params.typeOf} onDeleted not implemented`);
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
});
|
|
@@ -228,3 +241,95 @@ function deleteResourcesBySeller(params) {
|
|
|
228
241
|
}
|
|
229
242
|
});
|
|
230
243
|
}
|
|
244
|
+
function deleteResourcesByOffer(params) {
|
|
245
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
if (params.ids.length !== 1) {
|
|
247
|
+
throw new factory.errors.Argument('id', 'id.length must be 1');
|
|
248
|
+
}
|
|
249
|
+
for (const offerId of params.ids) {
|
|
250
|
+
const deleteActionAttributes = {
|
|
251
|
+
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
252
|
+
object: { id: offerId, typeOf: factory.offerType.Offer },
|
|
253
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
254
|
+
typeOf: factory.actionType.DeleteAction
|
|
255
|
+
};
|
|
256
|
+
let deleteResult;
|
|
257
|
+
const action = yield repos.action.start(deleteActionAttributes);
|
|
258
|
+
try {
|
|
259
|
+
// カタログからpullItemListElement
|
|
260
|
+
const updateCatalogResult = yield repos.offerCatalog.pullItemListElement({
|
|
261
|
+
project: { id: params.project.id },
|
|
262
|
+
$pull: { itemListElement: { $elemMatch: { id: { $in: [offerId] } } } }
|
|
263
|
+
});
|
|
264
|
+
deleteResult = { updateCatalogResult };
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
try {
|
|
268
|
+
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
269
|
+
yield repos.action.giveUp({ typeOf: deleteActionAttributes.typeOf, id: action.id, error: actionError });
|
|
270
|
+
}
|
|
271
|
+
catch (_) {
|
|
272
|
+
// no op
|
|
273
|
+
}
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
yield repos.action.complete({ typeOf: deleteActionAttributes.typeOf, id: action.id, result: deleteResult });
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function deleteResourcesByOfferCatalog(params) {
|
|
281
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
if (params.ids.length !== 1) {
|
|
283
|
+
throw new factory.errors.Argument('id', 'id.length must be 1');
|
|
284
|
+
}
|
|
285
|
+
for (const catalogId of params.ids) {
|
|
286
|
+
const deleteActionAttributes = {
|
|
287
|
+
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
288
|
+
object: { id: catalogId, typeOf: 'OfferCatalog' },
|
|
289
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
290
|
+
typeOf: factory.actionType.DeleteAction
|
|
291
|
+
};
|
|
292
|
+
let deleteResult;
|
|
293
|
+
const action = yield repos.action.start(deleteActionAttributes);
|
|
294
|
+
try {
|
|
295
|
+
// カタログからプロダクト検索
|
|
296
|
+
const productsWithCatalog = yield repos.product.search({
|
|
297
|
+
project: { id: { $eq: params.project.id } },
|
|
298
|
+
hasOfferCatalog: { id: { $eq: catalogId } }
|
|
299
|
+
}, ['_id'], []);
|
|
300
|
+
let deleteEventResult;
|
|
301
|
+
let updateOfferResult;
|
|
302
|
+
if (productsWithCatalog.length > 0) {
|
|
303
|
+
const deletingProductIds = productsWithCatalog.map((product) => product.id);
|
|
304
|
+
// 興行を設定されたイベント削除
|
|
305
|
+
deleteEventResult = yield repos.event.deleteManyByItemOfferedId({
|
|
306
|
+
project: { id: params.project.id },
|
|
307
|
+
offers: { itemOffered: { id: { $in: deletingProductIds } } }
|
|
308
|
+
});
|
|
309
|
+
// アドオンから除外
|
|
310
|
+
updateOfferResult = yield repos.offer.pullAddOns({
|
|
311
|
+
project: { id: params.project.id },
|
|
312
|
+
addOn: { itemOffered: { id: { $in: deletingProductIds } } }
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
// プロダクト削除
|
|
316
|
+
const deleteProductResult = yield repos.product.deleteByHasOfferCatalog({
|
|
317
|
+
project: { id: params.project.id },
|
|
318
|
+
hasOfferCatalog: { id: catalogId }
|
|
319
|
+
});
|
|
320
|
+
deleteResult = { deleteEventResult, deleteProductResult, updateOfferResult };
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
try {
|
|
324
|
+
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
325
|
+
yield repos.action.giveUp({ typeOf: deleteActionAttributes.typeOf, id: action.id, error: actionError });
|
|
326
|
+
}
|
|
327
|
+
catch (_) {
|
|
328
|
+
// no op
|
|
329
|
+
}
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
332
|
+
yield repos.action.complete({ typeOf: deleteActionAttributes.typeOf, id: action.id, result: deleteResult });
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
@@ -17,6 +17,8 @@ const categoryCode_1 = require("../../repo/categoryCode");
|
|
|
17
17
|
const creativeWork_1 = require("../../repo/creativeWork");
|
|
18
18
|
const event_1 = require("../../repo/event");
|
|
19
19
|
const member_1 = require("../../repo/member");
|
|
20
|
+
const offer_1 = require("../../repo/offer");
|
|
21
|
+
const offerCatalog_1 = require("../../repo/offerCatalog");
|
|
20
22
|
const paymentServiceProvider_1 = require("../../repo/paymentServiceProvider");
|
|
21
23
|
const place_1 = require("../../repo/place");
|
|
22
24
|
const product_1 = require("../../repo/product");
|
|
@@ -37,6 +39,8 @@ function call(data) {
|
|
|
37
39
|
creativeWork: new creativeWork_1.MongoRepository(connectionSettings.connection),
|
|
38
40
|
event: new event_1.MongoRepository(connectionSettings.connection),
|
|
39
41
|
member: new member_1.MongoRepository(connectionSettings.connection),
|
|
42
|
+
offer: new offer_1.MongoRepository(connectionSettings.connection),
|
|
43
|
+
offerCatalog: new offerCatalog_1.MongoRepository(connectionSettings.connection),
|
|
40
44
|
paymentServiceProvider: new paymentServiceProvider_1.MongoRepository(connectionSettings.connection),
|
|
41
45
|
place: new place_1.MongoRepository(connectionSettings.connection),
|
|
42
46
|
product: new product_1.MongoRepository(connectionSettings.connection),
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "3.162.
|
|
12
|
+
"@chevre/factory": "4.323.0",
|
|
13
|
+
"@cinerino/sdk": "3.162.2",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -117,5 +117,5 @@
|
|
|
117
117
|
"postversion": "git push origin --tags",
|
|
118
118
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
119
119
|
},
|
|
120
|
-
"version": "21.
|
|
120
|
+
"version": "21.6.0-alpha.1"
|
|
121
121
|
}
|