@chevre/domain 25.2.0-alpha.12 → 25.2.0-alpha.13

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.
@@ -9,6 +9,9 @@ export { ICancelActionAction };
9
9
  */
10
10
  type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction>;
11
11
  type IAvailableActionRecipe = IActionRecipe<Exclude<factory.recipe.RecipeCategory, factory.recipe.RecipeCategory.publishPaymentUrl | factory.recipe.RecipeCategory.checkMovieTicket | factory.recipe.RecipeCategory.acceptCOAOffer | factory.recipe.RecipeCategory.authorizeInvoice | factory.recipe.RecipeCategory.authorizeInvoice3ds | factory.recipe.RecipeCategory.payCreditCard | factory.recipe.RecipeCategory.payMovieTicket | factory.recipe.RecipeCategory.refundCreditCard | factory.recipe.RecipeCategory.refundMovieTicket>>;
12
+ export interface IDeleteActionResult {
13
+ deletedCount?: number;
14
+ }
12
15
  /**
13
16
  * アクションリポジトリ
14
17
  */
@@ -50,15 +53,20 @@ export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActio
50
53
  orderNumber: string;
51
54
  sort?: factory.action.ISortOrder;
52
55
  }): Promise<IAction<factory.actionType>[]>;
56
+ /**
57
+ * 注文番号から、注文に対するアクションを削除する
58
+ */
59
+ deleteActionsByOrderNumber(params: {
60
+ project: {
61
+ id: string;
62
+ };
63
+ orderNumber: string;
64
+ }): Promise<IDeleteActionResult[]>;
53
65
  deleteByProject(params: {
54
66
  project: {
55
67
  id: string;
56
68
  };
57
69
  }): Promise<void>;
58
- /**
59
- * イベントと入場ゲート指定で予約使用アクションを集計する
60
- * discontinue(2024-12-26~)
61
- */
62
70
  /**
63
71
  * 開始日時を一定期間過ぎたアクションを削除する
64
72
  */
@@ -78,20 +86,18 @@ export declare class ActionRepo extends ActionProcessRepo<IAction<StartableActio
78
86
  /**
79
87
  * 取引からアクションを削除する
80
88
  */
81
- deleteByPurpose(params: {
89
+ deleteActionsByTransactionId(params: {
82
90
  project: {
83
91
  id: string;
84
92
  };
85
- purpose: {
93
+ transaction: {
86
94
  typeOf: factory.transactionType;
87
95
  id: string;
88
96
  };
89
97
  typeOf: {
90
98
  $in: factory.actionType[];
91
99
  };
92
- }): Promise<{
93
- deletedCount?: number;
94
- } | null>;
100
+ }): Promise<IDeleteActionResult[]>;
95
101
  getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<import("@chevre/factory/lib/chevre/action").IAction<import("@chevre/factory/lib/chevre/action").IAttributes<factory.actionType, any, any>>, "id"> & {
96
102
  identifier?: string;
97
103
  } & {
@@ -312,130 +312,55 @@ class ActionRepo extends actionProcess_1.ActionProcessRepo {
312
312
  .lean() // 2024-08-26~
313
313
  .exec();
314
314
  }
315
+ /**
316
+ * 注文番号から、注文に対するアクションを削除する
317
+ */
318
+ async deleteActionsByOrderNumber(params) {
319
+ const { project, orderNumber } = params;
320
+ if (typeof project.id !== 'string' || project.id === '') {
321
+ throw new factory_1.factory.errors.ArgumentNull('project.id');
322
+ }
323
+ if (typeof orderNumber !== 'string' || orderNumber === '') {
324
+ throw new factory_1.factory.errors.ArgumentNull('orderNumber');
325
+ }
326
+ const filters = [
327
+ {
328
+ 'project.id': { $eq: project.id },
329
+ 'object.orderNumber': { $exists: true, $eq: orderNumber }
330
+ },
331
+ {
332
+ 'project.id': { $eq: project.id },
333
+ 'purpose.orderNumber': { $exists: true, $eq: orderNumber }
334
+ },
335
+ {
336
+ 'project.id': { $eq: project.id },
337
+ 'about.orderNumber': { $exists: true, $eq: orderNumber }
338
+ },
339
+ {
340
+ 'project.id': { $eq: project.id },
341
+ 'instrument.orderNumber': { $exists: true, $eq: orderNumber }
342
+ },
343
+ ];
344
+ const results = await Promise.all(filters.map(async (filter) => {
345
+ return this.actionModel.deleteMany(filter)
346
+ .exec();
347
+ }));
348
+ return results.map((result) => {
349
+ return {
350
+ // n: result?.n,
351
+ // opTime: result.opTime,
352
+ // ok: result?.ok,
353
+ // operationTime,
354
+ deletedCount: result?.deletedCount
355
+ };
356
+ });
357
+ }
315
358
  async deleteByProject(params) {
316
359
  await this.actionModel.deleteMany({
317
360
  'project.id': { $eq: params.project.id }
318
361
  })
319
362
  .exec();
320
363
  }
321
- // public async reCompleteAuthorizeEventOfferAction(params: {
322
- // id: string;
323
- // object: factory.action.authorize.offer.eventService.IObject;
324
- // result: factory.action.authorize.offer.eventService.IResult;
325
- // }): Promise<void> {
326
- // return this.actionModel.findOneAndUpdate(
327
- // {
328
- // // typeOf: factory.actionType.AuthorizeAction,
329
- // _id: { $eq: params.id },
330
- // // ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
331
- // // actionStatus: factory.actionStatusType.CompletedActionStatus
332
- // actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus }
333
- // },
334
- // {
335
- // $set: {
336
- // actionStatus: factory.actionStatusType.CompletedActionStatus,
337
- // object: params.object,
338
- // result: params.result,
339
- // endDate: new Date()
340
- // }
341
- // },
342
- // { new: true, projection: { _id: 1 } }
343
- // )
344
- // .lean<{ _id: ObjectId }>()
345
- // .exec()
346
- // .then((doc) => {
347
- // if (doc === null) {
348
- // throw new factory.errors.NotFound(this.actionModel.modelName);
349
- // }
350
- // });
351
- // }
352
- // public async updateById(params: {
353
- // id: string;
354
- // update: any;
355
- // }): Promise<void> {
356
- // await this.actionModel.updateOne(
357
- // { _id: { $eq: params.id } },
358
- // params.update
359
- // )
360
- // .exec();
361
- // }
362
- // public async findByIdAndUpdate(params: {
363
- // id: string;
364
- // update: UpdateQuery<IAction<factory.actionType>>;
365
- // }): Promise<void> {
366
- // await this.actionModel.findOneAndUpdate(
367
- // { _id: { $eq: params.id } },
368
- // params.update,
369
- // { projection: { _id: 1 } }
370
- // )
371
- // .lean<{ _id: ObjectId }>()
372
- // .exec()
373
- // .then((doc) => {
374
- // if (doc === null) {
375
- // throw new factory.errors.NotFound(this.actionModel.modelName);
376
- // }
377
- // });
378
- // }
379
- /**
380
- * イベントと入場ゲート指定で予約使用アクションを集計する
381
- * discontinue(2024-12-26~)
382
- */
383
- // public async countUseActionsByEntranceGate(params: {
384
- // event: { id: string };
385
- // entranceGateIdentifier: string;
386
- // }): Promise<IUseActionCountByOffer[]> {
387
- // return this.actionModel.aggregate([
388
- // {
389
- // $match: {
390
- // actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
391
- // }
392
- // },
393
- // {
394
- // $match: {
395
- // typeOf: { $eq: factory.actionType.UseAction }
396
- // }
397
- // },
398
- // {
399
- // $match: {
400
- // 'object.typeOf': {
401
- // $exists: true,
402
- // $eq: factory.reservationType.EventReservation
403
- // }
404
- // }
405
- // },
406
- // {
407
- // $match: {
408
- // 'object.reservationFor.id': {
409
- // $exists: true,
410
- // $eq: params.event.id
411
- // }
412
- // }
413
- // },
414
- // {
415
- // $match: {
416
- // 'location.identifier': {
417
- // $exists: true,
418
- // $eq: params.entranceGateIdentifier
419
- // }
420
- // }
421
- // },
422
- // {
423
- // $group: {
424
- // _id: '$object.id',
425
- // object: { $first: '$object' }
426
- // }
427
- // },
428
- // {
429
- // $group: {
430
- // _id: '$object.reservedTicket.ticketType.id',
431
- // useActionCount: {
432
- // $sum: 1
433
- // }
434
- // }
435
- // }
436
- // ])
437
- // .exec();
438
- // }
439
364
  /**
440
365
  * 開始日時を一定期間過ぎたアクションを削除する
441
366
  */
@@ -473,15 +398,34 @@ class ActionRepo extends actionProcess_1.ActionProcessRepo {
473
398
  /**
474
399
  * 取引からアクションを削除する
475
400
  */
476
- async deleteByPurpose(params) {
477
- return this.actionModel.deleteMany({
478
- 'project.id': { $eq: params.project.id },
479
- typeOf: { $in: params.typeOf.$in },
480
- 'purpose.id': { $exists: true, $eq: params.purpose.id },
481
- 'purpose.typeOf': { $exists: true, $eq: params.purpose.typeOf }
482
- })
483
- .exec()
484
- .then((result) => {
401
+ async deleteActionsByTransactionId(params) {
402
+ const { project, transaction } = params;
403
+ if (typeof project.id !== 'string' || project.id === '') {
404
+ throw new factory_1.factory.errors.ArgumentNull('project.id');
405
+ }
406
+ if (typeof transaction.id !== 'string' || transaction.id === '') {
407
+ throw new factory_1.factory.errors.ArgumentNull('transaction.id ');
408
+ }
409
+ const filters = [
410
+ {
411
+ 'project.id': { $eq: project.id },
412
+ typeOf: { $in: params.typeOf.$in },
413
+ 'purpose.id': { $exists: true, $eq: transaction.id },
414
+ 'purpose.typeOf': { $exists: true, $eq: transaction.typeOf }
415
+ },
416
+ // instrumentによるアクション削除にも対応(2026-07-10~)
417
+ {
418
+ 'project.id': { $eq: project.id },
419
+ // typeOf: { $in: params.typeOf.$in }, // typOfでフィルターしない
420
+ 'instrument.id': { $exists: true, $eq: transaction.id },
421
+ 'instrument.typeOf': { $exists: true, $eq: transaction.typeOf }
422
+ }
423
+ ];
424
+ const results = await Promise.all(filters.map(async (filter) => {
425
+ return this.actionModel.deleteMany(filter)
426
+ .exec();
427
+ }));
428
+ return results.map((result) => {
485
429
  return {
486
430
  // n: result?.n,
487
431
  // opTime: result.opTime,
@@ -491,51 +435,6 @@ class ActionRepo extends actionProcess_1.ActionProcessRepo {
491
435
  };
492
436
  });
493
437
  }
494
- // public async saveActionWithEndDate(savingAction: Omit<factory.action.authorize.invoice.IAction, 'id'>) {
495
- // const { sameAs, typeOf, project, agent, object, ...updateFields } = savingAction;
496
- // const filter: FilterQuery<factory.recipe.IRecipe> = {
497
- // 'project.id': { $eq: project.id },
498
- // // 'agent.id': { $exists: true, $eq: agent.id },
499
- // // 'object.typeOf': { $exists: true, $eq: object.typeOf },
500
- // 'object.paymentMethodId': { $exists: true, $eq: object.paymentMethodId },
501
- // typeOf: { $eq: typeOf },
502
- // 'sameAs.id': { $exists: true, $eq: sameAs.id }
503
- // };
504
- // const setOnInsert: AnyKeys<IAction<factory.actionType>> = { typeOf, project, agent, object, sameAs };
505
- // const setKeys: AnyKeys<IAction<factory.actionType>> = updateFields;
506
- // const update: UpdateQuery<IAction<factory.actionType>> = {
507
- // $setOnInsert: setOnInsert,
508
- // $set: setKeys
509
- // };
510
- // return this.actionModel.updateOne<HydratedDocument<IRecipeAsDocument>>(
511
- // filter,
512
- // update,
513
- // {
514
- // upsert: true,
515
- // includeResultMetadata: true
516
- // }
517
- // )
518
- // .exec();
519
- // }
520
- // public async findRecipeByAction<T extends factory.recipe.RecipeCategory>(params: {
521
- // project: { id: string };
522
- // recipeFor: { id: string };
523
- // }): Promise<Pick<IActionRecipe<T>, 'step' | 'recipeCategory'> | null> {
524
- // return this.actionRecipeModel.findOne(
525
- // {
526
- // 'project.id': { $eq: params.project.id },
527
- // 'recipeFor.id': { $eq: params.recipeFor.id }
528
- // },
529
- // { step: 1, recipeCategory: 1 }
530
- // // { lean: true }
531
- // )
532
- // .lean<Pick<IActionRecipe<T>, 'step' | 'recipeCategory'>>()
533
- // .exec();
534
- // // if (result === null) {
535
- // // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
536
- // // }
537
- // // return result;
538
- // }
539
438
  getCursor(conditions, projection) {
540
439
  return this.actionModel.find(conditions, projection)
541
440
  .sort({ startDate: factory_1.factory.sortType.Descending })
@@ -1,5 +1,6 @@
1
1
  import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
2
2
  import type { AccountingReportRepo } from '../../repo/accountingReport';
3
+ import type { IDeleteActionResult, ActionRepo } from '../../repo/action';
3
4
  import type { NoteRepo } from '../../repo/note';
4
5
  import type { OrderRepo } from '../../repo/order';
5
6
  import type { ReservationRepo } from '../../repo/reservation';
@@ -17,8 +18,11 @@ declare function deleteOrder(params: {
17
18
  }): (repos: {
18
19
  acceptedOffer: AcceptedOfferRepo;
19
20
  accountingReport: AccountingReportRepo;
21
+ action: ActionRepo;
20
22
  note: NoteRepo;
21
23
  order: OrderRepo;
22
24
  reservation: ReservationRepo;
23
- }) => Promise<void>;
25
+ }) => Promise<{
26
+ deleteActionsResult: IDeleteActionResult[];
27
+ }>;
24
28
  export { deleteOrder };
@@ -12,6 +12,7 @@ function deleteOrder(params) {
12
12
  if (typeof params.object.identifier !== 'string' || params.object.identifier === '') {
13
13
  throw new factory_1.factory.errors.ArgumentNull('object.identifier');
14
14
  }
15
+ let deleteActionsResult = [];
15
16
  const orders = await repos.order.projectFields({
16
17
  limit: 1,
17
18
  page: 1,
@@ -21,7 +22,7 @@ function deleteOrder(params) {
21
22
  const order = orders.shift();
22
23
  if (order === undefined) {
23
24
  // すでに削除済
24
- return;
25
+ return { deleteActionsResult: [] };
25
26
  }
26
27
  if (typeof order.id !== 'string') {
27
28
  throw new factory_1.factory.errors.Internal(`order.id undefined. orderNumber: ${order.orderNumber}`);
@@ -43,8 +44,14 @@ function deleteOrder(params) {
43
44
  typeOf: factory_1.factory.order.OrderType.Order
44
45
  }
45
46
  });
47
+ // アクション削除(2026-07-10~)
48
+ deleteActionsResult = await repos.action.deleteActionsByOrderNumber({
49
+ orderNumber: order.orderNumber,
50
+ project: { id: order.project.id },
51
+ });
46
52
  // 注文削除
47
53
  await repos.order.deleteByOrderNumber({ orderNumber: order.orderNumber });
54
+ return { deleteActionsResult };
48
55
  };
49
56
  }
50
57
  function deleteReservationsByOrder(order) {
@@ -70,6 +70,7 @@ function deleteTransactionById(params) {
70
70
  let deleteCancelReservationTransactionResult;
71
71
  let deletedReservationNumbers = [];
72
72
  let deleteActionResult;
73
+ let deleteOrderResult;
73
74
  const action = await repos.action.start(actionAttributes);
74
75
  try {
75
76
  const transactionTypeOf = transaction.typeOf;
@@ -89,7 +90,7 @@ function deleteTransactionById(params) {
89
90
  break;
90
91
  case factory_1.factory.transactionStatusType.Confirmed: {
91
92
  // identifierによる削除に変更(2026-06-28~)
92
- await (0, deleteOrder_1.deleteOrder)({
93
+ deleteOrderResult = await (0, deleteOrder_1.deleteOrder)({
93
94
  object: { identifier: transaction.id }
94
95
  })(repos);
95
96
  break;
@@ -110,9 +111,9 @@ function deleteTransactionById(params) {
110
111
  deleteReservationsByPlaceOrderResult.deleteCancelReservationTransactionResult;
111
112
  deletedReservationNumbers = deleteReservationsByPlaceOrderResult.reserveTransactionNumbers;
112
113
  // アクション削除(2023-05-19~)
113
- deleteActionResult = await repos.action.deleteByPurpose({
114
+ deleteActionResult = await repos.action.deleteActionsByTransactionId({
114
115
  project: { id: transaction.project.id },
115
- purpose: { id: transaction.id, typeOf: transactionTypeOf },
116
+ transaction: { id: transaction.id, typeOf: transactionTypeOf },
116
117
  typeOf: {
117
118
  $in: [
118
119
  factory_1.factory.actionType.AcceptAction, // オファー採用、決済採用
@@ -162,6 +163,7 @@ function deleteTransactionById(params) {
162
163
  deleteCancelReservationTransactionResult,
163
164
  deletedReservationNumbers,
164
165
  deleteActionResult,
166
+ deleteOrderResult // 2026-07-10~
165
167
  // ...(deleteMessagessResult !== undefined) ? { deleteMessagessResult } : undefined
166
168
  };
167
169
  await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "25.2.0-alpha.12"
94
+ "version": "25.2.0-alpha.13"
95
95
  }