@chevre/domain 24.0.0-alpha.83 → 24.0.0-alpha.84

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 (49) hide show
  1. package/lib/chevre/repo/product.js +0 -3
  2. package/lib/chevre/repo/transaction.d.ts +4 -4
  3. package/lib/chevre/repository.d.ts +0 -25
  4. package/lib/chevre/repository.js +2 -57
  5. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +1 -19
  6. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre/requestedProgramMembershipUsed2permit.js +1 -31
  7. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.js +1 -5
  8. package/lib/chevre/service/task/deletePerson.js +0 -2
  9. package/lib/chevre/service/task/onResourceDeleted.js +0 -3
  10. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +4 -4
  11. package/lib/chevre/service.d.ts +0 -12
  12. package/lib/chevre/service.js +1 -35
  13. package/package.json +2 -2
  14. package/lib/chevre/factory/availableProductTypes.d.ts +0 -1
  15. package/lib/chevre/factory/availableProductTypes.js +0 -8
  16. package/lib/chevre/repo/account.d.ts +0 -129
  17. package/lib/chevre/repo/account.js +0 -391
  18. package/lib/chevre/repo/accountTransaction.d.ts +0 -65
  19. package/lib/chevre/repo/accountTransaction.js +0 -277
  20. package/lib/chevre/repo/mongoose/schemas/account.d.ts +0 -11
  21. package/lib/chevre/repo/mongoose/schemas/account.js +0 -118
  22. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +0 -11
  23. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +0 -149
  24. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +0 -11
  25. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +0 -144
  26. package/lib/chevre/repo/permit.d.ts +0 -42
  27. package/lib/chevre/repo/permit.js +0 -77
  28. package/lib/chevre/repo/serviceOutput.d.ts +0 -36
  29. package/lib/chevre/repo/serviceOutput.js +0 -167
  30. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -18
  31. package/lib/chevre/repo/serviceOutputIdentifier.js +0 -74
  32. package/lib/chevre/service/account.d.ts +0 -59
  33. package/lib/chevre/service/account.js +0 -108
  34. package/lib/chevre/service/accountTransaction/deposit.d.ts +0 -14
  35. package/lib/chevre/service/accountTransaction/deposit.js +0 -57
  36. package/lib/chevre/service/accountTransaction/factory.d.ts +0 -10
  37. package/lib/chevre/service/accountTransaction/factory.js +0 -101
  38. package/lib/chevre/service/accountTransaction/transfer.d.ts +0 -14
  39. package/lib/chevre/service/accountTransaction/transfer.js +0 -87
  40. package/lib/chevre/service/accountTransaction/withdraw.d.ts +0 -14
  41. package/lib/chevre/service/accountTransaction/withdraw.js +0 -68
  42. package/lib/chevre/service/accountTransaction.d.ts +0 -20
  43. package/lib/chevre/service/accountTransaction.js +0 -81
  44. package/lib/chevre/service/permit.d.ts +0 -45
  45. package/lib/chevre/service/permit.js +0 -158
  46. package/lib/chevre/service/product.d.ts +0 -9
  47. package/lib/chevre/service/product.js +0 -77
  48. package/lib/chevre/service/task/registerService.d.ts +0 -6
  49. package/lib/chevre/service/task/registerService.js +0 -22
@@ -1,391 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountRepo = void 0;
4
- const account_1 = require("./mongoose/schemas/account");
5
- const factory_1 = require("../factory");
6
- const settings_1 = require("../settings");
7
- /**
8
- * 口座リポジトリ
9
- */
10
- class AccountRepo {
11
- accountModel;
12
- constructor(connection) {
13
- this.accountModel = connection.model(account_1.modelName, (0, account_1.createSchema)());
14
- }
15
- static CREATE_MONGO_CONDITIONS(params) {
16
- const andConditions = [];
17
- const accountTypeEq = params.accountType;
18
- /* istanbul ignore else */
19
- if (typeof accountTypeEq === 'string') {
20
- andConditions.push({
21
- accountType: accountTypeEq
22
- });
23
- }
24
- /* istanbul ignore else */
25
- if (params.project !== undefined && params.project !== null) {
26
- /* istanbul ignore else */
27
- if (params.project.id !== undefined && params.project.id !== null) {
28
- /* istanbul ignore else */
29
- if (typeof params.project.id.$eq === 'string') {
30
- andConditions.push({
31
- 'project.id': {
32
- $eq: params.project.id.$eq
33
- }
34
- });
35
- }
36
- /* istanbul ignore else */
37
- if (typeof params.project.id.$ne === 'string') {
38
- andConditions.push({
39
- 'project.id': {
40
- $ne: params.project.id.$ne
41
- }
42
- });
43
- }
44
- }
45
- }
46
- const accountNumberEq = params.accountNumber?.$eq;
47
- /* istanbul ignore else */
48
- if (typeof accountNumberEq === 'string') {
49
- andConditions.push({
50
- accountNumber: { $eq: accountNumberEq }
51
- });
52
- }
53
- const accountNumberIn = params.accountNumber?.$in;
54
- /* istanbul ignore else */
55
- if (Array.isArray(accountNumberIn)) {
56
- andConditions.push({
57
- accountNumber: { $in: accountNumberIn }
58
- });
59
- }
60
- const accountNumberRegex = params.accountNumber?.$regex;
61
- /* istanbul ignore else */
62
- if (typeof accountNumberRegex === 'string' && accountNumberRegex.length > 0) {
63
- andConditions.push({
64
- accountNumber: { $regex: new RegExp(accountNumberRegex) }
65
- });
66
- }
67
- /* istanbul ignore else */
68
- if (Array.isArray(params.accountNumbers) && params.accountNumbers.length > 0) {
69
- andConditions.push({
70
- accountNumber: { $in: params.accountNumbers }
71
- });
72
- }
73
- /* istanbul ignore else */
74
- // if (Array.isArray(params.statuses) && params.statuses.length > 0) {
75
- // andConditions.push({
76
- // status: { $in: params.statuses }
77
- // });
78
- // }
79
- const nameRegex = params.name?.$regex;
80
- /* istanbul ignore else */
81
- if (typeof nameRegex === 'string' && nameRegex.length > 0) {
82
- andConditions.push({
83
- name: { $regex: new RegExp(nameRegex) }
84
- });
85
- }
86
- /* istanbul ignore if */
87
- if (typeof params.name === 'string') {
88
- andConditions.push({
89
- name: new RegExp(params.name)
90
- });
91
- }
92
- const openDateGte = params.openDate?.$gte;
93
- /* istanbul ignore else */
94
- if (openDateGte instanceof Date) {
95
- andConditions.push({
96
- openDate: { $gte: openDateGte }
97
- });
98
- }
99
- const openDateLte = params.openDate?.$lte;
100
- /* istanbul ignore else */
101
- if (openDateLte instanceof Date) {
102
- andConditions.push({
103
- openDate: { $lte: openDateLte }
104
- });
105
- }
106
- const typeOfEq = params.typeOf?.$eq;
107
- if (typeof typeOfEq === 'string') {
108
- andConditions.push({
109
- typeOf: { $eq: typeOfEq }
110
- });
111
- }
112
- const typeOfIn = params.typeOf?.$in;
113
- if (Array.isArray(typeOfIn)) {
114
- andConditions.push({
115
- typeOf: { $in: typeOfIn }
116
- });
117
- }
118
- return andConditions;
119
- }
120
- /**
121
- * 口座を開設する
122
- */
123
- async open(params) {
124
- if (params.length > 0) {
125
- const accounts = params.map((p) => {
126
- return {
127
- project: { typeOf: factory_1.factory.organizationType.Project, id: p.project.id },
128
- typeOf: factory_1.factory.accountType.Account,
129
- accountType: p.accountType,
130
- accountNumber: p.accountNumber,
131
- name: p.name,
132
- balance: p.initialBalance,
133
- availableBalance: p.initialBalance,
134
- pendingTransactions: [],
135
- openDate: p.openDate
136
- };
137
- });
138
- const result = await this.accountModel.insertMany(accounts, { ordered: false, rawResult: true });
139
- if (result.insertedCount !== accounts.length) {
140
- throw new factory_1.factory.errors.Internal('all accounts not saved');
141
- }
142
- // return result.ops;
143
- return accounts;
144
- }
145
- else {
146
- return [];
147
- }
148
- }
149
- /**
150
- * 口座を解約する
151
- */
152
- // public async close(params: {
153
- // /**
154
- // * 口座番号
155
- // */
156
- // accountNumber: string;
157
- // /**
158
- // * 解約日時
159
- // */
160
- // closeDate: Date;
161
- // }) {
162
- // const doc = await this.accountModel.findOneAndUpdate(
163
- // {
164
- // accountNumber: params.accountNumber,
165
- // pendingTransactions: { $size: 0 },
166
- // status: factory.account.AccountStatusType.Opened
167
- // },
168
- // {
169
- // closeDate: params.closeDate,
170
- // status: factory.account.AccountStatusType.Closed
171
- // },
172
- // {
173
- // new: true
174
- // }
175
- // )
176
- // .exec();
177
- // // NotFoundであれば口座状態確認
178
- // if (doc === null) {
179
- // const account = await this.findByAccountNumber({
180
- // accountNumber: params.accountNumber
181
- // });
182
- // if (account.status === factory.account.AccountStatusType.Closed) {
183
- // // すでに口座解約済の場合
184
- // return;
185
- // } else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
186
- // // 進行中取引が存在する場合の場合
187
- // throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
188
- // } else {
189
- // throw new factory.errors.NotFound(this.accountModel.modelName);
190
- // }
191
- // }
192
- // }
193
- /**
194
- * 口座番号で検索する
195
- */
196
- async findByAccountNumber(params) {
197
- const doc = await this.accountModel.findOne({
198
- accountNumber: params.accountNumber
199
- })
200
- .exec();
201
- if (doc === null) {
202
- throw new factory_1.factory.errors.NotFound(this.accountModel.modelName);
203
- }
204
- return doc.toObject();
205
- }
206
- /**
207
- * 金額を確保する
208
- * https://en.wikipedia.org/wiki/Authorization_hold
209
- */
210
- async authorizeAmount(params) {
211
- const doc = await this.accountModel.findOneAndUpdate({
212
- accountNumber: params.accountNumber,
213
- // status: factory.account.AccountStatusType.Opened, // 開いている口座
214
- ...(params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
215
- }, {
216
- $inc: { availableBalance: -params.amount }, // 残高を減らす
217
- $push: { pendingTransactions: params.transaction } // 進行中取引追加
218
- }, { new: true })
219
- .exec();
220
- // NotFoundであれば口座状態確認
221
- if (doc === null) {
222
- const account = await this.findByAccountNumber({
223
- accountNumber: params.accountNumber
224
- });
225
- // if (account.status === factory.account.AccountStatusType.Closed) {
226
- // // 口座解約済の場合
227
- // throw new factory.errors.Argument('accountNumber', 'Account already closed');
228
- // } else
229
- if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
230
- // 残高不足の場合
231
- throw new factory_1.factory.errors.Argument('accountNumber', 'Insufficient balance');
232
- }
233
- else {
234
- throw new factory_1.factory.errors.NotFound(this.accountModel.modelName);
235
- }
236
- }
237
- }
238
- /**
239
- * 取引を開始する
240
- */
241
- async startTransaction(params) {
242
- const doc = await this.accountModel.findOneAndUpdate({
243
- accountNumber: params.accountNumber
244
- // status: factory.account.AccountStatusType.Opened // 開いている口座
245
- }, { $push: { pendingTransactions: params.transaction } })
246
- .exec();
247
- // NotFoundであれば口座状態確認
248
- if (doc === null) {
249
- // const account = await this.findByAccountNumber({
250
- // accountNumber: params.accountNumber
251
- // });
252
- // if (account.status === factory.account.AccountStatusType.Closed) {
253
- // // 口座解約済の場合
254
- // throw new factory.errors.Argument('accountNumber', 'Account already closed');
255
- // } else {
256
- // throw new factory.errors.NotFound(this.accountModel.modelName);
257
- // }
258
- throw new factory_1.factory.errors.NotFound(this.accountModel.modelName);
259
- }
260
- }
261
- /**
262
- * 決済処理を実行する
263
- * 口座上で進行中の取引について、実際に金額移動処理を実行します。
264
- */
265
- async settleTransaction(params) {
266
- // 転送元があれば残高調整
267
- if (params.fromAccountNumber !== undefined) {
268
- await this.accountModel.findOneAndUpdate({
269
- accountNumber: params.fromAccountNumber,
270
- 'pendingTransactions.id': params.transactionId
271
- }, {
272
- $inc: {
273
- balance: -params.amount // 残高調整
274
- },
275
- $pull: { pendingTransactions: { id: params.transactionId } }
276
- })
277
- .exec();
278
- }
279
- // 転送先へがあれば入金
280
- if (params.toAccountNumber !== undefined) {
281
- await this.accountModel.findOneAndUpdate({
282
- accountNumber: params.toAccountNumber,
283
- 'pendingTransactions.id': params.transactionId
284
- }, {
285
- $inc: {
286
- balance: params.amount,
287
- availableBalance: params.amount
288
- },
289
- $pull: { pendingTransactions: { id: params.transactionId } }
290
- })
291
- .exec();
292
- }
293
- }
294
- /**
295
- * 取引を取り消す
296
- * 口座上で進行中の取引を中止します。
297
- * https://www.investopedia.com/terms/v/void-transaction.asp
298
- */
299
- async voidTransaction(params) {
300
- // 転送元があればhold解除
301
- if (params.fromAccountNumber !== undefined) {
302
- await this.accountModel.findOneAndUpdate({
303
- accountNumber: params.fromAccountNumber,
304
- 'pendingTransactions.id': params.transactionId
305
- }, {
306
- $inc: {
307
- availableBalance: params.amount // 残高調整
308
- },
309
- $pull: { pendingTransactions: { id: params.transactionId } }
310
- })
311
- .exec();
312
- }
313
- // 転送先へがあれば進行中取引削除
314
- if (params.toAccountNumber !== undefined) {
315
- await this.accountModel.findOneAndUpdate({
316
- accountNumber: params.toAccountNumber,
317
- 'pendingTransactions.id': params.transactionId
318
- }, {
319
- $pull: { pendingTransactions: { id: params.transactionId } }
320
- })
321
- .exec();
322
- }
323
- }
324
- /**
325
- * 通貨転送返金
326
- */
327
- async returnTransaction(params) {
328
- if (params.fromAccountNumber !== undefined) {
329
- await this.accountModel.findOneAndUpdate({
330
- accountNumber: params.fromAccountNumber,
331
- 'retunedTransaction.id': { $ne: params.transactionId }
332
- }, {
333
- $inc: {
334
- balance: params.amount,
335
- availableBalance: params.amount
336
- },
337
- $push: { retunedTransaction: { id: params.transactionId } }
338
- })
339
- .exec();
340
- }
341
- if (params.toAccountNumber !== undefined) {
342
- await this.accountModel.findOneAndUpdate({
343
- accountNumber: params.toAccountNumber,
344
- 'retunedTransaction.id': { $ne: params.transactionId }
345
- }, {
346
- $inc: {
347
- balance: -params.amount,
348
- availableBalance: -params.amount
349
- },
350
- $push: { retunedTransaction: { id: params.transactionId } }
351
- })
352
- .exec();
353
- }
354
- }
355
- async count(params) {
356
- const conditions = AccountRepo.CREATE_MONGO_CONDITIONS(params);
357
- return this.accountModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
358
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
359
- .exec();
360
- }
361
- /**
362
- * 口座を検索する
363
- */
364
- async search(params) {
365
- const conditions = AccountRepo.CREATE_MONGO_CONDITIONS(params);
366
- const query = this.accountModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
367
- __v: 0,
368
- createdAt: 0,
369
- updatedAt: 0,
370
- pendingTransactions: 0
371
- });
372
- /* istanbul ignore else */
373
- if (typeof params.limit === 'number' && params.limit > 0) {
374
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
375
- query.limit(params.limit)
376
- .skip(params.limit * (page - 1));
377
- }
378
- /* istanbul ignore else */
379
- if (params.sort?.openDate !== undefined) {
380
- query.sort({ openDate: params.sort.openDate });
381
- }
382
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
383
- .exec()
384
- .then((docs) => docs.map((doc) => doc.toObject()));
385
- }
386
- async unsetUnnecessaryFields(params) {
387
- return this.accountModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
388
- .exec();
389
- }
390
- }
391
- exports.AccountRepo = AccountRepo;
@@ -1,65 +0,0 @@
1
- import type { Connection } from 'mongoose';
2
- import { factory } from '../factory';
3
- /**
4
- * 口座取引リポジトリ
5
- */
6
- export declare class AccountTransactionRepo {
7
- private readonly transactionModel;
8
- constructor(connection: Connection);
9
- static CREATE_MONGO_CONDITIONS(params: factory.account.transaction.ISearchConditions): any[];
10
- /**
11
- * 取引を開始する
12
- */
13
- start<T extends factory.account.transactionType>(params: factory.account.transaction.IStartParams<T>): Promise<factory.account.transaction.ITransaction<T>>;
14
- startByIdentifier<T extends factory.account.transactionType>(params: factory.account.transaction.IStartParams<T>): Promise<factory.account.transaction.ITransaction<T>>;
15
- /**
16
- * 取引検索
17
- */
18
- findById<T extends factory.account.transactionType>(params: {
19
- typeOf?: T;
20
- /**
21
- * 取引ID
22
- */
23
- id: string;
24
- }): Promise<factory.account.transaction.ITransaction<T>>;
25
- findByTransactionNumber<T extends factory.account.transactionType>(params: {
26
- typeOf?: T;
27
- transactionNumber: string;
28
- }): Promise<factory.account.transaction.ITransaction<T>>;
29
- /**
30
- * 取引を確定する
31
- */
32
- confirm<T extends factory.account.transactionType>(params: {
33
- typeOf?: T;
34
- id: string;
35
- potentialActions: factory.account.transaction.IPotentialActions;
36
- }): Promise<factory.account.transaction.ITransaction<T>>;
37
- /**
38
- * 取引を中止する
39
- */
40
- cancel<T extends factory.account.transactionType>(params: {
41
- typeOf?: T;
42
- id?: string;
43
- transactionNumber?: string;
44
- }): Promise<factory.account.transaction.ITransaction<T>>;
45
- /**
46
- * 取引を期限切れにする
47
- */
48
- makeExpired(params: {
49
- expires: {
50
- $lt: Date;
51
- };
52
- }): Promise<void>;
53
- /**
54
- * 取引を検索する
55
- */
56
- search(params: factory.account.transaction.ISearchConditions): Promise<factory.account.transaction.ITransaction<factory.account.transactionType>[]>;
57
- clean(params: {
58
- project?: {
59
- id?: string;
60
- };
61
- endDate: {
62
- $lt: Date;
63
- };
64
- }): Promise<void>;
65
- }