@chevre/domain 21.30.0-alpha.21 → 21.30.0-alpha.23

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.
@@ -36,12 +36,32 @@ async function main() {
36
36
  mainEntity: {
37
37
  typeOf: chevre.factory.order.OrderType.Order,
38
38
  orderNumber: 'TTT5-8982603-9533198'
39
- }
39
+ },
40
+ provider: { id: '5a392dfdfca1c8737fb6da42', typeOf: chevre.factory.organizationType.Corporation }
40
41
  }
41
42
  ]
42
43
  );
43
44
  console.log('createResult:', createResult);
44
45
 
46
+ const messages = await messageRepo.search(
47
+ {
48
+ limit: 1,
49
+ page: 1,
50
+ project: {
51
+ id: { $eq: project.id }
52
+ },
53
+ identifier: { $eq: 'SendOrder-TTT5-8982603-9533198' },
54
+ mainEntity: {
55
+ orderNumber: { $eq: 'TTT5-8982603-9533198' }
56
+ },
57
+ about: { identifier: { $eq: chevre.factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } },
58
+ provider: { id: { $eq: '5a392dfdfca1c8737fb6da42' } }
59
+ },
60
+ ['identifier', 'mainEntity', 'about', 'provider'],
61
+ []
62
+ );
63
+ console.log('messages:', messages);
64
+ console.log(messages.length, 'messages found');
45
65
  }
46
66
 
47
67
  main()
@@ -8,18 +8,63 @@ type IEmailMessage = factory.creativeWork.message.email.ICreativeWork & {
8
8
  id: string;
9
9
  typeOf: factory.organizationType.Project;
10
10
  };
11
+ provider: {
12
+ /**
13
+ * 販売者ID
14
+ */
15
+ id: string;
16
+ typeOf: factory.organizationType.Corporation;
17
+ };
11
18
  };
12
19
  type IFindByIdentifierResult = Pick<IEmailMessage, 'about' | 'identifier' | 'name' | 'sender' | 'text' | 'toRecipient' | 'typeOf'>;
20
+ interface ISearchConditions {
21
+ limit?: number;
22
+ page?: number;
23
+ sort?: {
24
+ datePublished?: factory.sortType;
25
+ };
26
+ project?: {
27
+ id?: {
28
+ $eq?: string;
29
+ };
30
+ };
31
+ provider?: {
32
+ id?: {
33
+ $eq?: string;
34
+ };
35
+ };
36
+ mainEntity?: {
37
+ orderNumber?: {
38
+ $eq?: string;
39
+ };
40
+ };
41
+ identifier?: {
42
+ $eq?: string;
43
+ };
44
+ about?: {
45
+ identifier?: {
46
+ $eq?: string;
47
+ };
48
+ };
49
+ }
50
+ type IKeyOfProjection = keyof IEmailMessage | '_id';
13
51
  /**
14
52
  * メッセージリポジトリ
15
53
  */
16
54
  export declare class MessageRepo {
17
55
  private readonly messageModel;
18
56
  constructor(connection: Connection);
57
+ static CREATE_MONGO_CONDITIONS(params: ISearchConditions): any[];
58
+ /**
59
+ * 検索
60
+ */
61
+ search(params: ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<(IEmailMessage & {
62
+ id: string;
63
+ })[]>;
19
64
  /**
20
65
  * コードをキーにしてなければ作成する(複数対応)
21
66
  */
22
- upsertByIdentifier(params: Pick<IEmailMessage, 'about' | 'identifier' | 'mainEntity' | 'name' | 'project' | 'sender' | 'text' | 'toRecipient'>[]): Promise<BulkWriteResult | void>;
67
+ upsertByIdentifier(params: Pick<IEmailMessage, 'about' | 'identifier' | 'mainEntity' | 'name' | 'project' | 'sender' | 'text' | 'toRecipient' | 'provider'>[]): Promise<BulkWriteResult | void>;
23
68
  /**
24
69
  * コードで参照
25
70
  */
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MessageRepo = void 0;
13
13
  const message_1 = require("./mongoose/schemas/message");
14
14
  const factory = require("../factory");
15
+ const settings_1 = require("../settings");
15
16
  /**
16
17
  * メッセージリポジトリ
17
18
  */
@@ -19,6 +20,71 @@ class MessageRepo {
19
20
  constructor(connection) {
20
21
  this.messageModel = connection.model(message_1.modelName, (0, message_1.createSchema)());
21
22
  }
23
+ static CREATE_MONGO_CONDITIONS(params) {
24
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
25
+ const andConditions = [];
26
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
27
+ if (typeof projectIdEq === 'string') {
28
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
29
+ }
30
+ const providerIdEq = (_d = (_c = params.provider) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
31
+ if (typeof providerIdEq === 'string') {
32
+ andConditions.push({ 'provider.id': { $eq: providerIdEq } });
33
+ }
34
+ const mainEntityOrderNumberEq = (_f = (_e = params.mainEntity) === null || _e === void 0 ? void 0 : _e.orderNumber) === null || _f === void 0 ? void 0 : _f.$eq;
35
+ if (typeof mainEntityOrderNumberEq === 'string') {
36
+ andConditions.push({ 'mainEntity.orderNumber': { $exists: true, $eq: mainEntityOrderNumberEq } });
37
+ }
38
+ const identifierEq = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$eq;
39
+ if (typeof identifierEq === 'string') {
40
+ andConditions.push({ identifier: { $eq: identifierEq } });
41
+ }
42
+ const aboutIdentifierEq = (_j = (_h = params.about) === null || _h === void 0 ? void 0 : _h.identifier) === null || _j === void 0 ? void 0 : _j.$eq;
43
+ if (typeof aboutIdentifierEq === 'string') {
44
+ andConditions.push({ 'about.identifier': { $eq: aboutIdentifierEq } });
45
+ }
46
+ return andConditions;
47
+ }
48
+ /**
49
+ * 検索
50
+ */
51
+ search(params, inclusion, exclusion) {
52
+ var _a;
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ let projection = {};
55
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
56
+ inclusion.forEach((field) => {
57
+ projection[field] = 1;
58
+ });
59
+ }
60
+ else {
61
+ projection = {
62
+ __v: 0,
63
+ createdAt: 0,
64
+ updatedAt: 0
65
+ };
66
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
67
+ exclusion.forEach((field) => {
68
+ projection[field] = 0;
69
+ });
70
+ }
71
+ }
72
+ const conditions = MessageRepo.CREATE_MONGO_CONDITIONS(params);
73
+ const query = this.messageModel.find((conditions.length > 0) ? { $and: conditions } : {})
74
+ .select(projection);
75
+ if (typeof params.limit === 'number' && params.limit > 0) {
76
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
77
+ query.limit(params.limit)
78
+ .skip(params.limit * (page - 1));
79
+ }
80
+ if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.datePublished) === 'number') {
81
+ query.sort({ datePublished: params.sort.datePublished });
82
+ }
83
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
84
+ .exec()
85
+ .then((docs) => docs.map((doc) => doc.toObject()));
86
+ });
87
+ }
22
88
  /**
23
89
  * コードをキーにしてなければ作成する(複数対応)
24
90
  */
@@ -28,7 +94,7 @@ class MessageRepo {
28
94
  const bulkWriteOps = [];
29
95
  if (Array.isArray(params)) {
30
96
  params.forEach((creatingNoteParams) => {
31
- const { about, identifier, project, text, mainEntity, name, sender, toRecipient } = creatingNoteParams;
97
+ const { about, identifier, project, text, mainEntity, name, sender, toRecipient, provider } = creatingNoteParams;
32
98
  if (typeof identifier !== 'string' || identifier.length === 0) {
33
99
  throw new factory.errors.ArgumentNull('identifier');
34
100
  }
@@ -48,7 +114,8 @@ class MessageRepo {
48
114
  typeOf: factory.creativeWorkType.EmailMessage
49
115
  };
50
116
  // 変更可能な属性のみ上書き
51
- const setFields = Object.assign({ mainEntity,
117
+ const setFields = Object.assign({ provider,
118
+ mainEntity,
52
119
  about,
53
120
  sender,
54
121
  text,
@@ -11,6 +11,10 @@ const schemaDefinition = {
11
11
  type: mongoose_1.SchemaTypes.Mixed,
12
12
  required: true
13
13
  },
14
+ provider: {
15
+ type: mongoose_1.SchemaTypes.Mixed,
16
+ required: true
17
+ },
14
18
  typeOf: {
15
19
  type: String,
16
20
  required: true
@@ -352,7 +352,7 @@ function payActionParams2seatInfoSyncIn(params) {
352
352
  function refundMovieTicket(params) {
353
353
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
354
354
  return (repos) => __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b, _c, _d, _e, _f, _g;
355
+ var _a, _b, _c, _d, _e, _f, _g, _h;
356
356
  const paymentMethodId = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.paymentMethod.paymentMethodId;
357
357
  const paymentServiceId = (_b = params.object[0]) === null || _b === void 0 ? void 0 : _b.id;
358
358
  const availableChannel = yield repos.paymentService.findAvailableChannel({
@@ -387,12 +387,7 @@ function refundMovieTicket(params) {
387
387
  // instrumentをセット(2024-04-30~)
388
388
  const instrument = Object.assign(Object.assign({ typeOf: factory.service.paymentService.PaymentServiceType.MovieTicket }, (seatInfoSyncIn !== undefined) ? { seatInfoSyncIn } : undefined), (seatInfoSyncCancelIn !== undefined) ? { seatInfoSyncCancelIn } : undefined);
389
389
  let action = yield repos.action.start(Object.assign(Object.assign(Object.assign({}, params), (typeof ((_g = params.sameAs) === null || _g === void 0 ? void 0 : _g.id) === 'string')
390
- ? {
391
- sameAs: {
392
- id: params.sameAs.id,
393
- typeOf: 'Task'
394
- }
395
- }
390
+ ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } }
396
391
  : undefined), { instrument }));
397
392
  let seatInfoSyncCancelResult;
398
393
  let seatInfoSyncResult;
@@ -406,28 +401,18 @@ function refundMovieTicket(params) {
406
401
  }
407
402
  catch (error) {
408
403
  let throwsError = true;
409
- // 「存在しない興行会社システム座席予約番号が入力されました」の場合、取消済なのでok
410
404
  if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
411
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.NotFound) {
412
- seatInfoSyncCancelResult = error;
413
- throwsError = false;
414
- }
415
- // ReservationResult 19の内容が不明だがリトライする意味はおそらくないパターン
416
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.ReservationResult19) {
417
- seatInfoSyncCancelResult = error;
418
- throwsError = false;
419
- }
420
- // surfrock: bookingNoが存在しないケースをハンドル(2024-03-13~)
421
- const expectedMessage4surfrockNotFound = JSON.stringify({ message: `bookingNo:"${paymentMethodId}" が見つかりません。` });
422
- if (error.code === http_status_1.BAD_REQUEST && error.message === expectedMessage4surfrockNotFound) {
423
- seatInfoSyncCancelResult = error;
424
- throwsError = false;
425
- }
426
- // 着券取消可能期間超過を認識した上でのあえての返金の場合(注文からしばらく経って返品など)(2024-03-19~)
427
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.CancellationPeriodPassed) {
428
- if (params.purpose.typeOf === factory.actionType.ReturnAction) {
429
- seatInfoSyncResultAsError = error;
430
- throwsError = false;
405
+ if (error.code === http_status_1.BAD_REQUEST) {
406
+ if (Array.isArray(error.errors) && error.errors.length > 0) {
407
+ const mvtkReserveServiceError = error.errors[0];
408
+ // 興行会社システム座席予約番号存在無の場合、取消済なのでok
409
+ if (mvtkReserveServiceError.status === surfrock.factory.ResultStatus.Success) {
410
+ const cnclResult = (_h = mvtkReserveServiceError.rawResult) === null || _h === void 0 ? void 0 : _h.cnclResult;
411
+ if (cnclResult === surfrock.service.seat.factory.seatInfoSyncCancel.CancelResult.CancelResult02) {
412
+ seatInfoSyncCancelResult = error;
413
+ throwsError = false;
414
+ }
415
+ }
431
416
  }
432
417
  }
433
418
  }
@@ -565,9 +550,9 @@ function createSeatInfoSyncCancelInOnRefund(params) {
565
550
  let seatInfoSyncCancelIn;
566
551
  seatInfoSyncCancelIn = {
567
552
  kgygishCd: seatInfoSyncInOnPay.kgygishCd,
568
- kgysystmzskyykNo: seatInfoSyncInOnPay.kgysystmzskyykNo,
553
+ kgysystmzskyykNo: seatInfoSyncInOnPay.kgygishSstmZskyykNo,
569
554
  kgysystmzskyykNoIkktsCnclFlg: '1',
570
- jyuTyp: surfrock.service.seat.factory.seatInfoSyncCancel.IJyuTyp.IJyuTyp05,
555
+ jyuTyp: surfrock.service.seat.factory.seatInfoSyncCancel.JyuTyp.IJyuTyp05,
571
556
  jyuTypRmk: ''
572
557
  // knyknrNoInfoIn: [],
573
558
  };
@@ -130,12 +130,13 @@ function saveMessagesIfNeeded(params, order, emailMessages) {
130
130
  return (repos) => __awaiter(this, void 0, void 0, function* () {
131
131
  if (params.options.useSaveMessages) {
132
132
  if (emailMessages.length > 0) {
133
- const { orderNumber, typeOf, project } = order;
133
+ const { orderNumber, typeOf, project, seller } = order;
134
134
  debug('saving', emailMessages.length, 'messages...', emailMessages);
135
135
  const saveMessageResult = yield repos.message.upsertByIdentifier(emailMessages.map(({ identifier, name, about, text, toRecipient, sender }) => {
136
136
  return {
137
137
  identifier, name, about, text, toRecipient, sender,
138
138
  project,
139
+ provider: { id: seller.id, typeOf: seller.typeOf },
139
140
  mainEntity: { orderNumber, typeOf }
140
141
  };
141
142
  }));
package/package.json CHANGED
@@ -10,12 +10,12 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.369.0-alpha.2",
13
+ "@chevre/factory": "4.369.0-alpha.3",
14
14
  "@cinerino/sdk": "5.17.1",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
17
17
  "@sendgrid/mail": "6.4.0",
18
- "@surfrock/sdk": "1.3.0-alpha.0",
18
+ "@surfrock/sdk": "1.3.0-alpha.1",
19
19
  "cdigit": "2.6.7",
20
20
  "debug": "^3.2.7",
21
21
  "google-libphonenumber": "^3.2.18",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.30.0-alpha.21"
113
+ "version": "21.30.0-alpha.23"
114
114
  }