@chevre/domain 21.30.0-alpha.9 → 21.30.0

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 (96) hide show
  1. package/example/src/chevre/checkActions.ts +65 -0
  2. package/example/src/chevre/checkReplaceActions.ts +65 -0
  3. package/example/src/chevre/checkSendEmailMessages4order.ts +73 -0
  4. package/example/src/chevre/deleteStartDatePassedCertainPeriod.ts +27 -0
  5. package/example/src/chevre/findReservationByCode.ts +3 -1
  6. package/example/src/chevre/findValidAuthorization.ts +45 -0
  7. package/example/src/chevre/importEventsFromCOA.ts +2 -2
  8. package/example/src/chevre/migrateMembers.ts +94 -0
  9. package/example/src/chevre/optimizeActions.ts +16 -22
  10. package/example/src/chevre/playAroundMessage.ts +73 -0
  11. package/example/src/chevre/playAroundNote.ts +19 -68
  12. package/example/src/chevre/playAroundTicket.ts +40 -0
  13. package/example/src/chevre/transaction/processPlaceOrder.ts +2 -0
  14. package/example/src/chevre/unsetUnnecessaryFields.ts +25 -7
  15. package/example/src/moment.ts +21 -0
  16. package/lib/chevre/credentials.d.ts +6 -1
  17. package/lib/chevre/credentials.js +12 -1
  18. package/lib/chevre/emailMessageBuilder.d.ts +13 -6
  19. package/lib/chevre/emailMessageBuilder.js +6 -10
  20. package/lib/chevre/repo/code.d.ts +25 -13
  21. package/lib/chevre/repo/code.js +48 -28
  22. package/lib/chevre/repo/customer.d.ts +7 -6
  23. package/lib/chevre/repo/customer.js +31 -36
  24. package/lib/chevre/repo/member.d.ts +4 -0
  25. package/lib/chevre/repo/member.js +7 -1
  26. package/lib/chevre/repo/message.d.ts +90 -0
  27. package/lib/chevre/repo/message.js +183 -0
  28. package/lib/chevre/repo/mongoose/schemas/authorization.js +6 -13
  29. package/lib/chevre/repo/mongoose/schemas/member.js +5 -12
  30. package/lib/chevre/repo/mongoose/schemas/message.d.ts +5 -0
  31. package/lib/chevre/repo/mongoose/schemas/message.js +124 -0
  32. package/lib/chevre/repo/mongoose/schemas/note.js +15 -10
  33. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +5 -12
  34. package/lib/chevre/repo/mongoose/schemas/role.d.ts +1 -1
  35. package/lib/chevre/repo/mongoose/schemas/role.js +23 -29
  36. package/lib/chevre/repo/mongoose/schemas/ticket.d.ts +5 -0
  37. package/lib/chevre/repo/mongoose/schemas/ticket.js +70 -0
  38. package/lib/chevre/repo/note.d.ts +4 -0
  39. package/lib/chevre/repo/note.js +6 -0
  40. package/lib/chevre/repo/ownershipInfo.d.ts +4 -0
  41. package/lib/chevre/repo/ownershipInfo.js +6 -0
  42. package/lib/chevre/repo/role.js +1 -5
  43. package/lib/chevre/repo/task.d.ts +16 -2
  44. package/lib/chevre/repo/task.js +17 -6
  45. package/lib/chevre/repo/ticket.d.ts +58 -0
  46. package/lib/chevre/repo/ticket.js +83 -0
  47. package/lib/chevre/repository.d.ts +13 -3
  48. package/lib/chevre/repository.js +29 -3
  49. package/lib/chevre/service/code.d.ts +34 -6
  50. package/lib/chevre/service/code.js +98 -12
  51. package/lib/chevre/service/event.d.ts +6 -8
  52. package/lib/chevre/service/event.js +137 -112
  53. package/lib/chevre/service/notification.d.ts +2 -0
  54. package/lib/chevre/service/notification.js +11 -1
  55. package/lib/chevre/service/offer/event/authorize.d.ts +4 -0
  56. package/lib/chevre/service/offer/event/processStartReserve4chevre.d.ts +4 -0
  57. package/lib/chevre/service/offer/event/processStartReserve4chevre.js +4 -1
  58. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +1 -1
  59. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +4 -1
  60. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +1 -0
  61. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +26 -5
  62. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -1
  63. package/lib/chevre/service/order/sendOrder.js +3 -1
  64. package/lib/chevre/service/payment/any.d.ts +4 -0
  65. package/lib/chevre/service/payment/any.js +4 -1
  66. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.js +1 -1
  67. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  68. package/lib/chevre/service/payment/movieTicket/factory.js +2 -2
  69. package/lib/chevre/service/payment/movieTicket.js +138 -53
  70. package/lib/chevre/service/reserve/findByCode.d.ts +1 -1
  71. package/lib/chevre/service/reserve/findByCode.js +4 -4
  72. package/lib/chevre/service/reserve/useReservation.js +14 -30
  73. package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +3 -1
  74. package/lib/chevre/service/reserve/verifyToken4reservation.js +3 -2
  75. package/lib/chevre/service/task/authorizePayment.js +4 -0
  76. package/lib/chevre/service/task/deleteTransaction.js +2 -0
  77. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -5
  78. package/lib/chevre/service/task/returnPayTransaction.js +4 -2
  79. package/lib/chevre/service/task/sendEmailMessage.js +2 -0
  80. package/lib/chevre/service/task.d.ts +1 -7
  81. package/lib/chevre/service/task.js +1 -10
  82. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  83. package/lib/chevre/service/transaction/deleteTransaction.js +29 -4
  84. package/lib/chevre/service/transaction/moneyTransfer.d.ts +6 -0
  85. package/lib/chevre/service/transaction/moneyTransfer.js +4 -1
  86. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.d.ts +6 -2
  87. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +29 -4
  88. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.d.ts +5 -1
  89. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.js +32 -30
  90. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +5 -1
  91. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +9 -6
  92. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.d.ts +10 -2
  93. package/lib/chevre/service/transaction/placeOrderInProgress/publishCode.js +4 -1
  94. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +2 -27
  95. package/package.json +4 -4
  96. package/example/src/chevre/migrateActionInstrumentTransactionNumber.ts +0 -93
@@ -0,0 +1,65 @@
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 CONSOLE_CLIENT_ID = 'xxx';
8
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+ type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>;
10
+
11
+ // tslint:disable-next-line:max-func-body-length
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
16
+
17
+ const cursor = actionRepo.getCursor(
18
+ {
19
+ typeOf: { $eq: chevre.factory.actionType.CreateAction },
20
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.eventType.ScreeningEvent },
21
+ startDate: {
22
+ $gte: moment()
23
+ // tslint:disable-next-line:no-magic-numbers
24
+ .add(-60, 'days')
25
+ .toDate()
26
+ }
27
+ },
28
+ {
29
+ }
30
+ );
31
+ console.log('actions found');
32
+
33
+ let i = 0;
34
+ await cursor.eachAsync(async (doc) => {
35
+ i += 1;
36
+ const action = <IAction>doc.toObject();
37
+ // const size = JSON.stringify(action).length;
38
+ // // console.log(JSON.stringify(action).length);
39
+ // if (action.typeOf !== chevre.factory.actionType.InformAction
40
+ // && action.typeOf !== chevre.factory.actionType.AuthorizeAction
41
+ // && action.typeOf !== chevre.factory.actionType.CheckAction
42
+ // && size > 2000) {
43
+ // console.log(action.typeOf, action.object?.typeOf);
44
+ // console.log(size);
45
+ // }
46
+
47
+ const eventCount = (Array.isArray(action.result))
48
+ ? action.result.filter(({ typeOf }) => typeOf === chevre.factory.eventType.ScreeningEvent)
49
+ .length
50
+ : 0;
51
+ if (action.instrument?.id !== CONSOLE_CLIENT_ID) {
52
+ console.log(eventCount, 'events created', action.project.id, action.startDate, action.instrument?.id, i);
53
+ // tslint:disable-next-line:no-magic-numbers
54
+ if (eventCount > 10) {
55
+ throw new Error('eventCount too large');
56
+ }
57
+ }
58
+ });
59
+
60
+ console.log(i, 'actions checked');
61
+ }
62
+
63
+ main()
64
+ .then()
65
+ .catch(console.error);
@@ -0,0 +1,65 @@
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 CONSOLE_CLIENT_ID = 'xxx';
8
+ // const project = { id: String(process.env.PROJECT_ID) };
9
+ type IAction = chevre.factory.action.IAction<chevre.factory.action.IAttributes<chevre.factory.actionType, any, any>>;
10
+
11
+ // tslint:disable-next-line:max-func-body-length
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
16
+
17
+ const cursor = actionRepo.getCursor(
18
+ {
19
+ typeOf: { $eq: chevre.factory.actionType.ReplaceAction },
20
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.eventType.ScreeningEventSeries },
21
+ startDate: {
22
+ $gte: moment()
23
+ // tslint:disable-next-line:no-magic-numbers
24
+ .add(-60, 'days')
25
+ .toDate()
26
+ }
27
+ },
28
+ {
29
+ }
30
+ );
31
+ console.log('actions found');
32
+
33
+ let i = 0;
34
+ await cursor.eachAsync(async (doc) => {
35
+ i += 1;
36
+ const action = <IAction>doc.toObject();
37
+ // const size = JSON.stringify(action).length;
38
+ // // console.log(JSON.stringify(action).length);
39
+ // if (action.typeOf !== chevre.factory.actionType.InformAction
40
+ // && action.typeOf !== chevre.factory.actionType.AuthorizeAction
41
+ // && action.typeOf !== chevre.factory.actionType.CheckAction
42
+ // && size > 2000) {
43
+ // console.log(action.typeOf, action.object?.typeOf);
44
+ // console.log(size);
45
+ // }
46
+
47
+ const eventCount = (Array.isArray(action.object))
48
+ ? action.object.filter(({ typeOf }) => typeOf === chevre.factory.eventType.ScreeningEventSeries)
49
+ .length
50
+ : 0;
51
+ if (action.instrument?.id !== CONSOLE_CLIENT_ID) {
52
+ console.log(eventCount, 'events created', action.project.id, action.startDate, action.instrument?.id, i);
53
+ // tslint:disable-next-line:no-magic-numbers
54
+ if (eventCount > 20) {
55
+ throw new Error('eventCount too large');
56
+ }
57
+ }
58
+ });
59
+
60
+ console.log(i, 'actions checked');
61
+ }
62
+
63
+ main()
64
+ .then()
65
+ .catch(console.error);
@@ -0,0 +1,73 @@
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
+
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 actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
+ // const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
15
+ const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
16
+
17
+ const cursor = transactionRepo.getCursor(
18
+ {
19
+ startDate: {
20
+ $gte: moment()
21
+ // tslint:disable-next-line:no-magic-numbers
22
+ .add(-30, 'days')
23
+ .toDate()
24
+ },
25
+ typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
26
+ status: { $eq: chevre.factory.transactionStatusType.Confirmed }
27
+ // orderStatus: { $nin: [chevre.factory.orderStatus.OrderReturned] }
28
+ },
29
+ {
30
+ // orderNumber: 1,
31
+ // orderDate: 1,
32
+ // project: 1
33
+ }
34
+ );
35
+ console.log('transactions found');
36
+
37
+ let i = 0;
38
+ await cursor.eachAsync(async (doc) => {
39
+ i += 1;
40
+ const transaction = <Pick<
41
+ chevre.factory.transaction.placeOrder.ITransaction,
42
+ 'object' | 'result' | 'potentialActions' | 'project' | 'startDate'
43
+ >>doc.toObject();
44
+
45
+ // console.log('searching actions...', order, order.project, order.orderNumber, order.orderDate, i);
46
+ // const actions = await actionRepo.search(
47
+ // {
48
+ // typeOf: { $eq: chevre.factory.actionType.SendAction },
49
+ // purpose: { orderNumber: { $in: [order.orderNumber] } }
50
+ // },
51
+ // ['_id', 'object'],
52
+ // []);
53
+ // const onOrderSentMessageCount: number = actions.filter(
54
+ // ({ object }) => object.about.identifier === chevre.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent
55
+ // ).length;
56
+ let onOrderSentMessageCount: number | undefined =
57
+ transaction.potentialActions?.order.potentialActions?.sendOrder?.potentialActions?.sendEmailMessage?.length;
58
+ if (onOrderSentMessageCount === undefined) {
59
+ onOrderSentMessageCount = 0;
60
+ }
61
+ console.log(
62
+ onOrderSentMessageCount, 'messages found', transaction.project, transaction.object.orderNumber, transaction.startDate, i);
63
+ if (onOrderSentMessageCount > 1) {
64
+ throw new Error(transaction.object.orderNumber);
65
+ }
66
+ });
67
+
68
+ console.log(i, 'orders checked');
69
+ }
70
+
71
+ main()
72
+ .then()
73
+ .catch(console.error);
@@ -0,0 +1,27 @@
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
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
11
+
12
+ const lt: Date = moment()
13
+ // tslint:disable-next-line:no-magic-numbers
14
+ .add(-16, 'months')
15
+ .toDate();
16
+ let result: any;
17
+ result = await actionRepo.deleteStartDatePassedCertainPeriod({
18
+ $lt: lt
19
+ });
20
+ console.log('result:', result, lt);
21
+ }
22
+
23
+ main()
24
+ .then(() => {
25
+ console.log('success!');
26
+ })
27
+ .catch(console.error);
@@ -19,6 +19,7 @@ async function main() {
19
19
  const authorizationRepo = await chevre.repository.Code.createInstance(mongoose.connection);
20
20
  const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
21
21
  const reservationRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
22
+ const ticketRepo = await chevre.repository.Ticket.createInstance(mongoose.connection);
22
23
 
23
24
  await (await chevre.service.reserve.createService()).verifyToken4reservation({
24
25
  project: { id: project.id },
@@ -29,7 +30,8 @@ async function main() {
29
30
  }
30
31
  })({
31
32
  authorization: authorizationRepo,
32
- order: orderRepo
33
+ order: orderRepo,
34
+ ticket: ticketRepo
33
35
  });
34
36
  console.log('verified.');
35
37
 
@@ -0,0 +1,45 @@
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 CODE = '85de7dc1-3761-4317-80d6-b36bf0b2788f';
8
+ // const ID = '6631d754c20be0772c217b90';
9
+
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const authorizationRepo = await chevre.repository.Code.createInstance(mongoose.connection);
14
+ const ticketRepo = await chevre.repository.Ticket.createInstance(mongoose.connection);
15
+
16
+ const result = await authorizationRepo.findValidOneByCode({
17
+ project,
18
+ code: CODE
19
+ });
20
+ console.log('result:', result);
21
+
22
+ // const result = await authorizationRepo.findValidOneById({
23
+ // project,
24
+ // id: ID
25
+ // });
26
+ // console.log('result:', result);
27
+
28
+ const token = await (await chevre.service.code.createService()).getToken({
29
+ agent: { id: 'xxx', typeOf: chevre.factory.personType.Person },
30
+ project,
31
+ code: CODE,
32
+ expiresIn: 18000,
33
+ issuer: 'https://example.com',
34
+ audience: 'https://example.com',
35
+ useJti: true
36
+ })({
37
+ authorization: authorizationRepo,
38
+ ticket: ticketRepo
39
+ });
40
+ console.log('token:', token);
41
+ }
42
+
43
+ main()
44
+ .then(console.log)
45
+ .catch(console.error);
@@ -30,8 +30,8 @@ async function main() {
30
30
  .add(1, 'day')
31
31
  .toDate(),
32
32
  saveMovieTheater: false,
33
- saveScreeningEventSeries: true,
34
- saveScreeningEventSeriesPeriodInMonth: 24
33
+ saveScreeningEventSeries: false,
34
+ saveScreeningEventSeriesPeriodInMonth: 3
35
35
  })({
36
36
  action: actionRepo,
37
37
  categoryCode: categoryCodeRepo,
@@ -0,0 +1,94 @@
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
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
13
+
14
+ const cursor = memberRepo.getCursor(
15
+ {
16
+ 'member.memberOf.typeOf': { $eq: chevre.factory.organizationType.Corporation }
17
+ },
18
+ {
19
+ }
20
+ );
21
+ console.log('members found');
22
+
23
+ let projectIds: string[] = [];
24
+ let i = 0;
25
+ let updateCount = 0;
26
+ await cursor.eachAsync(async (doc) => {
27
+ i += 1;
28
+ const iamMember: chevre.factory.iam.IMember = doc.toObject();
29
+
30
+ const alreadyMigrated = false;
31
+ projectIds.push(iamMember.project.id);
32
+
33
+ if (alreadyMigrated) {
34
+ console.log(
35
+ 'already exist.',
36
+ iamMember.project.id,
37
+ iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
38
+ );
39
+ } else {
40
+ console.log(
41
+ 'updating...',
42
+ iamMember.project.id,
43
+ iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
44
+ );
45
+ updateCount += 1;
46
+ console.log(
47
+ 'updated.',
48
+ iamMember.project.id,
49
+ iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
50
+ );
51
+ }
52
+ });
53
+
54
+ projectIds = [...new Set(projectIds)];
55
+ console.log(projectIds);
56
+ console.log(i, 'members checked');
57
+ console.log(updateCount, 'members updated');
58
+
59
+ // 販売者メンバーの存在するプロジェクトについて、inventoryManagerにiam.roleAdminを追加
60
+ const NEW_ROLE_NAME = 'iam.roleAdmin';
61
+ for (const projectId of projectIds) {
62
+ const inventoryManagers = await memberRepo.search({
63
+ project: { id: { $eq: projectId } },
64
+ member: {
65
+ hasRole: { roleName: { $eq: 'inventoryManager' } },
66
+ memberOf: { typeOf: { $eq: chevre.factory.organizationType.Project } }
67
+ }
68
+ });
69
+ console.log(inventoryManagers.length, 'inventoryManagers found', projectId);
70
+ for (const inventoryManager of inventoryManagers) {
71
+ const alreadyRoleAdmin = inventoryManager.member.hasRole.some(({ roleName }) => roleName === NEW_ROLE_NAME);
72
+ if (!alreadyRoleAdmin) {
73
+ const newHasRole: chevre.factory.iam.IMemberRole[] = [
74
+ { typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName: NEW_ROLE_NAME },
75
+ ...inventoryManager.member.hasRole
76
+ ];
77
+ console.log('adding newRole', projectId, inventoryManager.member.id, newHasRole);
78
+ await memberRepo.updateByMemberId({
79
+ project: { id: inventoryManager.project.id },
80
+ member: {
81
+ id: inventoryManager.member.id,
82
+ memberOf: inventoryManager.member.memberOf,
83
+ hasRole: newHasRole
84
+ },
85
+ $unset: {}
86
+ });
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ main()
93
+ .then()
94
+ .catch(console.error);
@@ -13,13 +13,14 @@ async function main() {
13
13
  const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
14
 
15
15
  // tslint:disable-next-line:no-increment-decrement no-magic-numbers
16
- for (let index = 0; index < 24 * 548; index++) {
16
+ for (let index = 0; index < 24 * 1000; index++) {
17
17
  const updateResult = await actionRepo.unsetUnnecessaryFields({
18
18
  filter: {
19
- typeOf: { $eq: chevre.factory.actionType.OrderAction },
20
- 'object.typeOf': { $exists: true, $eq: chevre.factory.order.OrderType.Order },
21
- // 'purpose.typeOf': { $exists: true, $eq: chevre.factory.order.OrderType.Order },
19
+ typeOf: { $eq: chevre.factory.actionType.UseAction },
20
+ 'object.typeOf': { $exists: true, $eq: chevre.factory.reservationType.EventReservation },
21
+ // actionStatus: { $eq: chevre.factory.actionStatusType.CompletedActionStatus },
22
22
  startDate: {
23
+ // $exists: true,
23
24
  $gte: moment()
24
25
  .add(-(index + 1), 'hours')
25
26
  .toDate(),
@@ -30,24 +31,17 @@ async function main() {
30
31
  // _id: { $eq: '61da235d94a80f000af85f6b' }
31
32
  },
32
33
  $unset: {
33
- // 'purpose.project': 1,
34
- // 'purpose.seller': 1,
35
- // 'purpose.customer': 1
36
- 'object.project': 1,
37
- 'object.seller': 1,
38
- 'object.customer': 1,
39
- 'object.paymentMethods': 1,
40
- 'object.discounts': 1,
41
- 'object.acceptedOffers': 1,
42
- 'object.url': 1,
43
- 'object.orderStatus': 1,
44
- 'object.identifier': 1,
45
- 'object.isGift': 1,
46
- 'object.broker': 1,
47
- 'object.dateReturned': 1,
48
- 'object.name': 1,
49
- 'object.orderedItem': 1,
50
- 'object.returner': 1
34
+ 'object.0.issuedThrough.availableChannel': 1,
35
+ 'object.0.issuedThrough.serviceType': 1,
36
+ 'object.0.reservationFor.superEvent': 1,
37
+ 'object.0.reservationFor.location': 1,
38
+ 'object.0.reservationFor.name': 1,
39
+ 'object.0.reservedTicket.issuedBy': 1,
40
+ 'object.0.reservedTicket.ticketType.description': 1,
41
+ 'object.0.reservedTicket.ticketType.name': 1,
42
+ 'object.0.reservedTicket.ticketType.additionalProperty': 1,
43
+ 'object.0.reservedTicket.ticketType.category': 1,
44
+ 'object.0.reservedTicket.ticketType.color': 1
51
45
  }
52
46
  });
53
47
  console.log(
@@ -0,0 +1,73 @@
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
+ mongoose.Model.on('index', (...args) => {
9
+ console.error('******** index event emitted. ********\n', args);
10
+ });
11
+
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
14
+
15
+ const messageRepo = await chevre.repository.Message.createInstance(mongoose.connection);
16
+ // const createResult = await messageRepo.upsertByIdentifier(
17
+ // [
18
+ // {
19
+ // project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
20
+ // identifier: 'SendOrder-TTT5-8982603-9533198',
21
+ // name: 'SendOrder-TTT5-8982603-9533198',
22
+ // sender: {
23
+ // typeOf: 'Corporation',
24
+ // name: 'sample sender name',
25
+ // email: 'text@example.com'
26
+ // },
27
+ // toRecipient: [
28
+ // {
29
+ // typeOf: 'WebApplication',
30
+ // name: 'sample toRecipient',
31
+ // email: 'text@example.com'
32
+ // }
33
+ // ],
34
+ // about: {
35
+ // typeOf: 'Thing',
36
+ // identifier: chevre.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent,
37
+ // name: 'sample about name'
38
+ // },
39
+ // text: 'sample text',
40
+ // mainEntity: {
41
+ // typeOf: chevre.factory.order.OrderType.Order,
42
+ // orderNumber: 'TTT5-8982603-9533198'
43
+ // },
44
+ // provider: { id: '5a392dfdfca1c8737fb6da42', typeOf: chevre.factory.organizationType.Corporation }
45
+ // }
46
+ // ]
47
+ // );
48
+ // console.log('createResult:', createResult);
49
+
50
+ const messages = await messageRepo.search(
51
+ {
52
+ limit: 1,
53
+ page: 1,
54
+ project: {
55
+ id: { $eq: project.id }
56
+ },
57
+ identifier: { $eq: 'SendOrder-TTT5-8982603-9533198' },
58
+ mainEntity: {
59
+ orderNumber: { $eq: 'TTT5-8982603-9533198' }
60
+ },
61
+ about: { identifier: { $eq: chevre.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } },
62
+ provider: { id: { $eq: '5a392dfdfca1c8737fb6da42' } }
63
+ },
64
+ ['identifier', 'mainEntity', 'about', 'provider'],
65
+ []
66
+ );
67
+ console.log('messages:', messages);
68
+ console.log(messages.length, 'messages found');
69
+ }
70
+
71
+ main()
72
+ .then(console.log)
73
+ .catch(console.error);
@@ -3,79 +3,30 @@ import * as mongoose from 'mongoose';
3
3
 
4
4
  import { chevre } from '../../../lib/index';
5
5
 
6
- // const project = { id: String(process.env.PROJECT_ID) };
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ mongoose.Model.on('index', (...args) => {
9
+ console.error('******** index event emitted. ********\n', args);
10
+ });
7
11
 
8
12
  async function main() {
9
13
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
14
 
11
15
  const noteRepo = await chevre.repository.Note.createInstance(mongoose.connection);
12
- const result = await noteRepo.search({
13
- limit: 1,
14
- page: 1,
15
- inclusion: ['text', 'about', 'identifier'],
16
- exclusion: []
17
- });
18
- console.log('result:', result);
19
-
20
- // let createResult = await noteRepo.upsertByIdentifier(
21
- // [{
22
- // about: {
23
- // id: '65c41ca61898c4feba427e4f',
24
- // orderNumber: 'CIN2-8393218-6955938',
25
- // typeOf: chevre.factory.order.OrderType.Order
26
- // },
27
- // creator: {
28
- // id: '582ee997-86ac-43e4-90c2-213a10c3282f',
29
- // typeOf: chevre.factory.personType.Person
30
- // },
31
- // identifier: '20240213OrderNote',
32
- // project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
33
- // text: 'note text',
34
- // version: '1'
35
- // }],
36
- // { overwrite: false }
37
- // );
38
- // console.log('createResult:', createResult);
39
-
40
- // createResult = await noteRepo.upsertByIdentifier(
41
- // [{
42
- // about: {
43
- // id: '65c41ca61898c4feba427e4f',
44
- // orderNumber: 'CIN2-8393218-6955938',
45
- // typeOf: chevre.factory.order.OrderType.Order
46
- // },
47
- // creator: {
48
- // id: '582ee997-86ac-43e4-90c2-213a10c3282f',
49
- // typeOf: chevre.factory.personType.Person
50
- // },
51
- // identifier: '20240213OrderNote',
52
- // project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
53
- // text: 'note text updated',
54
- // version: '1'
55
- // }],
56
- // { overwrite: false }
57
- // );
58
- // console.log('createResult:', createResult);
59
-
60
- // createResult = await noteRepo.upsertByIdentifier(
61
- // [{
62
- // about: {
63
- // id: '65c41ca61898c4feba427e4f',
64
- // orderNumber: 'CIN2-8393218-6955938',
65
- // typeOf: chevre.factory.order.OrderType.Order
66
- // },
67
- // creator: {
68
- // id: '582ee997-86ac-43e4-90c2-213a10c3282f',
69
- // typeOf: chevre.factory.personType.Person
70
- // },
71
- // identifier: '20240213OrderNote',
72
- // project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
73
- // text: '',
74
- // version: '1'
75
- // }],
76
- // { overwrite: false }
77
- // );
78
- // console.log('createResult:', createResult);
16
+ const notes = await noteRepo.search(
17
+ {
18
+ limit: 1,
19
+ page: 1,
20
+ project: {
21
+ id: { $eq: project.id }
22
+ },
23
+ about: { id: { $eq: '' } },
24
+ inclusion: [],
25
+ exclusion: []
26
+ }
27
+ );
28
+ console.log('notes:', notes);
29
+ console.log(notes.length, 'notes found');
79
30
  }
80
31
 
81
32
  main()
@@ -0,0 +1,40 @@
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 TICKET_TOKEN = 'xxx';
8
+
9
+ mongoose.Model.on('index', (...args) => {
10
+ console.error('******** index event emitted. ********\n', args);
11
+ });
12
+
13
+ async function main() {
14
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
15
+
16
+ const ticketRepo = await chevre.repository.Ticket.createInstance(mongoose.connection);
17
+ const tickets = await ticketRepo.search(
18
+ {
19
+ limit: 1,
20
+ page: 1,
21
+ sort: { dateIssued: chevre.factory.sortType.Descending },
22
+ project: {
23
+ id: { $eq: project.id }
24
+ },
25
+ ticketToken: { $eq: TICKET_TOKEN }
26
+ }
27
+ );
28
+ console.log('tickets:', tickets);
29
+ console.log(tickets.length, 'tickets found');
30
+
31
+ // const issueResult = await ticketRepo.issueByTicketToken({
32
+ // ticketToken: TICKET_TOKEN,
33
+ // project: { id: project.id }
34
+ // });
35
+ // console.log('issueResult:', issueResult);
36
+ }
37
+
38
+ main()
39
+ .then(console.log)
40
+ .catch(console.error);