@chevre/domain 25.0.0-alpha.20 → 25.0.0-alpha.21

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.
@@ -2,44 +2,57 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.issueOrderNumberIfNotExist = issueOrderNumberIfNotExist;
4
4
  const factory_1 = require("../../../factory");
5
- // const USE_LEGACY_ISSUE_ORDER_NUMBER = process.env.USE_LEGACY_ISSUE_ORDER_NUMBER === '1';
6
5
  /**
7
6
  * 未発行であれば、注文番号を発行して取引に保管する
8
7
  */
9
- function issueOrderNumberIfNotExist(params) {
8
+ function issueOrderNumberIfNotExist(params, options) {
10
9
  return async (repos) => {
11
- // 1. 最初のチェック
12
- let orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
13
- // すでに発行済であれば何もしない
14
- if (typeof orderNumber === 'string') {
15
- return orderNumber;
16
- }
17
- // 2. 発行準備
10
+ const { saveOrderNumberInPlaceOrderInProgress } = options;
11
+ // // 1. 最初のチェック
12
+ // let orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
13
+ // // すでに発行済であれば何もしない
14
+ // if (typeof orderNumber === 'string') {
15
+ // return orderNumber;
16
+ // }
17
+ // 新注文番号発行
18
18
  const { alternateName } = await repos.project.findAlternateNameById({ id: params.project.id });
19
19
  if (typeof alternateName !== 'string') {
20
20
  throw new factory_1.factory.errors.NotFound('project.alternateName');
21
21
  }
22
- // 3. 番号発行
23
22
  const issuedOrderNumber = await repos.orderNumber.issueOrderNumber({
24
23
  project: { alternateName },
25
24
  orderDate: params.object.orderDate
26
25
  });
27
- // 4. 保管を試みる
28
- const { modifiedCount } = await repos.placeOrder.saveOrderNumberIfNotExist({
29
- id: params.id,
30
- orderNumber: issuedOrderNumber
26
+ // 注文ドキュメント作成
27
+ await repos.orderInTransaction.createPlaceOrderIfNotExists({
28
+ ...params.creatingOrderInTransaction,
29
+ orderNumber: issuedOrderNumber,
30
+ project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
31
+ identifier: params.id,
31
32
  });
32
- // 5. 書き込めたなら、自分が発行した番号が「真実」
33
- if (modifiedCount === 1) {
34
- return issuedOrderNumber;
35
- }
36
- // 6. 競合が発生した場合(他者が先に書き込んだ場合)
37
- // DBにある「正解」を再取得して返す
38
- orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
39
- if (typeof orderNumber !== 'string') {
40
- // ここを通るのは、他者が保存した直後に取引がキャンセル/削除された等の極めて稀なケース
41
- throw new factory_1.factory.errors.Internal('OrderNumber conflict: failed to retrieve existing number');
33
+ // 注文ドキュメント(存在するはず)から注文番号を参照
34
+ const orderNumber = await repos.orderInTransaction.findOrderNumberByIdentifier({
35
+ identifier: params.id,
36
+ project: { id: params.project.id }
37
+ }, { onlyPlaceOrder: true });
38
+ if (saveOrderNumberInPlaceOrderInProgress) {
39
+ // 取引に保管を試みる
40
+ await repos.placeOrder.saveOrderNumberIfNotExist({
41
+ id: params.id,
42
+ orderNumber
43
+ });
42
44
  }
45
+ // // 5. 書き込めたなら、自分が発行した番号が「真実」
46
+ // if (modifiedCount === 1) {
47
+ // return issuedOrderNumber;
48
+ // }
49
+ // // 6. 競合が発生した場合(他者が先に書き込んだ場合)
50
+ // // DBにある「正解」を再取得して返す
51
+ // const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
52
+ // if (typeof orderNumber !== 'string') {
53
+ // // ここを通るのは、他者が保存した直後に取引がキャンセル/削除された等の極めて稀なケース
54
+ // throw new factory.errors.Internal('OrderNumber conflict: failed to retrieve existing number');
55
+ // }
43
56
  return orderNumber;
44
57
  };
45
58
  }
@@ -25,5 +25,7 @@ type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
25
25
  /**
26
26
  * 取引開始
27
27
  */
28
- declare function start(params: IStartPlaceOrderParams): IStartOperation<IStartedPlaceOrder>;
28
+ declare function start(params: IStartPlaceOrderParams, options: {
29
+ saveOrderNumberInPlaceOrderInProgress: boolean;
30
+ }): IStartOperation<IStartedPlaceOrder>;
29
31
  export { start, IStartPlaceOrderParams };
@@ -8,7 +8,7 @@ const issueOrderNumberIfNotExist_1 = require("./issueOrderNumberIfNotExist");
8
8
  /**
9
9
  * 取引開始
10
10
  */
11
- function start(params) {
11
+ function start(params, options) {
12
12
  return async (repos) => {
13
13
  const { passport, customerType } = await repos.passport.validatePassportTokenIfExist(params);
14
14
  const { sellerMakesOffer, seller } = await (0, validateStartRequest_1.validateStartRequest)({
@@ -52,26 +52,22 @@ function start(params) {
52
52
  if (transaction === undefined) {
53
53
  transaction = await repos.placeOrder.startPlaceOrder(startParams);
54
54
  }
55
- // support createOrderDocument(2026-06-23~)
56
- const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
55
+ await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
57
56
  project: { id: params.project.id },
58
57
  id: transaction.id,
59
- object: { orderDate: new Date() }
60
- })(repos);
61
- await repos.orderInTransaction.createPlaceOrderIfNotExists({
62
- orderNumber,
63
- project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
64
- identifier: transaction.id,
65
- seller: {
66
- id: seller.id,
67
- name: (typeof seller.name === 'string') ? seller.name : String(seller.name?.ja),
68
- typeOf: seller.typeOf,
69
- additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
70
- },
71
- ...((typeof params.object.customer?.typeOf === 'string') && { customer: params.object.customer }),
72
- ...((typeof params.broker?.typeOf === 'string') && { broker: params.broker })
73
- });
74
- // console.log('createPlaceOrderResult:', createPlaceOrderResult);
58
+ object: { orderDate: new Date() },
59
+ // support createOrderDocument(2026-06-23~)
60
+ creatingOrderInTransaction: {
61
+ seller: {
62
+ id: seller.id,
63
+ name: (typeof seller.name === 'string') ? seller.name : String(seller.name?.ja),
64
+ typeOf: seller.typeOf,
65
+ additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
66
+ },
67
+ ...((typeof params.object.customer?.typeOf === 'string') && { customer: params.object.customer }),
68
+ ...((typeof params.broker?.typeOf === 'string') && { broker: params.broker })
69
+ }
70
+ }, options)(repos);
75
71
  return transaction;
76
72
  };
77
73
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "9.0.0",
14
+ "@chevre/factory": "9.2.0",
15
15
  "@motionpicture/coa-service": "10.0.0",
16
16
  "@motionpicture/gmo-service": "6.1.0-alpha.0",
17
17
  "@sendgrid/client": "8.1.4",
@@ -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.0.0-alpha.20"
94
+ "version": "25.0.0-alpha.21"
95
95
  }
@@ -1,6 +0,0 @@
1
- import { factory } from '../../factory';
2
- import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(params: Pick<factory.task.deletePerson.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
@@ -1,465 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.call = call;
7
- const debug_1 = __importDefault(require("debug"));
8
- const factory_1 = require("../../factory");
9
- const action_1 = require("../../repo/action");
10
- const ownershipInfo_1 = require("../../repo/ownershipInfo");
11
- const paymentService_1 = require("../../repo/paymentService");
12
- const person_1 = require("../../repo/person");
13
- const setting_1 = require("../../repo/setting");
14
- const task_1 = require("../../repo/task");
15
- const debug = (0, debug_1.default)('chevre-domain:service:task:deletePerson');
16
- // type IOwnershipInfoPermit = factory.ownershipInfo.IPermitAsGood;
17
- const ADMIN_PROVIDER_NAME = 'Google';
18
- let cognitoIdentityServiceProvider;
19
- /**
20
- * タスク実行関数
21
- */
22
- function call(params) {
23
- return async ({ connection }) => {
24
- if (cognitoIdentityServiceProvider === undefined) {
25
- const { CognitoIdentityProvider } = await import('@aws-sdk/client-cognito-identity-provider');
26
- const { fromEnv } = await import('@aws-sdk/credential-providers');
27
- cognitoIdentityServiceProvider = new CognitoIdentityProvider({
28
- apiVersion: 'latest',
29
- region: 'ap-northeast-1',
30
- credentials: fromEnv()
31
- });
32
- }
33
- const settingRepo = new setting_1.SettingRepo(connection);
34
- const setting = await settingRepo.findOne({ project: { id: { $eq: '*' } } }, ['userPoolIdOld']);
35
- if (typeof setting?.userPoolIdOld !== 'string') {
36
- throw new factory_1.factory.errors.NotFound('setting.userPoolIdOld');
37
- }
38
- const newPersonRepo = new person_1.PersonRepo({
39
- userPoolId: params.data.userPoolId,
40
- cognitoIdentityServiceProvider
41
- });
42
- const oldPersonRepo = new person_1.PersonRepo({
43
- // userPoolId: settings.userPoolIdOld,
44
- userPoolId: setting.userPoolIdOld,
45
- cognitoIdentityServiceProvider
46
- });
47
- const paymentServiceRepo = new paymentService_1.PaymentServiceRepo(connection);
48
- await deleteById({
49
- ...params.data,
50
- project: { id: params.project.id }
51
- })({
52
- action: new action_1.ActionRepo(connection),
53
- ownershipInfo: new ownershipInfo_1.OwnershipInfoRepo(connection),
54
- paymentService: paymentServiceRepo,
55
- newPerson: newPersonRepo,
56
- oldPerson: oldPersonRepo,
57
- task: new task_1.TaskRepo(connection),
58
- cognitoIdentityServiceProvider
59
- });
60
- };
61
- }
62
- /**
63
- * 会員削除処理
64
- */
65
- function deleteById(params
66
- // setting: Pick<ISetting, 'userPoolIdOld'>
67
- ) {
68
- return async (repos) => {
69
- const deleteObject = {
70
- id: params.id,
71
- typeOf: factory_1.factory.personType.Person,
72
- // migrate: params.migrate, // discontinue(2026-04-08~)
73
- physically: params.physically
74
- };
75
- const deleteMemberAction = {
76
- agent: params.agent,
77
- object: deleteObject,
78
- project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
79
- typeOf: factory_1.factory.actionType.DeleteAction
80
- };
81
- const action = await repos.action.start(deleteMemberAction);
82
- let existingPeople;
83
- try {
84
- existingPeople = await repos.newPerson.search({ id: params.id });
85
- // exclude ADMIN_PROVIDER_NAME
86
- const username = existingPeople.at(0)?.Username;
87
- const isAdminPerson = typeof username === 'string' && username.startsWith(ADMIN_PROVIDER_NAME, 0);
88
- if (isAdminPerson) {
89
- throw new factory_1.factory.errors.Argument('id', `${ADMIN_PROVIDER_NAME} people cannot be deleted`);
90
- }
91
- // if (!params.migrate) {
92
- // }
93
- // 移行でなければDeleteTransactionタスクを作成(2023-07-03~)
94
- await createDeleteTransactionTask({
95
- id: params.id,
96
- project: { id: params.project.id },
97
- now: action.startDate
98
- })({ task: repos.task });
99
- if (existingPeople.length > 0) {
100
- // if (repos.creditCard !== undefined) {
101
- // // クレジットカード削除
102
- // await deleteCreditCardsById(
103
- // {
104
- // id: params.id,
105
- // useUsernameAsGMOMemberId: params.useUsernameAsGMOMemberId
106
- // },
107
- // setting
108
- // )(
109
- // {
110
- // person: repos.newPerson,
111
- // creditCard: repos.creditCard,
112
- // cognitoIdentityServiceProvider: repos.cognitoIdentityServiceProvider
113
- // }
114
- // );
115
- // }
116
- }
117
- // 所有権削除
118
- debug('task:deletePerson:deleteById: deleteOwnershipInfosById processing... personId:', params.id);
119
- await deleteOwnershipInfosById({
120
- id: params.id,
121
- project: { id: params.project.id }
122
- })({ ownershipInfo: repos.ownershipInfo });
123
- if (existingPeople.length > 0) {
124
- // 会員削除
125
- if (params.physically === true) {
126
- debug('task:deletePerson:deleteById: deleteById processing...userId:', params.id);
127
- await repos.newPerson.deleteById({ userId: params.id });
128
- }
129
- else {
130
- // Cognitoユーザを無効にする
131
- await repos.newPerson.globalSignOutAndDisable({ userId: params.id });
132
- }
133
- }
134
- }
135
- catch (error) {
136
- try {
137
- await repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
138
- }
139
- catch (__) {
140
- // no op
141
- }
142
- throw error;
143
- }
144
- const actionResult = { existingPeople };
145
- await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
146
- };
147
- }
148
- // interface ICreditCardPaymentServiceCredentials {
149
- // endpoint: string;
150
- // siteId: string;
151
- // sitePass: string;
152
- // }
153
- // function getCreditCardPaymentServiceChannel(params: {
154
- // project: { id: string };
155
- // paymentMethodType: string;
156
- // }) {
157
- // return async (repos: {
158
- // paymentService: PaymentServiceRepo;
159
- // }): Promise<ICreditCardPaymentServiceCredentials> => {
160
- // const paymentServices = await repos.paymentService.projectFields(
161
- // {
162
- // limit: 1,
163
- // project: { id: { $eq: params.project.id } },
164
- // typeOf: { $eq: factory.service.paymentService.PaymentServiceType.CreditCard },
165
- // serviceType: { codeValue: { $eq: params.paymentMethodType } }
166
- // },
167
- // ['availableChannel']
168
- // ) as Pick<factory.service.paymentService.IService, 'availableChannel' | 'id'>[];
169
- // const paymentService = paymentServices.shift();
170
- // if (paymentService === undefined) {
171
- // throw new factory.errors.NotFound('PaymentService');
172
- // }
173
- // if (typeof paymentService.id !== 'string') {
174
- // throw new factory.errors.NotFound('paymentService.id.id');
175
- // }
176
- // const availableChannel = await repos.paymentService.findAvailableChannelCreditCard({
177
- // project: { id: params.project.id },
178
- // id: paymentService.id
179
- // });
180
- // // const availableChannel = paymentService?.availableChannel;
181
- // if (typeof availableChannel?.serviceUrl !== 'string') {
182
- // throw new factory.errors.NotFound('paymentService.availableChannel.serviceUrl');
183
- // }
184
- // if (typeof availableChannel?.credentials?.siteId !== 'string') {
185
- // throw new factory.errors.NotFound('paymentService.availableChannel.credentials.siteId');
186
- // }
187
- // if (typeof availableChannel?.credentials?.sitePass !== 'string') {
188
- // throw new factory.errors.NotFound('paymentService.availableChannel.credentials.sitePass');
189
- // }
190
- // return {
191
- // endpoint: availableChannel.serviceUrl,
192
- // siteId: availableChannel.credentials.siteId,
193
- // sitePass: availableChannel.credentials.sitePass
194
- // };
195
- // };
196
- // }
197
- // function createInformTask(params: {
198
- // id: string;
199
- // project: { id: string };
200
- // now: Date;
201
- // migratePersonRecipientUrl: string;
202
- // }) {
203
- // // tslint:disable-next-line:max-func-body-length
204
- // return async (repos: {
205
- // account: AccountRepo;
206
- // ownershipInfo: OwnershipInfoRepo;
207
- // newPerson: PersonRepo;
208
- // oldPerson: PersonRepo;
209
- // task: TaskRepo;
210
- // }) => {
211
- // const person = await repos.newPerson.findById({ userId: params.id });
212
- // let oldUser: factory.person.IPerson | undefined;
213
- // const userIdentitiesStr = person.additionalProperty?.find((p) => p.name === 'identities')?.value;
214
- // if (typeof userIdentitiesStr === 'string' && userIdentitiesStr.length > 0) {
215
- // try {
216
- // const identities = JSON.parse(userIdentitiesStr);
217
- // if (Array.isArray(identities) && identities.length > 0) {
218
- // const userIdByIdentities = identities[0].userId;
219
- // if (typeof userIdByIdentities === 'string' && userIdByIdentities.length > 0) {
220
- // // oldUserは必ず存在するはず
221
- // oldUser = await repos.oldPerson.findById({ userId: userIdByIdentities });
222
- // }
223
- // }
224
- // } catch (error) {
225
- // // tslint:disable-next-line:no-console
226
- // console.error('find oldUser throwed', error);
227
- // throw error;
228
- // }
229
- // }
230
- // const reservations = await repos.ownershipInfo.projectFields({
231
- // project: { id: { $eq: params.project.id } },
232
- // ownedBy: { id: params.id },
233
- // typeOfGood: { issuedThrough: { typeOf: { $eq: factory.product.ProductType.EventService } } }
234
- // });
235
- // const memberships = <factory.ownershipInfo.IOwnershipInfo<factory.ownershipInfo.IPermitAsGood>[]>
236
- // await repos.ownershipInfo.projectFields({
237
- // limit: 1,
238
- // page: 1,
239
- // project: { id: { $eq: params.project.id } },
240
- // ownedBy: { id: params.id },
241
- // typeOfGood: { issuedThrough: { typeOf: { $eq: factory.product.ProductType.MembershipService } } },
242
- // ownedFrom: params.now,
243
- // ownedThrough: params.now
244
- // });
245
- // let paymentCards = <factory.ownershipInfo.IOwnershipInfo<factory.ownershipInfo.IPermitAsGood & {
246
- // balance: number;
247
- // }>[]>
248
- // await repos.ownershipInfo.projectFields({
249
- // // 最も古い所有ペイメントカードをデフォルトペイメントカードとして扱う使用なので、ソート条件は以下の通り
250
- // sort: { ownedFrom: factory.sortType.Ascending },
251
- // limit: 1,
252
- // page: 1,
253
- // project: { id: { $eq: params.project.id } },
254
- // ownedBy: { id: params.id },
255
- // typeOfGood: { issuedThrough: { typeOf: { $eq: factory.product.ProductType.PaymentCard } } },
256
- // ownedFrom: params.now,
257
- // ownedThrough: params.now
258
- // });
259
- // paymentCards = await Promise.all(paymentCards.map(async (paymentCard) => {
260
- // // 口座検索
261
- // const accountNumber = String((<IOwnershipInfoPermit>paymentCard.typeOfGood).identifier);
262
- // const account = await repos.account.findByAccountNumber({ accountNumber });
263
- // return {
264
- // ...paymentCard,
265
- // typeOfGood: {
266
- // ...paymentCard.typeOfGood,
267
- // balance: account.balance
268
- // }
269
- // };
270
- // }));
271
- // // create task
272
- // let informTask: factory.task.IAttributes<factory.taskName.TriggerWebhook> & {
273
- // data: factory.task.triggerWebhook.IInformAnyResourceAction & {
274
- // object: factory.notification.person.IPersonAsNotification;
275
- // };
276
- // };
277
- // const informObject: factory.notification.person.IPersonAsNotification = {
278
- // id: person.id,
279
- // memberOf: person.memberOf,
280
- // typeOf: person.typeOf,
281
- // cognitoUser: {
282
- // Attributes: (<any>oldUser)?.Attributes,
283
- // Enabled: (<any>oldUser)?.Enabled,
284
- // UserCreateDate: (<any>oldUser)?.UserCreateDate,
285
- // UserLastModifiedDate: (<any>oldUser)?.UserLastModifiedDate,
286
- // UserStatus: (<any>oldUser)?.UserStatus,
287
- // Username: (<any>oldUser)?.Username
288
- // },
289
- // reservations: reservations.map((ownershipInfo) => {
290
- // const { id, typeOf, typeOfGood, ownedFrom, ownedThrough } = ownershipInfo;
291
- // return { id, typeOf, typeOfGood, ownedFrom, ownedThrough };
292
- // }),
293
- // memberships: memberships.map((ownershipInfo) => {
294
- // const { id, typeOf, typeOfGood, ownedFrom, ownedThrough } = ownershipInfo;
295
- // const { identifier } = typeOfGood;
296
- // return {
297
- // id,
298
- // typeOf,
299
- // typeOfGood: { identifier },
300
- // ownedFrom,
301
- // ownedThrough
302
- // };
303
- // }),
304
- // paymentCards: paymentCards.map((ownershipInfo) => {
305
- // const { id, typeOf, typeOfGood } = ownershipInfo;
306
- // const { balance, identifier } = typeOfGood;
307
- // return {
308
- // id,
309
- // typeOf,
310
- // typeOfGood: { balance, identifier }
311
- // };
312
- // })
313
- // };
314
- // const informActionAttributes: factory.task.triggerWebhook.IInformAnyResourceAction & {
315
- // object: factory.notification.person.IPersonAsNotification;
316
- // } = { // optimize(2024-07-01~)
317
- // object: informObject,
318
- // recipient: {
319
- // // url: params.migratePersonRecipientUrl, // discontinue(2025-02-13~)
320
- // id: '',
321
- // name: 'NewUserPool',
322
- // typeOf: factory.creativeWorkType.WebApplication
323
- // },
324
- // target: {
325
- // httpMethod: 'POST',
326
- // encodingType: factory.encodingFormat.Application.json,
327
- // typeOf: 'EntryPoint',
328
- // urlTemplate: params.migratePersonRecipientUrl
329
- // }
330
- // };
331
- // informTask = {
332
- // project: { id: params.project.id, typeOf: factory.organizationType.Project },
333
- // name: factory.taskName.TriggerWebhook,
334
- // status: factory.taskStatus.Ready,
335
- // runsAt: params.now,
336
- // remainingNumberOfTries: 10,
337
- // numberOfTried: 0,
338
- // executionResults: [],
339
- // data: informActionAttributes
340
- // };
341
- // await repos.task.createInformTaskIfNotExist(informTask, { emitImmediately: true });
342
- // };
343
- // }
344
- function createDeleteTransactionTask(params) {
345
- return async (repos) => {
346
- const deleteTransactionTasks = [
347
- factory_1.factory.transactionType.PlaceOrder,
348
- factory_1.factory.transactionType.ReturnOrder
349
- ].map((transactionType) => {
350
- return {
351
- project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
352
- name: factory_1.factory.taskName.DeleteTransaction,
353
- status: factory_1.factory.taskStatus.Ready,
354
- runsAt: params.now,
355
- remainingNumberOfTries: 3,
356
- numberOfTried: 0,
357
- executionResults: [],
358
- data: {
359
- object: {
360
- specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.AgentId,
361
- agent: { id: params.id },
362
- project: { id: params.project.id },
363
- typeOf: transactionType
364
- }
365
- }
366
- };
367
- });
368
- await repos.task.saveMany(deleteTransactionTasks, { emitImmediately: true });
369
- };
370
- }
371
- function deleteOwnershipInfosById(params) {
372
- return async (repos) => {
373
- // まず所有権削除
374
- await repos.ownershipInfo.deleteByOwnedById({
375
- project: { id: params.project.id },
376
- ownedBy: { id: params.id }
377
- });
378
- };
379
- }
380
- // async function sleep(waitTime: number): Promise<void> {
381
- // return new Promise<void>((resolve) => {
382
- // setTimeout(
383
- // () => {
384
- // resolve();
385
- // },
386
- // waitTime
387
- // );
388
- // });
389
- // }
390
- // const DELETE_CREDIT_CARD_MAX_RETRY_COUNT = 2;
391
- // const DELETE_CREDIT_CARD_RETRY_INTERVAL_IN_MS = 1000;
392
- // function deleteCreditCardsById(
393
- // params: {
394
- // id: string;
395
- // useUsernameAsGMOMemberId: boolean;
396
- // },
397
- // setting: Pick<ISetting, 'userPoolIdOld'>
398
- // ) {
399
- // return async (
400
- // repos: {
401
- // person: PersonRepo;
402
- // creditCard: CreditCardRepo;
403
- // cognitoIdentityServiceProvider: CognitoIdentityServiceProvider;
404
- // }
405
- // ) => {
406
- // let retry = true;
407
- // let numberOfTry = 0;
408
- // while (numberOfTry >= 0) {
409
- // try {
410
- // numberOfTry += 1;
411
- // if (numberOfTry > DELETE_CREDIT_CARD_MAX_RETRY_COUNT) {
412
- // retry = false;
413
- // }
414
- // // retryInterval
415
- // if (numberOfTry > 1) {
416
- // await sleep(DELETE_CREDIT_CARD_RETRY_INTERVAL_IN_MS * (numberOfTry - 1));
417
- // }
418
- // // クレジットカード削除
419
- // if (params.useUsernameAsGMOMemberId) {
420
- // const person = await repos.person.findById({ userId: params.id });
421
- // let oldUsername: string | undefined;
422
- // try {
423
- // oldUsername = await person2username(
424
- // person, repos.cognitoIdentityServiceProvider,
425
- // // settings
426
- // setting
427
- // );
428
- // } catch (error) {
429
- // let throwsPerson2usernameError = true;
430
- // // oldUserが存在しないケースをハンドル
431
- // if (error instanceof factory.errors.NotFound && error.entityName === 'User') {
432
- // debug(
433
- // 'task:deletePerson:deleteById: deleteCreditCardsById oldUsername not found',
434
- // 'personId:', params.id,
435
- // 'numberOfTry:', numberOfTry
436
- // );
437
- // throwsPerson2usernameError = false;
438
- // }
439
- // if (throwsPerson2usernameError) {
440
- // throw error;
441
- // }
442
- // }
443
- // if (typeof oldUsername === 'string') {
444
- // debug(
445
- // 'task:deletePerson:deleteById: deleteCreditCardsById processing... oldUsername:', oldUsername,
446
- // 'personId:', params.id,
447
- // 'numberOfTry:', numberOfTry
448
- // );
449
- // await repos.creditCard.deleteAll({ personId: oldUsername });
450
- // }
451
- // } else {
452
- // await repos.creditCard.deleteAll({ personId: params.id });
453
- // }
454
- // debug('task:deletePerson:deleteById: deleteCreditCardsById processed. personId:', params.id, 'numberOfTry:', numberOfTry);
455
- // break;
456
- // } catch (error) {
457
- // if (retry) {
458
- // continue;
459
- // } else {
460
- // throw error;
461
- // }
462
- // }
463
- // }
464
- // };
465
- // }