@chevre/domain 23.2.0-alpha.2 → 23.2.0-alpha.20

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.
Files changed (67) hide show
  1. package/example/src/chevre/actions/checkAuthorizePaymentActions.ts +55 -0
  2. package/example/src/chevre/event/importEventsFromCOAByTitle.ts +1 -1
  3. package/example/src/chevre/eventSeries/migrateEventSeriesOffers.ts +75 -0
  4. package/example/src/chevre/eventSeries/migrateEventSeriesVideoFormat.ts +80 -0
  5. package/example/src/chevre/place/adminEntranceGates.ts +68 -0
  6. package/example/src/chevre/place/checkEntranceGatesCount.ts +82 -0
  7. package/example/src/chevre/place/findRooms.ts +24 -0
  8. package/example/src/chevre/place/findSections.ts +28 -0
  9. package/example/src/chevre/place/migrateSectionIdentifier.ts +92 -0
  10. package/example/src/chevre/place/seatsJson2csv.ts +63 -0
  11. package/example/src/chevre/place/upsertSeatsByBranchCode.ts +72 -0
  12. package/example/src/chevre/reIndex.ts +1 -1
  13. package/example/src/chevre/roles/addAdminEventSeriesReadPermissionIfNotExists.ts +49 -0
  14. package/example/src/chevre/roles/addAdminMovieReadPermissionIfNotExists.ts +49 -0
  15. package/example/src/chevre/roles/addAdminMovieTheaterReadPermissionIfNotExists.ts +34 -0
  16. package/example/src/chevre/roles/addAdminMovieTheaterWritePermissionIfNotExists.ts +34 -0
  17. package/example/src/chevre/roles/addAdminRoomReadPermissionIfNotExists.ts +34 -0
  18. package/example/src/chevre/roles/addAdminRoomWritePermissionIfNotExists.ts +34 -0
  19. package/lib/chevre/repo/acceptedPaymentMethod.js +14 -10
  20. package/lib/chevre/repo/aggregateOrder.js +0 -93
  21. package/lib/chevre/repo/aggregateReservation.d.ts +0 -1
  22. package/lib/chevre/repo/aggregateReservation.js +0 -2
  23. package/lib/chevre/repo/creativeWork.js +9 -5
  24. package/lib/chevre/repo/eventSeries.js +16 -12
  25. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +0 -1
  26. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +10 -9
  27. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +10 -0
  28. package/lib/chevre/repo/place/entranceGate.d.ts +58 -0
  29. package/lib/chevre/repo/place/entranceGate.js +159 -0
  30. package/lib/chevre/repo/place/movieTheater.d.ts +5 -2
  31. package/lib/chevre/repo/place/movieTheater.js +3 -1
  32. package/lib/chevre/repo/place/screeningRoom.d.ts +38 -31
  33. package/lib/chevre/repo/place/screeningRoom.js +166 -135
  34. package/lib/chevre/repo/place/seat.d.ts +47 -45
  35. package/lib/chevre/repo/place/seat.js +175 -45
  36. package/lib/chevre/repo/place/section.d.ts +36 -30
  37. package/lib/chevre/repo/place/section.js +214 -130
  38. package/lib/chevre/repository.d.ts +8 -0
  39. package/lib/chevre/repository.js +16 -0
  40. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.d.ts +6 -1
  41. package/lib/chevre/service/assetTransaction/pay/validateAcceptedPaymentMethodIfNeeded.js +26 -4
  42. package/lib/chevre/service/assetTransaction/pay.d.ts +3 -0
  43. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +1 -1
  44. package/lib/chevre/service/event/processUpdateMovieTheater.js +1 -1
  45. package/lib/chevre/service/event/saveScreeningEvents.d.ts +1 -1
  46. package/lib/chevre/service/event/saveScreeningEvents.js +1 -1
  47. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +7 -4
  48. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.js +9 -6
  49. package/lib/chevre/service/offer/event/searchOffersByIds.js +7 -4
  50. package/lib/chevre/service/offer/onEventChanged.js +7 -5
  51. package/lib/chevre/service/payment/any/factory.d.ts +5 -0
  52. package/lib/chevre/service/payment/any/factory.js +11 -2
  53. package/lib/chevre/service/payment/any.d.ts +8 -0
  54. package/lib/chevre/service/payment/any.js +3 -2
  55. package/lib/chevre/service/task/authorizePayment.js +3 -1
  56. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.d.ts +1 -1
  57. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +2 -2
  58. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.js +1 -1
  59. package/lib/chevre/service/task/onResourceUpdated.js +2 -2
  60. package/lib/chevre/service/task/publishPaymentUrl.js +3 -1
  61. package/lib/chevre/service/task/syncResourcesFromCOA.js +1 -1
  62. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +2 -2
  63. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +3 -1
  64. package/lib/chevre/service/transaction/placeOrder/confirm.js +3 -1
  65. package/package.json +3 -2
  66. package/lib/chevre/service/eventOld.d.ts +0 -60
  67. package/lib/chevre/service/eventOld.js +0 -864
@@ -0,0 +1,55 @@
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 actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
12
+
13
+ const cursor = actionRepo.getCursor(
14
+ {
15
+ typeOf: { $eq: chevre.factory.actionType.AuthorizeAction },
16
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment },
17
+ startDate: {
18
+ $gte: moment()
19
+ // tslint:disable-next-line:no-magic-numbers
20
+ .add(-7, 'days')
21
+ .toDate()
22
+ }
23
+ },
24
+ {
25
+ }
26
+ );
27
+ console.log('docs found');
28
+
29
+ let i = 0;
30
+ let expectdCount = 0;
31
+ await cursor.eachAsync(async (doc) => {
32
+ i += 1;
33
+ const authorizeAction = <chevre.factory.action.authorize.paymentMethod.any.IAction>doc.toObject();
34
+
35
+ const isExpected = authorizeAction.object.paymentMethodId === authorizeAction.instrument.transactionNumber;
36
+ if (isExpected) {
37
+ console.log(
38
+ authorizeAction.object.paymentMethodId,
39
+ ' expected.',
40
+ authorizeAction.project.id, authorizeAction.typeOf, authorizeAction.object.typeOf,
41
+ authorizeAction.startDate, authorizeAction.identifier, i
42
+ );
43
+ expectdCount += 1;
44
+ } else {
45
+ throw new Error(`not expected ${authorizeAction.object.paymentMethodId} ${authorizeAction.instrument.transactionNumber} ${authorizeAction.project.id}`);
46
+ }
47
+ });
48
+
49
+ console.log(i, 'docs checked');
50
+ console.log(expectdCount, 'expectd');
51
+ }
52
+
53
+ main()
54
+ .then()
55
+ .catch(console.error);
@@ -67,7 +67,7 @@ async function main() {
67
67
  }
68
68
  console.log('movieTheater:', movieTheater);
69
69
 
70
- const screeningRooms = await roomRepo.searchScreeningRooms({
70
+ const screeningRooms = await roomRepo.findRooms({
71
71
  project: { id: { $eq: project.id } },
72
72
  containedInPlace: { branchCode: { $eq: movieTheater.branchCode } },
73
73
  branchCode: { $eq: roomCode }
@@ -0,0 +1,75 @@
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 eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
12
+
13
+ const cursor = eventSeriesRepo.getCursor(
14
+ {
15
+ // _id: { $eq: 'bmd7x21f2' },
16
+ // 'project.id': { $eq: 'xxx' },
17
+ 'offers.typeOf': {
18
+ $exists: true,
19
+ $eq: chevre.factory.offerType.AggregateOffer
20
+ }
21
+ },
22
+ {
23
+ // _id: 1,
24
+ // offers: 1,
25
+ // startDate: 1,
26
+ // project: 1,
27
+ // typeOf: 1
28
+ }
29
+ );
30
+ console.log('docs found');
31
+
32
+ let i = 0;
33
+ let updateCount = 0;
34
+ await cursor.eachAsync(async (doc) => {
35
+ i += 1;
36
+ const eventSeries: Pick<
37
+ chevre.factory.eventSeries.IEvent,
38
+ 'id' | 'offers' | 'startDate' | 'project' | 'typeOf'
39
+ > = doc.toObject();
40
+
41
+ console.log(
42
+ 'alreadyMigrated?', eventSeries.project.id, eventSeries.typeOf, eventSeries.id, eventSeries.startDate, i);
43
+ const alreadyMigrated = eventSeries.offers?.typeOf === chevre.factory.offerType.Offer;
44
+
45
+ if (alreadyMigrated) {
46
+ console.log(
47
+ 'already migrated.', eventSeries.project.id, eventSeries.typeOf, eventSeries.id, eventSeries.startDate, i);
48
+ } else {
49
+ console.log(
50
+ 'updating...',
51
+ eventSeries.project.id, eventSeries.typeOf, eventSeries.id, eventSeries.startDate, i);
52
+ await eventSeriesRepo.saveEventSeries({
53
+ id: eventSeries.id,
54
+ attributes: <any>{
55
+ ...{
56
+ typeOf: eventSeries.typeOf,
57
+ 'offers.typeOf': chevre.factory.offerType.Offer
58
+ }
59
+ }
60
+ });
61
+ updateCount += 1;
62
+ console.log(
63
+ 'updated.',
64
+ eventSeries.project.id, eventSeries.typeOf, eventSeries.id, eventSeries.startDate, i);
65
+
66
+ }
67
+ });
68
+
69
+ console.log(i, 'docs checked');
70
+ console.log(updateCount, 'docs updated');
71
+ }
72
+
73
+ main()
74
+ .then()
75
+ .catch(console.error);
@@ -0,0 +1,80 @@
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 eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
12
+
13
+ const cursor = eventSeriesRepo.getCursor(
14
+ {
15
+ // _id: { $eq: 'al9s38bj6' },
16
+ 'project.id': { $nin: ['sskts-development', 'sskts-test', 'sskts-production'] }
17
+ },
18
+ {
19
+ // _id: 1,
20
+ // offers: 1,
21
+ // startDate: 1,
22
+ // project: 1,
23
+ // typeOf: 1
24
+ }
25
+ );
26
+ console.log('docs found');
27
+
28
+ let i = 0;
29
+ let updateCount = 0;
30
+ await cursor.eachAsync(async (doc) => {
31
+ i += 1;
32
+ const eventSeries: Pick<
33
+ chevre.factory.eventSeries.IEvent,
34
+ 'id' | 'videoFormat' | 'subEvent' | 'project' | 'startDate' | 'typeOf'
35
+ > = doc.toObject();
36
+
37
+ const videoFormatByOldAttribute: string[] =
38
+ (Array.isArray(eventSeries.videoFormat)) ? eventSeries.videoFormat.map(({ typeOf }) => typeOf) : [];
39
+ const videoFormatByNewAttribute: string[] =
40
+ (Array.isArray(eventSeries.subEvent?.videoFormat)) ? eventSeries.subEvent.videoFormat : [];
41
+ const alreadyMigrated = videoFormatByOldAttribute.length === videoFormatByNewAttribute.length
42
+ && videoFormatByOldAttribute.every((codeValue) => videoFormatByNewAttribute.includes(codeValue))
43
+ && eventSeries.subEvent?.typeOf === chevre.factory.eventType.ScreeningEvent;
44
+
45
+ if (alreadyMigrated) {
46
+ console.log(
47
+ 'already migrated.', eventSeries.project.id, eventSeries.id, eventSeries.startDate, i);
48
+ } else {
49
+ const subEvent: chevre.factory.eventSeries.ISubEvent = {
50
+ typeOf: chevre.factory.eventType.ScreeningEvent,
51
+ ...(videoFormatByOldAttribute.length > 0) ? { videoFormat: videoFormatByOldAttribute } : undefined
52
+ };
53
+ console.log(
54
+ 'updating...',
55
+ eventSeries.project.id, eventSeries.id, eventSeries.startDate, i, videoFormatByOldAttribute, subEvent
56
+ );
57
+ await eventSeriesRepo.saveEventSeries({
58
+ id: eventSeries.id,
59
+ attributes: <any>{
60
+ ...{
61
+ typeOf: eventSeries.typeOf,
62
+ subEvent
63
+ }
64
+ }
65
+ });
66
+ updateCount += 1;
67
+ console.log(
68
+ 'updated.',
69
+ eventSeries.project.id, eventSeries.id, eventSeries.startDate, i);
70
+
71
+ }
72
+ });
73
+
74
+ console.log(i, 'docs checked');
75
+ console.log(updateCount, 'docs updated');
76
+ }
77
+
78
+ main()
79
+ .then()
80
+ .catch(console.error);
@@ -0,0 +1,68 @@
1
+ // tslint:disable:no-console
2
+ // import * as redis from 'redis';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../../lib/index';
6
+
7
+ const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const entranceGateRepo =
13
+ await chevre.repository.place.EntranceGate.createInstance(mongoose.connection, { id: '5bfb841d5a78d7948369979a' });
14
+
15
+ const gates = await entranceGateRepo.findEntranceGates({
16
+ limit: 10,
17
+ page: 1,
18
+ project: { id: { $eq: project.id } }
19
+ });
20
+ console.log(gates);
21
+ console.log(gates.length);
22
+
23
+ let result = await entranceGateRepo.addEntranceGatesByIdentifierIfNotExist(
24
+ [
25
+ {
26
+ $set: {
27
+ identifier: 'sample001',
28
+ name: { ja: 'gateNameJa' }
29
+ }
30
+ }
31
+ ],
32
+ {
33
+ project: { id: project.id }
34
+ }
35
+ );
36
+ console.log(result);
37
+
38
+ result = await entranceGateRepo.updateEntranceGatesByIdentifier(
39
+ [
40
+ {
41
+ $set: {
42
+ identifier: 'sample001',
43
+ name: { ja: 'gateNameJaUpdated' }
44
+ }
45
+ }
46
+ ],
47
+ {
48
+ project: { id: project.id }
49
+ }
50
+ );
51
+ console.log(result);
52
+
53
+ result = await entranceGateRepo.deleteEntranceGatesByIdentifier(
54
+ [
55
+ {
56
+ identifier: 'sample001'
57
+ }
58
+ ],
59
+ {
60
+ project: { id: project.id }
61
+ }
62
+ );
63
+ console.log(result);
64
+ }
65
+
66
+ main()
67
+ .then(console.log)
68
+ .catch(console.error);
@@ -0,0 +1,82 @@
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
+ // const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const movieTheaterRepo = await chevre.repository.place.MovieTheater.createInstance(mongoose.connection);
14
+
15
+ const cursor = movieTheaterRepo.getCursor(
16
+ {
17
+ // 'project.id': {
18
+ // $ne: 'sskts-development',
19
+ // $eq: 'ttts-development'
20
+ // }
21
+ // _id: { $eq: '67de46777ec0510590b68922' }
22
+ },
23
+ {
24
+ // _id: 1,
25
+ // about: 1,
26
+ // project: 1,
27
+ // typeOf: 1,
28
+ // issuedBy: 1
29
+ }
30
+ );
31
+ console.log('docs found');
32
+
33
+ let i = 0;
34
+ let updateCount = 0;
35
+ await cursor.eachAsync(async (doc) => {
36
+ const movieTheater: chevre.factory.place.movieTheater.IPlace = doc.toObject();
37
+
38
+ i += 1;
39
+ const { hasEntranceGate } = movieTheater;
40
+ if (!Array.isArray(hasEntranceGate)) {
41
+ throw new Error('hasEntranceGateLength must be an array');
42
+ }
43
+ const hasEntranceGateLength = hasEntranceGate?.length;
44
+ if (typeof hasEntranceGateLength !== 'number') {
45
+ throw new Error('hasEntranceGateLength undefined');
46
+ }
47
+ const uniqueIdentifiersByMovieTheater = hasEntranceGate.map(({ identifier }) => identifier);
48
+
49
+ const entranceGateRepo = await chevre.repository.place.EntranceGate.createInstance(mongoose.connection, { id: movieTheater.id });
50
+ const entranceGates = await entranceGateRepo.findEntranceGates({
51
+ limit: 100,
52
+ page: 1,
53
+ project: { id: { $eq: movieTheater.project.id } }
54
+ });
55
+ const entranceGateCount = entranceGates.length;
56
+ const uniqueIdentifiers = entranceGates.map(({ identifier }) => identifier);
57
+
58
+ const countMatched = hasEntranceGateLength === entranceGateCount;
59
+ const identifiersMatched = uniqueIdentifiersByMovieTheater.length === uniqueIdentifiers.length
60
+ && uniqueIdentifiersByMovieTheater.every((identifier) => uniqueIdentifiers.includes(identifier));
61
+ console.log(uniqueIdentifiersByMovieTheater, uniqueIdentifiers);
62
+
63
+ console.log(
64
+ 'checking...', movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
65
+ if (countMatched && identifiersMatched) {
66
+ console.log(
67
+ 'matched.', movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
68
+ } else {
69
+ updateCount += 1;
70
+ console.log(
71
+ 'unmatched.',
72
+ movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
73
+ }
74
+ });
75
+
76
+ console.log(i, 'docs checked');
77
+ console.log(updateCount, 'docs updated');
78
+ }
79
+
80
+ main()
81
+ .then()
82
+ .catch(console.error);
@@ -0,0 +1,24 @@
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, { autoIndex: false });
10
+
11
+ const roomRepo = await chevre.repository.place.ScreeningRoom.createInstance(mongoose.connection);
12
+
13
+ const rooms = await roomRepo.findRooms({
14
+ limit: 20,
15
+ page: 1,
16
+ project: { id: { $eq: project.id } }
17
+ });
18
+ console.log(rooms);
19
+ console.log(rooms.length);
20
+ }
21
+
22
+ main()
23
+ .then(console.log)
24
+ .catch(console.error);
@@ -0,0 +1,28 @@
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, { autoIndex: false });
10
+
11
+ const sectionRepo = await chevre.repository.place.Section.createInstance(mongoose.connection);
12
+
13
+ const sections = await sectionRepo.findSections({
14
+ limit: 10,
15
+ page: 1,
16
+ project: { id: { $eq: project.id } },
17
+ containedInPlace: {
18
+ branchCode: { $eq: '10' },
19
+ containedInPlace: { id: { $eq: '5bfb841d5a78d7948369979a' } }
20
+ }
21
+ });
22
+ console.log(sections);
23
+ console.log(sections.length);
24
+ }
25
+
26
+ main()
27
+ .then(console.log)
28
+ .catch(console.error);
@@ -0,0 +1,92 @@
1
+ // tslint:disable:no-console
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 excludedProject = { id: String(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 roomRepo = await chevre.repository.place.ScreeningRoom.createInstance(mongoose.connection);
15
+ const sectionRepo = await chevre.repository.place.Section.createInstance(mongoose.connection);
16
+
17
+ const cursor = roomRepo.getCursor(
18
+ {
19
+ 'project.id': {
20
+ $ne: 'sskts-development',
21
+ $eq: 'ttts-development'
22
+ }
23
+ // _id: { $eq: '67de46777ec0510590b68922' }
24
+ },
25
+ {
26
+ // _id: 1,
27
+ // about: 1,
28
+ // project: 1,
29
+ // typeOf: 1,
30
+ // issuedBy: 1
31
+ }
32
+ );
33
+ console.log('docs found');
34
+
35
+ const timestamp = moment()
36
+ .tz('Asia/Tokyo')
37
+ .format('YYYYMMDDHHmmss');
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ const room: chevre.factory.place.screeningRoom.IPlace = doc.toObject();
43
+
44
+ const sections = room.containsPlace;
45
+ if (Array.isArray(sections)) {
46
+ for (const section of sections) {
47
+ i += 1;
48
+ const movieTheaterCode = room.containedInPlace?.branchCode;
49
+ if (typeof movieTheaterCode !== 'string') {
50
+ throw new Error('movieTheaterCode undefined');
51
+ }
52
+ const alreadyMigrated = typeof (<any>section).identifier === 'string';
53
+
54
+ if (alreadyMigrated) {
55
+ console.log(
56
+ 'already migrated.', room.project.id, movieTheaterCode, room.branchCode, section.branchCode, i);
57
+ } else {
58
+ // if (typeof identity.id !== 'string') {
59
+ // throw new Error(`id undefined ${identity.id}`);
60
+ // }
61
+ const identifier = `${movieTheaterCode}:${room.branchCode}:${section.branchCode}:${timestamp}`;
62
+
63
+ console.log(
64
+ 'updating...',
65
+ identifier,
66
+ room.project.id, movieTheaterCode, room.branchCode, section.branchCode, i);
67
+ await sectionRepo.migrateSectionIdentifier({
68
+ project: { id: room.project.id },
69
+ identifier,
70
+ branchCode: section.branchCode,
71
+ containedInPlace: {
72
+ branchCode: room.branchCode,
73
+ containedInPlace: {
74
+ branchCode: movieTheaterCode
75
+ }
76
+ }
77
+ });
78
+ updateCount += 1;
79
+ console.log(
80
+ 'updated.', room.project.id, movieTheaterCode, room.branchCode, section.branchCode, i);
81
+ }
82
+ }
83
+ }
84
+ });
85
+
86
+ console.log(i, 'docs checked');
87
+ console.log(updateCount, 'docs updated');
88
+ }
89
+
90
+ main()
91
+ .then()
92
+ .catch(console.error);
@@ -0,0 +1,63 @@
1
+ // tslint:disable:no-console
2
+ // tslint:disable-next-line:no-implicit-dependencies
3
+ import { Parser } from '@json2csv/plainjs';
4
+ import * as mongoose from 'mongoose';
5
+ import { chevre } from '../../../../lib/index';
6
+
7
+ const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
13
+
14
+ const seats = await seatRepo.searchSeats(
15
+ {
16
+ project: { id: { $eq: project.id } },
17
+ containedInPlace: {
18
+ // branchCode: { $eq: 'Default02' },
19
+ branchCode: { $eq: 'Default' },
20
+ containedInPlace: {
21
+ branchCode: { $eq: '10' },
22
+ containedInPlace: { branchCode: { $eq: '118' } }
23
+ }
24
+ }
25
+ }
26
+ );
27
+ console.log(seats);
28
+ console.log(seats.length, 'seats found');
29
+ try {
30
+ const opts = {
31
+ // formatters: {
32
+ // // Define how strings are formatted
33
+ // string: (value) => {
34
+ // // if (value.includes(',') || value.includes('"') || value.includes('\n')) {
35
+ // // return `"${value.replace(/"/g, '""')}"`; // Standard CSV escaping
36
+ // // }
37
+ // // if (value === '') {
38
+ // // return `""`; // Standard CSV escaping
39
+ // // }
40
+
41
+ // return value; // No quotes if safe
42
+ // }
43
+ // }
44
+ };
45
+ const parser = new Parser(opts);
46
+ const csv = parser.parse(seats.map((seat) => {
47
+ // branchCode,seatingType,name.ja,name.en
48
+ return {
49
+ branchCode: seat.branchCode,
50
+ ...(Array.isArray(seat.seatingType) && seat.seatingType.length > 0) ? { seatingType: seat.seatingType[0] } : undefined,
51
+ 'name.ja': (typeof seat.name?.ja === 'string') ? seat.name.ja : '',
52
+ 'name.en': (typeof seat.name?.en === 'string') ? seat.name.en : ''
53
+ };
54
+ }));
55
+ console.log(csv);
56
+ } catch (err) {
57
+ console.error(err);
58
+ }
59
+ }
60
+
61
+ main()
62
+ .then(console.log)
63
+ .catch(console.error);
@@ -0,0 +1,72 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+ import { chevre } from '../../../../lib/index';
4
+
5
+ const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
6
+
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
11
+
12
+ let result = await seatRepo.addSeatsByBranchCodeIfNotExist(
13
+ [
14
+ {
15
+ $set: {
16
+ branchCode: 'SAMPLE',
17
+ name: { ja: 'from samples', en: 'from samples' },
18
+ additionalProperty: []
19
+ }
20
+ },
21
+ {
22
+ $set: {
23
+ branchCode: 'SAMPLE2',
24
+ name: { ja: 'from samples2', en: 'from samples' },
25
+ additionalProperty: []
26
+ }
27
+ }
28
+ ],
29
+ {
30
+ project: { id: project.id },
31
+ movieTheaterCode: '118',
32
+ roomCode: '10',
33
+ sectionCode: 'Default02'
34
+ }
35
+ );
36
+ console.log(result);
37
+
38
+ result = await seatRepo.updateSeatsByBranchCode(
39
+ [
40
+ {
41
+ $set: {
42
+ branchCode: 'SAMPLE',
43
+ name: { ja: 'from samples', en: 'from samples' },
44
+ additionalProperty: [],
45
+ maximumAttendeeCapacity: 0
46
+ }
47
+ },
48
+ {
49
+ $set: {
50
+ branchCode: 'SAMPLE2',
51
+ name: { ja: 'from samples2', en: 'from samples' },
52
+ additionalProperty: []
53
+ // maximumAttendeeCapacity: 0
54
+ },
55
+ $unset: {
56
+ maximumAttendeeCapacity: 1
57
+ }
58
+ }
59
+ ],
60
+ {
61
+ project: { id: project.id },
62
+ movieTheaterCode: '118',
63
+ roomCode: '10',
64
+ sectionCode: 'Default02'
65
+ }
66
+ );
67
+ console.log(result);
68
+ }
69
+
70
+ main()
71
+ .then(console.log)
72
+ .catch(console.error);
@@ -11,7 +11,7 @@ mongoose.Model.on('index', (...args) => {
11
11
  async function main() {
12
12
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
13
 
14
- await chevre.repository.EventOffer.createInstance(mongoose.connection);
14
+ await chevre.repository.EventSeries.createInstance(mongoose.connection);
15
15
  console.log('success!');
16
16
  }
17
17