@chevre/domain 22.13.0-alpha.5 → 22.13.0-alpha.6

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.
@@ -13,7 +13,7 @@ async function main() {
13
13
 
14
14
  const cursor = eventRepo.getCursor(
15
15
  {
16
- _id: { $eq: 'blwz44aee' },
16
+ // _id: { $eq: 'blwz44d0k' },
17
17
  'project.id': { $eq: project.id }
18
18
  },
19
19
  {
@@ -61,16 +61,16 @@ async function main() {
61
61
  console.log(
62
62
  'updating... oldEventId:',
63
63
  oldEventId, event.project.id, event.id, event.startDate, i);
64
- // await eventRepo.updatePartiallyById({
65
- // project: { id: event.project.id },
66
- // id: event.id,
67
- // attributes: {
68
- // typeOf: event.typeOf,
69
- // ...{
70
- // identifier: oldEventId
71
- // }
72
- // }
73
- // });
64
+ await eventRepo.updatePartiallyById({
65
+ project: { id: event.project.id },
66
+ id: event.id,
67
+ attributes: {
68
+ typeOf: event.typeOf,
69
+ ...{
70
+ identifier: oldEventId
71
+ }
72
+ }
73
+ });
74
74
  updateCount += 1;
75
75
  console.log(
76
76
  'updated.',
@@ -0,0 +1,192 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as moment from 'moment-timezone';
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 ADDITIONAL_PROPERTY_NAME = 'sampleCreateId';
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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
15
+
16
+ const today = moment()
17
+ .tz('Asia/Tokyo')
18
+ .format('YYYY-MM-DD');
19
+ const identifier = `fromSamples:${moment()
20
+ .format('YYYY-MM-DD HH:mm')}`;
21
+ const settingEvent: chevre.factory.event.screeningEvent.IEvent = {
22
+ identifier,
23
+ additionalProperty: [
24
+ { name: ADDITIONAL_PROPERTY_NAME, value: identifier }
25
+ ],
26
+ id: 'bmcvkft5g',
27
+ project: {
28
+ id: project.id,
29
+ typeOf: chevre.factory.organizationType.Project
30
+ },
31
+ organizer: {
32
+ id: '59d20831e53ebc2b4e774466'
33
+ },
34
+ typeOf: chevre.factory.eventType.ScreeningEvent,
35
+ name: {
36
+ en: 'pet IMAX2D',
37
+ ja: 'ペット IMAX2D'
38
+ },
39
+ doorTime: moment(`${today}T13:00:00Z`)
40
+ .toDate(),
41
+ startDate: moment(`${today}T13:00:00Z`)
42
+ .toDate(),
43
+ endDate: moment(`${today}T14:00:00Z`)
44
+ .toDate(),
45
+ eventStatus: chevre.factory.eventStatusType.EventScheduled,
46
+ location: {
47
+ typeOf: chevre.factory.placeType.ScreeningRoom,
48
+ branchCode: '70',
49
+ name: {
50
+ ja: 'シネマ7',
51
+ en: 'CINEMA7'
52
+ },
53
+ address: {
54
+ ja: '',
55
+ en: ''
56
+ }
57
+ },
58
+ superEvent: {
59
+ typeOf: chevre.factory.eventType.ScreeningEventSeries,
60
+ id: 'al9s38bj6',
61
+ videoFormat: [
62
+ {
63
+ typeOf: '2D',
64
+ name: '2D'
65
+ },
66
+ {
67
+ typeOf: 'IMAX',
68
+ name: 'IMAX'
69
+ }
70
+ ],
71
+ soundFormat: [],
72
+ workPerformed: {
73
+ typeOf: chevre.factory.creativeWorkType.Movie,
74
+ identifier: '1622100',
75
+ id: '5bfb841d5a78d7948369980a',
76
+ name: {
77
+ en: 'Pet',
78
+ ja: 'ペット'
79
+ },
80
+ duration: 'PT2H3M'
81
+ },
82
+ location: {
83
+ typeOf: chevre.factory.placeType.MovieTheater,
84
+ id: '5bfb841d5a78d7948369979a',
85
+ branchCode: '118',
86
+ name: {
87
+ ja: 'シネモーション赤坂 ',
88
+ en: 'CineMotion Akasaka'
89
+ }
90
+ },
91
+ kanaName: 'ペット IMAX2D',
92
+ name: {
93
+ en: 'pet IMAX2D',
94
+ ja: 'ペット IMAX2D'
95
+ },
96
+ additionalProperty: [],
97
+ startDate: moment('2022-09-30T15:00:00.000Z')
98
+ .toDate(),
99
+ endDate: moment('2029-07-31T15:00:00.000Z')
100
+ .toDate(),
101
+ headline: {
102
+ ja: 'IMAX2D上映'
103
+ }
104
+ },
105
+ offers: {
106
+ typeOf: chevre.factory.offerType.Offer,
107
+ eligibleQuantity: {
108
+ typeOf: 'QuantitativeValue',
109
+ unitCode: chevre.factory.unitCode.C62,
110
+ maxValue: 6
111
+ },
112
+ itemOffered: {
113
+ id: '655dc6b02cbb99d946cb6081',
114
+ name: {
115
+ ja: '通常興行カタログ(サブカタログ版)'
116
+ },
117
+ serviceOutput: {
118
+ typeOf: chevre.factory.reservationType.EventReservation,
119
+ reservedTicket: {
120
+ typeOf: 'Ticket',
121
+ ticketedSeat: {
122
+ typeOf: chevre.factory.placeType.Seat
123
+ }
124
+ }
125
+ },
126
+ typeOf: chevre.factory.product.ProductType.EventService,
127
+ availableChannel: {
128
+ typeOf: 'ServiceChannel',
129
+ serviceLocation: {
130
+ typeOf: chevre.factory.placeType.ScreeningRoom,
131
+ branchCode: '70',
132
+ name: {
133
+ ja: 'シネマ7',
134
+ en: 'CINEMA7'
135
+ },
136
+ containedInPlace: {
137
+ typeOf: chevre.factory.placeType.MovieTheater,
138
+ id: '5bfb841d5a78d7948369979a',
139
+ branchCode: '118',
140
+ name: {
141
+ ja: 'シネモーション赤坂 ',
142
+ en: 'CineMotion Akasaka'
143
+ }
144
+ }
145
+ }
146
+ }
147
+ },
148
+ seller: {
149
+ typeOf: chevre.factory.organizationType.Corporation,
150
+ id: '59d20831e53ebc2b4e774466',
151
+ name: {
152
+ ja: 'シネモーション赤坂',
153
+ en: 'CineMotion Akasaka'
154
+ },
155
+ makesOffer: [
156
+ ]
157
+ }
158
+ }
159
+ };
160
+
161
+ const createResult = await eventRepo.upsertManyScreeningEventByIdentifier(
162
+ [
163
+ {
164
+ $set: settingEvent,
165
+ $unset: {}
166
+ }
167
+ ],
168
+ { update: false }
169
+ );
170
+ // tslint:disable-next-line:no-null-keyword
171
+ console.dir(createResult, { depth: null });
172
+
173
+ const updateResult = await eventRepo.upsertManyScreeningEventByIdentifier(
174
+ [
175
+ {
176
+ $set: {
177
+ ...settingEvent,
178
+ eventStatus: chevre.factory.eventStatusType.EventCancelled
179
+ },
180
+ $unset: {}
181
+ }
182
+ ],
183
+ { update: true }
184
+ );
185
+ // tslint:disable-next-line:no-null-keyword
186
+ console.dir(updateResult, { depth: null });
187
+
188
+ }
189
+
190
+ main()
191
+ .then()
192
+ .catch(console.error);
@@ -105,6 +105,24 @@ export declare class EventRepo {
105
105
  id: string;
106
106
  }[];
107
107
  } | void>;
108
+ /**
109
+ * イベントコードをキーにして冪等置換
110
+ */
111
+ upsertManyScreeningEventByIdentifier(params: {
112
+ $set: factory.event.screeningEvent.IEvent;
113
+ $unset: IUnset<factory.eventType.ScreeningEvent>;
114
+ }[], options: {
115
+ /**
116
+ * falseの場合setOnInsertのみ
117
+ * trueの場合setのみ
118
+ */
119
+ update: boolean;
120
+ }): Promise<{
121
+ bulkWriteResult: BulkWriteResult;
122
+ modifiedEvents: {
123
+ id: string;
124
+ }[];
125
+ } | void>;
108
126
  /**
109
127
  * イベント部分更新
110
128
  */
@@ -482,6 +482,71 @@ class EventRepo {
482
482
  }
483
483
  });
484
484
  }
485
+ /**
486
+ * イベントコードをキーにして冪等置換
487
+ */
488
+ upsertManyScreeningEventByIdentifier(params, options) {
489
+ return __awaiter(this, void 0, void 0, function* () {
490
+ const { update } = options;
491
+ const uniqid = yield Promise.resolve().then(() => require('uniqid'));
492
+ const bulkWriteOps = [];
493
+ const queryFilters = [];
494
+ if (Array.isArray(params)) {
495
+ params.forEach(({ $set, $unset }) => {
496
+ const { project, identifier } = $set;
497
+ if (typeof identifier !== 'string' || identifier.length === 0) {
498
+ throw new factory.errors.ArgumentNull('identifier');
499
+ }
500
+ // リソースのユニークネスを保証するfilter
501
+ const filter = {
502
+ 'project.id': { $eq: project.id },
503
+ identifier: { $exists: true, $eq: identifier }
504
+ };
505
+ queryFilters.push({
506
+ 'project.id': { $eq: project.id },
507
+ identifier: { $exists: true, $eq: identifier }
508
+ });
509
+ if (update === true) {
510
+ const { maximumPhysicalAttendeeCapacity, additionalProperty, eventStatus, location, name, superEvent, offers, doorTime, endDate, startDate } = $set;
511
+ const setFields = {
512
+ maximumPhysicalAttendeeCapacity, additionalProperty,
513
+ eventStatus, location, name, superEvent, offers,
514
+ doorTime, endDate, startDate
515
+ };
516
+ const updateOne = {
517
+ filter,
518
+ update: Object.assign({ $set: setFields }, ($unset !== undefined) ? { $unset } : undefined),
519
+ upsert: false
520
+ };
521
+ bulkWriteOps.push({ updateOne });
522
+ }
523
+ else {
524
+ const { id, coaInfo, description, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, aggregateReservation } = $set, setOnInsertFields = __rest($set, ["id", "coaInfo", "description", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "aggregateReservation"]);
525
+ const setOnInsert = Object.assign(Object.assign({}, setOnInsertFields), { identifier, _id: uniqid() });
526
+ const updateOne = {
527
+ filter,
528
+ update: {
529
+ $setOnInsert: setOnInsert
530
+ },
531
+ upsert: true
532
+ };
533
+ bulkWriteOps.push({ updateOne });
534
+ }
535
+ });
536
+ }
537
+ if (bulkWriteOps.length > 0) {
538
+ const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
539
+ // modifiedの場合upsertedIdsに含まれないので、idを検索する
540
+ const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, {
541
+ _id: 0,
542
+ id: { $toString: '$_id' }
543
+ })
544
+ .lean()
545
+ .exec();
546
+ return { bulkWriteResult, modifiedEvents };
547
+ }
548
+ });
549
+ }
485
550
  /**
486
551
  * イベント部分更新
487
552
  */
@@ -595,7 +660,7 @@ class EventRepo {
595
660
  saveEventByIdentifier4ttts(params) {
596
661
  return __awaiter(this, void 0, void 0, function* () {
597
662
  const { oldEventId } = params;
598
- const _a = params.attributes, { project, typeOf } = _a, updateFields = __rest(_a, ["project", "typeOf"]);
663
+ const _a = params.attributes, { project, typeOf, eventStatus } = _a, updateFields = __rest(_a, ["project", "typeOf", "eventStatus"]);
599
664
  const identifier = oldEventId;
600
665
  const uniqid = yield Promise.resolve().then(() => require('uniqid'));
601
666
  const id = uniqid();
@@ -614,6 +679,7 @@ class EventRepo {
614
679
  _id: id,
615
680
  typeOf,
616
681
  project,
682
+ eventStatus,
617
683
  identifier // イベントコードを必ず追加(2025-09-03~)
618
684
  // ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
619
685
  },
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": "22.13.0-alpha.5"
118
+ "version": "22.13.0-alpha.6"
119
119
  }
@@ -1,22 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- const project = { id: String(process.env.PROJECT_ID) };
7
-
8
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
-
11
- const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
12
-
13
- const result = await eventRepo.cancelEvent({
14
- project: { id: project.id },
15
- id: '7iri6w0m1h1hu5y'
16
- });
17
- console.log(result);
18
- }
19
-
20
- main()
21
- .then()
22
- .catch(console.error);