@chevre/domain 20.2.0-alpha.26 → 20.2.0-alpha.27

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,51 @@
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
+ // tslint:disable-next-line:max-func-body-length
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const projectRepo = new chevre.repository.Project(mongoose.connection);
12
+
13
+ const cursor = projectRepo.getCursor(
14
+ {
15
+ },
16
+ {
17
+ // _id: 1,
18
+ }
19
+ );
20
+ console.log('projects found');
21
+
22
+ let i = 0;
23
+ let updateCount = 0;
24
+ // tslint:disable-next-line:max-func-body-length
25
+ await cursor.eachAsync(async (doc) => {
26
+ i += 1;
27
+ const project: chevre.factory.project.IProject = doc.toObject();
28
+
29
+ const useEventServiceAsProduct = project.subscription?.useEventServiceAsProduct;
30
+ const alreadyMigrated = useEventServiceAsProduct === true;
31
+
32
+ if (alreadyMigrated) {
33
+ console.log('already migrated.', project.id, i);
34
+ } else {
35
+ console.log(
36
+ 'updating product...', project.id, i);
37
+ await projectRepo.findByIdAndIUpdate({
38
+ id: project.id,
39
+ subscription: { useEventServiceAsProduct: true }
40
+ });
41
+ updateCount += 1;
42
+ console.log('updated...', project.id, i);
43
+ }
44
+ });
45
+ console.log(i, 'projects checked');
46
+ console.log(updateCount, 'projects updated');
47
+ }
48
+
49
+ main()
50
+ .then()
51
+ .catch(console.error);
@@ -10,6 +10,12 @@ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
10
10
  */
11
11
  const schema = new mongoose.Schema({
12
12
  _id: String,
13
+ aggregateReservation: mongoose.SchemaTypes.Mixed,
14
+ alternateName: String,
15
+ logo: String,
16
+ name: String,
17
+ settings: mongoose.SchemaTypes.Mixed,
18
+ subscription: mongoose.SchemaTypes.Mixed,
13
19
  typeOf: {
14
20
  type: String,
15
21
  required: true
@@ -19,7 +25,7 @@ const schema = new mongoose.Schema({
19
25
  id: true,
20
26
  read: 'primaryPreferred',
21
27
  writeConcern: writeConcern,
22
- strict: false,
28
+ strict: true,
23
29
  useNestedStrict: true,
24
30
  timestamps: {
25
31
  createdAt: 'createdAt',
@@ -10,7 +10,6 @@ export declare class MongoRepository {
10
10
  findById(conditions: {
11
11
  id: string;
12
12
  }, projection?: any): Promise<factory.project.IProject>;
13
- count(params: factory.project.ISearchConditions): Promise<number>;
14
13
  /**
15
14
  * プロジェクト検索
16
15
  */
@@ -24,6 +23,9 @@ export declare class MongoRepository {
24
23
  settings?: {
25
24
  sendgridApiKey?: string;
26
25
  };
26
+ subscription?: {
27
+ useEventServiceAsProduct?: boolean;
28
+ };
27
29
  }): Promise<void>;
28
30
  updateAggregateReservation(params: {
29
31
  id: string;
@@ -32,4 +34,5 @@ export declare class MongoRepository {
32
34
  deleteById(params: {
33
35
  id: string;
34
36
  }): Promise<void>;
37
+ getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
35
38
  }
@@ -61,14 +61,6 @@ class MongoRepository {
61
61
  return doc.toObject();
62
62
  });
63
63
  }
64
- count(params) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
67
- return this.projectModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
68
- .setOptions({ maxTimeMS: 10000 })
69
- .exec();
70
- });
71
- }
72
64
  /**
73
65
  * プロジェクト検索
74
66
  */
@@ -98,12 +90,14 @@ class MongoRepository {
98
90
  });
99
91
  }
100
92
  findByIdAndIUpdate(params) {
101
- var _a;
93
+ var _a, _b;
102
94
  return __awaiter(this, void 0, void 0, function* () {
103
- yield this.projectModel.findOneAndUpdate({ _id: params.id }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date() }, (typeof params.alternateName === 'string' && params.alternateName.length > 0)
95
+ yield this.projectModel.findOneAndUpdate({ _id: params.id }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ updatedAt: new Date() }, (typeof params.alternateName === 'string' && params.alternateName.length > 0)
104
96
  ? { alternateName: params.alternateName }
105
97
  : undefined), (typeof params.name === 'string' && params.name.length > 0) ? { name: params.name } : undefined), (typeof params.logo === 'string' && params.logo.length > 0) ? { logo: params.logo } : undefined), (typeof ((_a = params.settings) === null || _a === void 0 ? void 0 : _a.sendgridApiKey) === 'string')
106
98
  ? { 'settings.sendgridApiKey': params.settings.sendgridApiKey }
99
+ : undefined), (typeof ((_b = params.subscription) === null || _b === void 0 ? void 0 : _b.useEventServiceAsProduct) === 'boolean')
100
+ ? { 'subscription.useEventServiceAsProduct': params.subscription.useEventServiceAsProduct }
107
101
  : undefined), {
108
102
  // ↓customerUserPoolは廃止
109
103
  $unset: {
@@ -131,5 +125,10 @@ class MongoRepository {
131
125
  .exec();
132
126
  });
133
127
  }
128
+ getCursor(conditions, projection) {
129
+ return this.projectModel.find(conditions, projection)
130
+ .sort({ _id: factory.sortType.Ascending })
131
+ .cursor();
132
+ }
134
133
  }
135
134
  exports.MongoRepository = MongoRepository;
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.26"
123
+ "version": "20.2.0-alpha.27"
124
124
  }
@@ -1,77 +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, { autoIndex: false });
13
-
14
- const productRepo = new chevre.repository.Product(mongoose.connection);
15
-
16
- const cursor = productRepo.getCursor(
17
- {
18
- // 'project.id': { $eq: project.id },
19
- 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
- typeOf: { $eq: chevre.factory.service.paymentService.PaymentServiceType.CreditCard }
21
- },
22
- {
23
- // _id: 1,
24
- }
25
- );
26
- console.log('products found');
27
-
28
- let i = 0;
29
- let updateCount = 0;
30
- // tslint:disable-next-line:max-func-body-length
31
- await cursor.eachAsync(async (doc) => {
32
- i += 1;
33
- const paymentService: chevre.factory.service.paymentService.IService = doc.toObject();
34
-
35
- const hasPaymentUrlExpiresInseconds = paymentService.provider?.some((provider) => {
36
- return typeof (<any>provider).credentials?.paymentUrlExpiresInSeconds === 'number';
37
- });
38
-
39
- if (!hasPaymentUrlExpiresInseconds) {
40
- console.log(
41
- 'no expiresInSeconds', paymentService.project.id, paymentService.id, paymentService.productID, i);
42
-
43
- return;
44
- }
45
-
46
- const alreadyMigrated = paymentService.provider?.filter((provider) => {
47
- return typeof (<any>provider).credentials?.paymentUrlExpiresInSeconds === 'number';
48
- })
49
- .every((provider) => {
50
- return typeof provider.credentials?.paymentUrl?.expiresInSeconds === 'number';
51
- });
52
-
53
- if (alreadyMigrated) {
54
- console.log(
55
- 'already exist...', paymentService.project.id, paymentService.id, paymentService.productID, i);
56
- } else {
57
- console.log(
58
- 'updating product...', paymentService.project.id, paymentService.id, paymentService.productID, i);
59
- // await eventRepo.updatePartiallyById({
60
- // id: event.id,
61
- // attributes: <any>{
62
- // typeOf: event.typeOf,
63
- // 'offers.itemOffered.availableChannel': newAvailableChannel
64
- // }
65
- // });
66
- updateCount += 1;
67
- console.log(
68
- 'updated...', paymentService.project.id, paymentService.id, paymentService.productID, i);
69
- }
70
- });
71
- console.log(i, 'products checked');
72
- console.log(updateCount, 'products updated');
73
- }
74
-
75
- main()
76
- .then()
77
- .catch(console.error);