@chevre/domain 21.6.0-alpha.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.
@@ -5,7 +5,7 @@ import * as mongoose from 'mongoose';
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
7
  // const project = { id: String(process.env.PROJECT_ID) };
8
- // const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
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,7 +17,7 @@ async function main() {
17
17
  const cursor = eventRepo.getCursor(
18
18
  {
19
19
  // 'project.id': { $eq: project.id },
20
- // 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
21
21
  typeOf: {
22
22
  $in: [
23
23
  // chevre.factory.eventType.ScreeningEvent,
@@ -96,16 +96,16 @@ async function main() {
96
96
 
97
97
  if (alreadyMigrated) {
98
98
  console.log('already exist...', event.project.id, event.id, event.startDate, organizerId, i);
99
- if (organizerId !== sellerId) {
99
+ if (organizerId === sellerId) {
100
+ console.log('organizerId is valid', event.project.id, event.id, event.startDate, organizerId, i);
101
+ } else {
100
102
  invalidOrganizerCount += 1;
101
- }
102
- } else {
103
- throw new Error('organizer not found');
104
- // if (typeof sellerId !== 'string') {
105
- // throw new Error('movieTheater not found');
106
- // }
107
- if (typeof sellerId === 'string') {
108
- const newOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
103
+
104
+ // organizerを修正する
105
+ if (typeof sellerId !== 'string') {
106
+ throw new Error('movieTheater not found');
107
+ }
108
+ const fixedOrganizer: chevre.factory.event.screeningEventSeries.IOrganizer = {
109
109
  id: sellerId
110
110
  };
111
111
  console.log('updating event...', event.project.id, event.id, event.startDate, i);
@@ -114,12 +114,33 @@ async function main() {
114
114
  id: event.id,
115
115
  attributes: <any>{
116
116
  typeOf: event.typeOf,
117
- organizer: newOrganizer
117
+ organizer: fixedOrganizer
118
118
  }
119
119
  });
120
120
  updateCount += 1;
121
121
  console.log('updated.', event.project.id, event.id, event.startDate, i);
122
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
+ // }
123
144
  }
124
145
  });
125
146
 
@@ -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;
@@ -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>;
@@ -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
  */
@@ -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
- // no op
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.321.1",
13
- "@cinerino/sdk": "3.162.1",
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.6.0-alpha.0"
120
+ "version": "21.6.0-alpha.1"
121
121
  }