@chevre/domain 20.1.0-alpha.37 → 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.
@@ -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
  }
@@ -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;
@@ -33,8 +33,9 @@ function confirmReservation(actionAttributesList) {
33
33
  // ...actionAttributes.object,
34
34
  id: reservation.id,
35
35
  previousReservationStatus: reservation.reservationStatus,
36
- underName: reservation.underName,
37
- reservedTicket: reservation.reservedTicket
36
+ underName: reservation.underName
37
+ // issuedThroughは予約取引開始時に確定しているので更新不要(2022-12-21~)
38
+ // reservedTicket: reservation.reservedTicket
38
39
  });
39
40
  // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
40
41
  // delete (<any>reservation)._id;
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.1.0-alpha.37"
123
+ "version": "20.1.0-alpha.38"
124
124
  }
@@ -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);