@chevre/domain 21.19.0-alpha.8 → 21.19.0-alpha.9

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.
@@ -0,0 +1,18 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // tslint:disable-next-line:max-func-body-length
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
11
+
12
+ const result = await paymentServiceRepo.deleteOldPaymentServices();
13
+ console.log(result);
14
+ }
15
+
16
+ main()
17
+ .then()
18
+ .catch(console.error);
@@ -58,5 +58,6 @@ export declare class MongoRepository {
58
58
  id: string;
59
59
  }): Promise<factory.product.IAvailableChannel>;
60
60
  migratePaymentServicesToNewCollection(): Promise<void>;
61
+ deleteOldPaymentServices(): Promise<import("mongodb").DeleteResult>;
61
62
  }
62
63
  export {};
@@ -324,7 +324,7 @@ class MongoRepository {
324
324
  const existingPaymentService = doc.toObject();
325
325
  const { _id, id, createdAt, updatedAt, offers } = existingPaymentService, setFields = __rest(existingPaymentService, ["_id", "id", "createdAt", "updatedAt", "offers"]);
326
326
  // tslint:disable-next-line:no-console
327
- console.log('migrating paymentService...', setFields, id, i);
327
+ // console.log('migrating paymentService...', setFields, id, i);
328
328
  yield this.paymentServiceModel.findByIdAndUpdate(id, {
329
329
  // $setOnInsert: { _id },
330
330
  $set: setFields
@@ -335,5 +335,18 @@ class MongoRepository {
335
335
  }));
336
336
  });
337
337
  }
338
+ deleteOldPaymentServices() {
339
+ return __awaiter(this, void 0, void 0, function* () {
340
+ return this.productModel.deleteMany({
341
+ typeOf: {
342
+ $in: [
343
+ factory.service.paymentService.PaymentServiceType.CreditCard,
344
+ factory.service.paymentService.PaymentServiceType.MovieTicket
345
+ ]
346
+ }
347
+ })
348
+ .exec();
349
+ });
350
+ }
338
351
  }
339
352
  exports.MongoRepository = MongoRepository;
@@ -9,8 +9,10 @@ export declare function createInformOfferCatalogTasks(params: {
9
9
  };
10
10
  ids: string[];
11
11
  typeOf: factory.offerCatalog.IOfferCatalog['typeOf'];
12
+ isOfferCatalogItem: boolean;
12
13
  }): (repos: {
13
14
  offerCatalog: OfferCatalogRepo;
15
+ offerCatalogItem: OfferCatalogItemRepo;
14
16
  task: TaskRepo;
15
17
  }) => Promise<void>;
16
18
  /**
@@ -19,11 +19,15 @@ function createInformOfferCatalogTasks(params) {
19
19
  if (params.ids.length === 0) {
20
20
  return;
21
21
  }
22
- const offerCatalogs = yield repos.offerCatalog.search({
23
- id: { $in: params.ids }
24
- });
25
- const offerCatalogs4inform = offerCatalogs.map(({ id, typeOf, name, identifier, project }) => {
26
- return { id, typeOf, name, identifier, project };
22
+ let offerCatalogs = [];
23
+ if (params.isOfferCatalogItem) {
24
+ offerCatalogs = yield repos.offerCatalogItem.search({ id: { $in: params.ids } }, {});
25
+ }
26
+ else {
27
+ offerCatalogs = yield repos.offerCatalog.search({ id: { $in: params.ids } });
28
+ }
29
+ const offerCatalogs4inform = offerCatalogs.map(({ id, typeOf, name, identifier, project, numberOfItems }) => {
30
+ return { id, typeOf, name, identifier, project, numberOfItems };
27
31
  });
28
32
  if (offerCatalogs4inform.length > 0) {
29
33
  const taskRunsAt = new Date();
@@ -122,7 +122,8 @@ function onResourceUpdated(params) {
122
122
  yield (0, onOfferCatalogUpdated_1.createInformOfferCatalogTasks)({
123
123
  project: { id: params.project.id },
124
124
  ids: params.id,
125
- typeOf: params.typeOf
125
+ typeOf: params.typeOf,
126
+ isOfferCatalogItem: params.isOfferCatalogItem === true
126
127
  })(repos);
127
128
  break;
128
129
  default:
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.19.0-alpha.8"
118
+ "version": "21.19.0-alpha.9"
119
119
  }