@chevre/domain 26.0.0-alpha.26 → 26.0.0-alpha.28
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.
- package/lib/chevre/repo/action.d.ts +1 -1
- package/lib/chevre/repo/action.js +0 -260
- package/lib/chevre/repo/adminTransaction.d.ts +131 -0
- package/lib/chevre/repo/adminTransaction.js +237 -0
- package/lib/chevre/repo/aggregateTransaction.d.ts +39 -0
- package/lib/chevre/repo/aggregateTransaction.js +166 -0
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +8 -9
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +85 -76
- package/lib/chevre/repo/mongoose/schemas/event.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/eventOffer.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/pendingReservation.js +11 -4
- package/lib/chevre/repo/mongoose/schemas/{ownershipInfo.d.ts → updateAction.d.ts} +5 -3
- package/lib/chevre/repo/mongoose/schemas/updateAction.js +65 -0
- package/lib/chevre/repo/transaction.d.ts +1 -187
- package/lib/chevre/repo/transaction.js +2 -383
- package/lib/chevre/repo/updateAction.d.ts +52 -0
- package/lib/chevre/repo/updateAction.js +429 -0
- package/lib/chevre/repository.d.ts +15 -5
- package/lib/chevre/repository.js +35 -13
- package/lib/chevre/service/aggregation/system.d.ts +2 -2
- package/lib/chevre/service/aggregation/system.js +2 -2
- package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +2 -2
- package/lib/chevre/service/event/processUpdateMovieTheater.js +3 -3
- package/lib/chevre/service/event.d.ts +2 -2
- package/lib/chevre/service/event.js +3 -3
- package/lib/chevre/service/task/deleteTransaction.js +2 -4
- package/lib/chevre/service/task/importEventsFromCOA.js +2 -2
- package/lib/chevre/service/task/syncResourcesFromCOA.js +11 -11
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -2
- package/lib/chevre/service/transaction/deleteTransaction.js +2 -2
- package/package.json +2 -2
- package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +0 -82
- package/lib/chevre/repo/ownershipInfo.d.ts +0 -20
- package/lib/chevre/repo/ownershipInfo.js +0 -130
|
@@ -7,7 +7,7 @@ export { ICancelActionAction };
|
|
|
7
7
|
/**
|
|
8
8
|
* 汎用アクションリポジトリで開始可能なアクションタイプ
|
|
9
9
|
*/
|
|
10
|
-
type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction>;
|
|
10
|
+
type StartableActionType = Exclude<factory.actionType, factory.actionType.AcceptAction | factory.actionType.CheckAction | factory.actionType.AuthorizeAction | factory.actionType.PayAction | factory.actionType.RefundAction | factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction>;
|
|
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
12
|
export interface IDeleteActionResult {
|
|
13
13
|
identifier: string;
|
|
@@ -6,277 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ActionRepo = void 0;
|
|
7
7
|
const moment_1 = __importDefault(require("moment"));
|
|
8
8
|
const factory_1 = require("../factory");
|
|
9
|
-
// import { createSchema as createRecipeSchema, IModel as IActionRecipeModel, modelName as recipeModelName } from './mongoose/schemas/actionRecipe';
|
|
10
9
|
const actionProcess_1 = require("./action/actionProcess");
|
|
11
10
|
/**
|
|
12
11
|
* アクションリポジトリ
|
|
13
12
|
*/
|
|
14
13
|
class ActionRepo extends actionProcess_1.ActionProcessRepo {
|
|
15
|
-
// private readonly actionModel: IActionModel;
|
|
16
|
-
// private readonly actionRecipeModel: IActionRecipeModel;
|
|
17
|
-
// constructor(connection: Connection) {
|
|
18
|
-
// this.actionModel = connection.model(modelName, createSchema());
|
|
19
|
-
// this.actionRecipeModel = connection.model(recipeModelName, createRecipeSchema());
|
|
20
|
-
// }
|
|
21
14
|
/**
|
|
22
15
|
* 汎用アクション検索
|
|
23
16
|
*/
|
|
24
17
|
async findActionsByType(params, inclusion) {
|
|
25
18
|
return (this.findAnyActions(params, inclusion));
|
|
26
19
|
}
|
|
27
|
-
// /**
|
|
28
|
-
// * アクション開始
|
|
29
|
-
// */
|
|
30
|
-
// public async start<T extends factory.actionType>(
|
|
31
|
-
// attributes: factory.action.IAttributes<T, any, any>,
|
|
32
|
-
// options?: {
|
|
33
|
-
// recipe?: IRecipeAsActionAttributes;
|
|
34
|
-
// }
|
|
35
|
-
// ): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>> {
|
|
36
|
-
// const startDate = new Date();
|
|
37
|
-
// const creatingAction: Omit<factory.action.IAction<factory.action.IAttributes<T, any, any>>, 'id'> = {
|
|
38
|
-
// ...attributes,
|
|
39
|
-
// actionStatus: factory.actionStatusType.ActiveActionStatus,
|
|
40
|
-
// startDate
|
|
41
|
-
// };s
|
|
42
|
-
// // reimplemnt with insertMany(2024-08-29~)
|
|
43
|
-
// const result = await this.actionModel.insertMany(creatingAction, { rawResult: true });
|
|
44
|
-
// const id = result.insertedIds?.[0]?.toHexString();
|
|
45
|
-
// if (typeof id !== 'string') {
|
|
46
|
-
// throw new factory.errors.Internal('action not saved');
|
|
47
|
-
// }
|
|
48
|
-
// // add recipe(2024-06-09~)
|
|
49
|
-
// const savingRecipe = options?.recipe;
|
|
50
|
-
// if (savingRecipe?.typeOf === 'Recipe') {
|
|
51
|
-
// await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf } });
|
|
52
|
-
// }
|
|
53
|
-
// return { id, startDate, typeOf: creatingAction.typeOf };
|
|
54
|
-
// }
|
|
55
|
-
// public async completeWithVoid(params: {
|
|
56
|
-
// typeOf: factory.actionType;
|
|
57
|
-
// id: string;
|
|
58
|
-
// result: any;
|
|
59
|
-
// recipe?: IRecipeAsActionAttributes;
|
|
60
|
-
// }): Promise<void> {
|
|
61
|
-
// if (params.recipe?.typeOf === 'Recipe') {
|
|
62
|
-
// await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
|
|
63
|
-
// }
|
|
64
|
-
// const doc = await this.actionModel.findOneAndUpdate(
|
|
65
|
-
// {
|
|
66
|
-
// _id: { $eq: params.id },
|
|
67
|
-
// typeOf: { $eq: params.typeOf }
|
|
68
|
-
// },
|
|
69
|
-
// {
|
|
70
|
-
// $set: {
|
|
71
|
-
// actionStatus: factory.actionStatusType.CompletedActionStatus,
|
|
72
|
-
// result: params.result,
|
|
73
|
-
// endDate: new Date()
|
|
74
|
-
// }
|
|
75
|
-
// },
|
|
76
|
-
// { new: false, projection: { _id: 1 } }
|
|
77
|
-
// )
|
|
78
|
-
// .lean<{ _id: ObjectId }>()
|
|
79
|
-
// .exec();
|
|
80
|
-
// if (doc === null) {
|
|
81
|
-
// throw new factory.errors.NotFound(this.actionModel.modelName);
|
|
82
|
-
// }
|
|
83
|
-
// }
|
|
84
|
-
// /**
|
|
85
|
-
// * アクション取消
|
|
86
|
-
// */
|
|
87
|
-
// public async cancelWithVoid(params: {
|
|
88
|
-
// typeOf: factory.actionType.AcceptAction | factory.actionType.AuthorizeAction; // 現時点でAcceptAction,AuthorizeActionのみ対応
|
|
89
|
-
// id: string;
|
|
90
|
-
// cancelAction?: Pick<ICancelActionAction, 'agent' | 'sameAs' | 'startTime'>;
|
|
91
|
-
// }): Promise<void> {
|
|
92
|
-
// const cancelDate = new Date();
|
|
93
|
-
// const cancelAction: ICancelActionAction | undefined = (params.cancelAction !== undefined)
|
|
94
|
-
// ? {
|
|
95
|
-
// ...params.cancelAction,
|
|
96
|
-
// endTime: cancelDate,
|
|
97
|
-
// typeOf: factory.actionType.CancelAction
|
|
98
|
-
// }
|
|
99
|
-
// : undefined;
|
|
100
|
-
// const doc = await this.actionModel.findOneAndUpdate(
|
|
101
|
-
// {
|
|
102
|
-
// _id: { $eq: params.id },
|
|
103
|
-
// typeOf: { $eq: params.typeOf },
|
|
104
|
-
// actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
|
|
105
|
-
// },
|
|
106
|
-
// {
|
|
107
|
-
// $set: {
|
|
108
|
-
// actionStatus: factory.actionStatusType.CanceledActionStatus,
|
|
109
|
-
// ...(cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
|
|
110
|
-
// }
|
|
111
|
-
// },
|
|
112
|
-
// { new: false, projection: { _id: 1 } }
|
|
113
|
-
// )
|
|
114
|
-
// .lean<{ _id: ObjectId }>()
|
|
115
|
-
// .exec();
|
|
116
|
-
// if (doc === null) {
|
|
117
|
-
// // 既にCanceledActionStatusであればok
|
|
118
|
-
// const existingAction = <Pick<IAction<typeof params.typeOf>, 'actionStatus'>>
|
|
119
|
-
// await this.findById({ id: params.id, typeOf: params.typeOf }, ['actionStatus'], []);
|
|
120
|
-
// if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
|
|
121
|
-
// throw new factory.errors.NotFound(this.actionModel.modelName);
|
|
122
|
-
// }
|
|
123
|
-
// }
|
|
124
|
-
// // endDateが存在しなければセット(2024-04-22~)
|
|
125
|
-
// await this.actionModel.updateOne(
|
|
126
|
-
// {
|
|
127
|
-
// _id: { $eq: params.id },
|
|
128
|
-
// endDate: { $exists: false }
|
|
129
|
-
// },
|
|
130
|
-
// { $set: { endDate: cancelDate } }
|
|
131
|
-
// )
|
|
132
|
-
// .exec();
|
|
133
|
-
// }
|
|
134
|
-
// /**
|
|
135
|
-
// * アクション失敗
|
|
136
|
-
// */
|
|
137
|
-
// public async giveUp(params: {
|
|
138
|
-
// typeOf: factory.actionType;
|
|
139
|
-
// id: string;
|
|
140
|
-
// error: Error | Error[];
|
|
141
|
-
// recipe?: IRecipeAsActionAttributes;
|
|
142
|
-
// }): Promise<void> {
|
|
143
|
-
// const actionError: IActionError | IActionError[] = (Array.isArray(params.error))
|
|
144
|
-
// ? params.error.map((e) => ({ ...e, message: e.message, name: e.name }))
|
|
145
|
-
// : { ...params.error, message: params.error.message, name: params.error.name };
|
|
146
|
-
// if (params.recipe?.typeOf === 'Recipe') {
|
|
147
|
-
// await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
|
|
148
|
-
// }
|
|
149
|
-
// const doc = await this.actionModel.findOneAndUpdate(
|
|
150
|
-
// {
|
|
151
|
-
// typeOf: { $eq: params.typeOf },
|
|
152
|
-
// _id: { $eq: params.id }
|
|
153
|
-
// },
|
|
154
|
-
// {
|
|
155
|
-
// $set: {
|
|
156
|
-
// actionStatus: factory.actionStatusType.FailedActionStatus,
|
|
157
|
-
// error: actionError,
|
|
158
|
-
// endDate: new Date()
|
|
159
|
-
// }
|
|
160
|
-
// },
|
|
161
|
-
// { new: true, projection: { _id: 1 } }
|
|
162
|
-
// )
|
|
163
|
-
// .lean<{ _id: ObjectId }>()
|
|
164
|
-
// .exec();
|
|
165
|
-
// if (doc === null) {
|
|
166
|
-
// throw new factory.errors.NotFound(this.actionModel.modelName);
|
|
167
|
-
// }
|
|
168
|
-
// }
|
|
169
|
-
// /**
|
|
170
|
-
// * アクション再開
|
|
171
|
-
// */
|
|
172
|
-
// public async reStart(params: {
|
|
173
|
-
// typeOf: factory.actionType;
|
|
174
|
-
// id: string;
|
|
175
|
-
// recipe?: IRecipeAsActionAttributes;
|
|
176
|
-
// }): Promise<void> {
|
|
177
|
-
// const doc = await this.actionModel.findOneAndUpdate(
|
|
178
|
-
// {
|
|
179
|
-
// _id: { $eq: params.id },
|
|
180
|
-
// typeOf: { $eq: params.typeOf },
|
|
181
|
-
// actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
|
|
182
|
-
// },
|
|
183
|
-
// {
|
|
184
|
-
// $set: {
|
|
185
|
-
// actionStatus: factory.actionStatusType.ActiveActionStatus,
|
|
186
|
-
// startDate: new Date()
|
|
187
|
-
// },
|
|
188
|
-
// $unset: { endDate: 1 }
|
|
189
|
-
// },
|
|
190
|
-
// { new: false, projection: { _id: 1 } }
|
|
191
|
-
// )
|
|
192
|
-
// .lean<{ _id: ObjectId }>()
|
|
193
|
-
// .exec();
|
|
194
|
-
// if (doc === null) {
|
|
195
|
-
// throw new factory.errors.NotFound(this.actionModel.modelName);
|
|
196
|
-
// }
|
|
197
|
-
// // add recipe(2024-06-09~)
|
|
198
|
-
// if (params.recipe?.typeOf === 'Recipe') {
|
|
199
|
-
// await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// /**
|
|
203
|
-
// * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
|
|
204
|
-
// */
|
|
205
|
-
// public async giveUpStartDatePassedCertainPeriod(params: {
|
|
206
|
-
// id?: { $eq?: string };
|
|
207
|
-
// error: any;
|
|
208
|
-
// startDate: { $lt: Date };
|
|
209
|
-
// }): Promise<any> {
|
|
210
|
-
// return this.actionModel.updateMany(
|
|
211
|
-
// {
|
|
212
|
-
// actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus },
|
|
213
|
-
// // 一定期間過ぎたもの
|
|
214
|
-
// startDate: { $lt: params.startDate.$lt },
|
|
215
|
-
// ...(typeof params.id?.$eq === 'string') ? { _id: { $eq: params.id.$eq } } : undefined
|
|
216
|
-
// },
|
|
217
|
-
// {
|
|
218
|
-
// actionStatus: factory.actionStatusType.FailedActionStatus,
|
|
219
|
-
// error: params.error,
|
|
220
|
-
// endDate: new Date()
|
|
221
|
-
// }
|
|
222
|
-
// )
|
|
223
|
-
// .exec();
|
|
224
|
-
// }
|
|
225
|
-
// public async findById<T extends factory.actionType>(
|
|
226
|
-
// params: {
|
|
227
|
-
// typeOf: T;
|
|
228
|
-
// id: string;
|
|
229
|
-
// },
|
|
230
|
-
// inclusion?: IKeyOfProjection[],
|
|
231
|
-
// exclusion?: IKeyOfProjection[]
|
|
232
|
-
// ): Promise<IAction<T>> {
|
|
233
|
-
// let positiveProjectionFields: IKeyOfProjection[] = AVAILABLE_PROJECT_FIELDS;
|
|
234
|
-
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
235
|
-
// positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
236
|
-
// } else {
|
|
237
|
-
// if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
238
|
-
// positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
|
|
239
|
-
// }
|
|
240
|
-
// }
|
|
241
|
-
// const projection: ProjectionType<IAction<T>> = {
|
|
242
|
-
// _id: 0,
|
|
243
|
-
// id: { $toString: '$_id' },
|
|
244
|
-
// ...Object.fromEntries<1>(positiveProjectionFields.map((key) => ([key, 1])))
|
|
245
|
-
// };
|
|
246
|
-
// const doc = await this.actionModel.findOne(
|
|
247
|
-
// {
|
|
248
|
-
// typeOf: { $eq: params.typeOf },
|
|
249
|
-
// _id: { $eq: params.id }
|
|
250
|
-
// },
|
|
251
|
-
// projection
|
|
252
|
-
// )
|
|
253
|
-
// .lean<IAction<T>>() // 2024-08-26~
|
|
254
|
-
// .exec();
|
|
255
|
-
// if (doc === null) {
|
|
256
|
-
// throw new factory.errors.NotFound(this.actionModel.modelName);
|
|
257
|
-
// }
|
|
258
|
-
// return doc;
|
|
259
|
-
// }
|
|
260
|
-
// public async findPayAction(params: {
|
|
261
|
-
// project: { id: string };
|
|
262
|
-
// paymentMethodId: string;
|
|
263
|
-
// actionStatus?: { $in?: factory.actionStatusType[] };
|
|
264
|
-
// }): Promise<factory.action.trade.pay.IAction | undefined> {
|
|
265
|
-
// const payActions = await this.findActionsByType<factory.actionType.PayAction>(
|
|
266
|
-
// {
|
|
267
|
-
// limit: 1,
|
|
268
|
-
// page: 1,
|
|
269
|
-
// actionStatus: (Array.isArray(params.actionStatus?.$in))
|
|
270
|
-
// ? { $in: params.actionStatus?.$in }
|
|
271
|
-
// : { $in: [factory.actionStatusType.CompletedActionStatus] },
|
|
272
|
-
// project: { id: { $eq: params.project.id } },
|
|
273
|
-
// typeOf: { $eq: factory.actionType.PayAction },
|
|
274
|
-
// object: { paymentMethod: { paymentMethodId: { $eq: params.paymentMethodId } } }
|
|
275
|
-
// },
|
|
276
|
-
// []
|
|
277
|
-
// ) as factory.action.trade.pay.IAction[];
|
|
278
|
-
// return payActions.shift();
|
|
279
|
-
// }
|
|
280
20
|
/**
|
|
281
21
|
* 取引に対するアクションを検索する
|
|
282
22
|
*/
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
import { IDocType } from './mongoose/schemas/transaction';
|
|
4
|
+
/**
|
|
5
|
+
* 取引管理リポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class AdminTransactionRepo {
|
|
8
|
+
private readonly transactionModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
countPotentiallyExportTasks(params: {
|
|
11
|
+
endDate: {
|
|
12
|
+
$lt: Date;
|
|
13
|
+
};
|
|
14
|
+
limit?: number;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
count: number;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
|
|
20
|
+
* PotentialActionStatusに変更する
|
|
21
|
+
* 2025-03-10~
|
|
22
|
+
*/
|
|
23
|
+
reExportAction(params: {
|
|
24
|
+
startDate: {
|
|
25
|
+
$lt: Date;
|
|
26
|
+
};
|
|
27
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
28
|
+
/**
|
|
29
|
+
* add(2025-03-13~)
|
|
30
|
+
*/
|
|
31
|
+
countPotentiallyExpired(params: {
|
|
32
|
+
expires: {
|
|
33
|
+
$lt: Date;
|
|
34
|
+
};
|
|
35
|
+
limit?: number;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
count: number;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* add(2025-03-03~)
|
|
41
|
+
*/
|
|
42
|
+
makeOneExpiredIfExists(params: {
|
|
43
|
+
expires: {
|
|
44
|
+
$lt: Date;
|
|
45
|
+
};
|
|
46
|
+
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | undefined>;
|
|
47
|
+
findByIdAndDelete(params: {
|
|
48
|
+
id: string;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
unsetUnnecessaryFields(params: {
|
|
51
|
+
filter: any;
|
|
52
|
+
$unset: any;
|
|
53
|
+
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
54
|
+
getCursor(conditions: any, projection: any, sort?: factory.sortType): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
55
|
+
object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
|
|
56
|
+
error?: any;
|
|
57
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
58
|
+
seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
|
|
59
|
+
typeOf: factory.transactionType.PlaceOrder;
|
|
60
|
+
expires: Date;
|
|
61
|
+
result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
|
|
62
|
+
startDate: Date;
|
|
63
|
+
endDate?: Date | undefined;
|
|
64
|
+
instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
|
|
65
|
+
agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
|
|
66
|
+
status: factory.transactionStatusType;
|
|
67
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
68
|
+
potentialActions?: undefined;
|
|
69
|
+
} & {
|
|
70
|
+
_id: import("mongoose").Types.ObjectId;
|
|
71
|
+
} & {
|
|
72
|
+
__v: number;
|
|
73
|
+
}) | ({
|
|
74
|
+
object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
|
|
75
|
+
error?: any;
|
|
76
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
77
|
+
seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
|
|
78
|
+
typeOf: factory.transactionType.ReturnOrder;
|
|
79
|
+
expires: Date;
|
|
80
|
+
result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
|
|
81
|
+
startDate: Date;
|
|
82
|
+
endDate?: Date | undefined;
|
|
83
|
+
agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
|
|
84
|
+
recipient?: undefined;
|
|
85
|
+
status: factory.transactionStatusType;
|
|
86
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
87
|
+
potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
|
|
88
|
+
} & {
|
|
89
|
+
_id: import("mongoose").Types.ObjectId;
|
|
90
|
+
} & {
|
|
91
|
+
__v: number;
|
|
92
|
+
})), import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & (({
|
|
93
|
+
object: import("@chevre/factory/lib/chevre/transaction/placeOrder").IObject;
|
|
94
|
+
error?: any;
|
|
95
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
96
|
+
seller: import("@chevre/factory/lib/chevre/transaction/placeOrder").ISeller;
|
|
97
|
+
typeOf: factory.transactionType.PlaceOrder;
|
|
98
|
+
expires: Date;
|
|
99
|
+
result?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IResult | undefined;
|
|
100
|
+
startDate: Date;
|
|
101
|
+
endDate?: Date | undefined;
|
|
102
|
+
instrument?: import("@chevre/factory/lib/chevre/transaction/placeOrder").IInstrument | undefined;
|
|
103
|
+
agent: import("@chevre/factory/lib/chevre/transaction/placeOrder").IAgent;
|
|
104
|
+
status: factory.transactionStatusType;
|
|
105
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
106
|
+
potentialActions?: undefined;
|
|
107
|
+
} & {
|
|
108
|
+
_id: import("mongoose").Types.ObjectId;
|
|
109
|
+
} & {
|
|
110
|
+
__v: number;
|
|
111
|
+
}) | ({
|
|
112
|
+
object: import("@chevre/factory/lib/chevre/transaction/returnOrder").IObject;
|
|
113
|
+
error?: any;
|
|
114
|
+
project: import("@chevre/factory/lib/chevre/transaction").IProject;
|
|
115
|
+
seller: import("@chevre/factory/lib/chevre/transaction").ISeller;
|
|
116
|
+
typeOf: factory.transactionType.ReturnOrder;
|
|
117
|
+
expires: Date;
|
|
118
|
+
result?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined;
|
|
119
|
+
startDate: Date;
|
|
120
|
+
endDate?: Date | undefined;
|
|
121
|
+
agent: import("@chevre/factory/lib/chevre/transaction").IAgent;
|
|
122
|
+
recipient?: undefined;
|
|
123
|
+
status: factory.transactionStatusType;
|
|
124
|
+
tasksExportAction?: import("@chevre/factory/lib/chevre/transaction").ITasksExportAction | undefined;
|
|
125
|
+
potentialActions?: import("@chevre/factory/lib/chevre/transaction/returnOrder").IPotentialActions | undefined;
|
|
126
|
+
} & {
|
|
127
|
+
_id: import("mongoose").Types.ObjectId;
|
|
128
|
+
} & {
|
|
129
|
+
__v: number;
|
|
130
|
+
}))) | null>;
|
|
131
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminTransactionRepo = void 0;
|
|
4
|
+
const transaction_1 = require("../eventEmitter/transaction");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
7
|
+
const transaction_2 = require("./mongoose/schemas/transaction");
|
|
8
|
+
/**
|
|
9
|
+
* 取引管理リポジトリ
|
|
10
|
+
*/
|
|
11
|
+
class AdminTransactionRepo {
|
|
12
|
+
transactionModel;
|
|
13
|
+
constructor(connection) {
|
|
14
|
+
this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
|
|
15
|
+
}
|
|
16
|
+
async countPotentiallyExportTasks(params) {
|
|
17
|
+
const { endDate, limit } = params;
|
|
18
|
+
const endDateLt = endDate?.$lt;
|
|
19
|
+
if (!(endDateLt instanceof Date)) {
|
|
20
|
+
throw new factory_1.factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
21
|
+
}
|
|
22
|
+
const query = this.transactionModel.countDocuments({
|
|
23
|
+
status: {
|
|
24
|
+
$in: [
|
|
25
|
+
factory_1.factory.transactionStatusType.Canceled,
|
|
26
|
+
factory_1.factory.transactionStatusType.Confirmed,
|
|
27
|
+
factory_1.factory.transactionStatusType.Expired
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
'tasksExportAction.actionStatus': {
|
|
31
|
+
$exists: true,
|
|
32
|
+
$eq: factory_1.factory.actionStatusType.PotentialActionStatus
|
|
33
|
+
},
|
|
34
|
+
endDate: { $exists: true, $lt: endDateLt }
|
|
35
|
+
});
|
|
36
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
37
|
+
query.limit(limit);
|
|
38
|
+
}
|
|
39
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
40
|
+
.exec();
|
|
41
|
+
return { count };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
|
|
45
|
+
* PotentialActionStatusに変更する
|
|
46
|
+
* 2025-03-10~
|
|
47
|
+
*/
|
|
48
|
+
async reExportAction(params) {
|
|
49
|
+
const { startDate } = params;
|
|
50
|
+
if (!(startDate.$lt instanceof Date)) {
|
|
51
|
+
throw new factory_1.factory.errors.Argument('startDate.$lt', 'must be Date');
|
|
52
|
+
}
|
|
53
|
+
return this.transactionModel.updateMany({
|
|
54
|
+
'tasksExportAction.actionStatus': {
|
|
55
|
+
$exists: true,
|
|
56
|
+
$eq: factory_1.factory.actionStatusType.ActiveActionStatus
|
|
57
|
+
},
|
|
58
|
+
'tasksExportAction.startDate': {
|
|
59
|
+
$exists: true,
|
|
60
|
+
$lt: startDate.$lt
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
$set: {
|
|
64
|
+
tasksExportAction: {
|
|
65
|
+
actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.exec();
|
|
70
|
+
}
|
|
71
|
+
// /**
|
|
72
|
+
// * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
|
|
73
|
+
// */
|
|
74
|
+
// public async exportTasksMany(params: {
|
|
75
|
+
// now: Date;
|
|
76
|
+
// delayInSeconds: number;
|
|
77
|
+
// status: {
|
|
78
|
+
// $in: factory.transactionStatusType[];
|
|
79
|
+
// };
|
|
80
|
+
// limit: number;
|
|
81
|
+
// }) {
|
|
82
|
+
// const delayedTransactions = await this.transactionModel.find({
|
|
83
|
+
// status: { $in: params.status.$in },
|
|
84
|
+
// 'tasksExportAction.actionStatus': {
|
|
85
|
+
// $exists: true,
|
|
86
|
+
// $eq: factory.actionStatusType.PotentialActionStatus
|
|
87
|
+
// },
|
|
88
|
+
// endDate: {
|
|
89
|
+
// $exists: true,
|
|
90
|
+
// $lt: moment(params.now)
|
|
91
|
+
// .add(-params.delayInSeconds, 'seconds')
|
|
92
|
+
// .toDate()
|
|
93
|
+
// }
|
|
94
|
+
// })
|
|
95
|
+
// .select({
|
|
96
|
+
// _id: 0,
|
|
97
|
+
// id: { $toString: '$_id' },
|
|
98
|
+
// typeOf: 1,
|
|
99
|
+
// status: 1
|
|
100
|
+
// })
|
|
101
|
+
// .limit(params.limit)
|
|
102
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
103
|
+
// .lean<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'status' | 'typeOf'>[]>()
|
|
104
|
+
// .exec();
|
|
105
|
+
// if (delayedTransactions.length > 0) {
|
|
106
|
+
// delayedTransactions.forEach((delayedTransaction) => {
|
|
107
|
+
// transactionEventEmitter.emitTransactionStatusChanged({
|
|
108
|
+
// id: delayedTransaction.id,
|
|
109
|
+
// typeOf: delayedTransaction.typeOf,
|
|
110
|
+
// status: delayedTransaction.status
|
|
111
|
+
// });
|
|
112
|
+
// });
|
|
113
|
+
// }
|
|
114
|
+
// return delayedTransactions;
|
|
115
|
+
// }
|
|
116
|
+
/**
|
|
117
|
+
* add(2025-03-13~)
|
|
118
|
+
*/
|
|
119
|
+
async countPotentiallyExpired(params) {
|
|
120
|
+
const { expires, limit } = params;
|
|
121
|
+
const query = this.transactionModel.countDocuments({
|
|
122
|
+
status: { $eq: factory_1.factory.transactionStatusType.InProgress },
|
|
123
|
+
expires: { $lt: expires.$lt }
|
|
124
|
+
});
|
|
125
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
126
|
+
query.limit(limit);
|
|
127
|
+
}
|
|
128
|
+
const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
129
|
+
.exec();
|
|
130
|
+
return { count };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* add(2025-03-03~)
|
|
134
|
+
*/
|
|
135
|
+
async makeOneExpiredIfExists(params) {
|
|
136
|
+
const endDate = new Date();
|
|
137
|
+
const sort = {
|
|
138
|
+
expires: factory_1.factory.sortType.Ascending
|
|
139
|
+
};
|
|
140
|
+
const doc = await this.transactionModel.findOneAndUpdate({
|
|
141
|
+
status: { $eq: factory_1.factory.transactionStatusType.InProgress },
|
|
142
|
+
expires: { $lt: params.expires.$lt }
|
|
143
|
+
}, {
|
|
144
|
+
status: factory_1.factory.transactionStatusType.Expired,
|
|
145
|
+
endDate
|
|
146
|
+
}, {
|
|
147
|
+
new: true,
|
|
148
|
+
projection: {
|
|
149
|
+
_id: 0,
|
|
150
|
+
id: { $toString: '$_id' },
|
|
151
|
+
typeOf: 1
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
.sort(sort)
|
|
155
|
+
.lean()
|
|
156
|
+
.exec();
|
|
157
|
+
if (doc === null) {
|
|
158
|
+
// no op
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
|
|
163
|
+
id: doc.id,
|
|
164
|
+
typeOf: doc.typeOf,
|
|
165
|
+
status: factory_1.factory.transactionStatusType.Expired
|
|
166
|
+
});
|
|
167
|
+
return doc;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// /**
|
|
171
|
+
// * 取引を期限切れにする
|
|
172
|
+
// */
|
|
173
|
+
// public async makeExpired(params: {
|
|
174
|
+
// expires: { $lt: Date };
|
|
175
|
+
// limit: number; // add limit(2025-02-27~)
|
|
176
|
+
// }): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'>[]> {
|
|
177
|
+
// if (typeof params.limit !== 'number' || params.limit === 0) {
|
|
178
|
+
// throw new factory.errors.ArgumentNull('limit');
|
|
179
|
+
// }
|
|
180
|
+
// const sort: { [key in keyof factory.transaction.ITransaction<factory.transactionType>]?: factory.sortType } = {
|
|
181
|
+
// expires: factory.sortType.Ascending
|
|
182
|
+
// };
|
|
183
|
+
// // IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
184
|
+
// const expiringTransactions =
|
|
185
|
+
// await this.transactionModel.find({
|
|
186
|
+
// status: { $eq: factory.transactionStatusType.InProgress },
|
|
187
|
+
// expires: { $lt: params.expires.$lt }
|
|
188
|
+
// })
|
|
189
|
+
// .select({
|
|
190
|
+
// _id: 0,
|
|
191
|
+
// id: { $toString: '$_id' },
|
|
192
|
+
// typeOf: 1
|
|
193
|
+
// })
|
|
194
|
+
// .limit(params.limit)
|
|
195
|
+
// .sort(sort) // sort(2025-03-03~)
|
|
196
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
197
|
+
// .lean<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'>[]>()
|
|
198
|
+
// .exec();
|
|
199
|
+
// if (expiringTransactions.length > 0) {
|
|
200
|
+
// // ステータスと期限を見て更新
|
|
201
|
+
// await this.transactionModel.updateMany(
|
|
202
|
+
// {
|
|
203
|
+
// _id: { $in: expiringTransactions.map((t) => t.id) },
|
|
204
|
+
// status: { $eq: factory.transactionStatusType.InProgress },
|
|
205
|
+
// expires: { $lt: params.expires.$lt }
|
|
206
|
+
// },
|
|
207
|
+
// {
|
|
208
|
+
// status: factory.transactionStatusType.Expired,
|
|
209
|
+
// endDate: new Date()
|
|
210
|
+
// }
|
|
211
|
+
// )
|
|
212
|
+
// .exec();
|
|
213
|
+
// expiringTransactions.forEach((expiringTransaction) => {
|
|
214
|
+
// transactionEventEmitter.emitTransactionStatusChanged({
|
|
215
|
+
// id: expiringTransaction.id,
|
|
216
|
+
// typeOf: expiringTransaction.typeOf,
|
|
217
|
+
// status: factory.transactionStatusType.Expired
|
|
218
|
+
// });
|
|
219
|
+
// });
|
|
220
|
+
// }
|
|
221
|
+
// return expiringTransactions;
|
|
222
|
+
// }
|
|
223
|
+
async findByIdAndDelete(params) {
|
|
224
|
+
await this.transactionModel.findByIdAndDelete(params.id)
|
|
225
|
+
.exec();
|
|
226
|
+
}
|
|
227
|
+
async unsetUnnecessaryFields(params) {
|
|
228
|
+
return this.transactionModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
229
|
+
.exec();
|
|
230
|
+
}
|
|
231
|
+
getCursor(conditions, projection, sort) {
|
|
232
|
+
return this.transactionModel.find(conditions, projection)
|
|
233
|
+
.sort({ startDate: (sort === factory_1.factory.sortType.Ascending) ? sort : factory_1.factory.sortType.Descending })
|
|
234
|
+
.cursor();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.AdminTransactionRepo = AdminTransactionRepo;
|