forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.controller.ts
More file actions
104 lines (95 loc) · 2.47 KB
/
Copy pathbatch.controller.ts
File metadata and controls
104 lines (95 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {
Body,
Controller,
Delete,
Get,
HttpCode,
HttpStatus,
Param,
Post,
Query,
UseGuards,
} from "@nestjs/common";
import {
Permissions,
RequirePermissions,
} from "../auth/decorators/permissions.decorator";
import { AuthorizationGuard } from "../auth/guards/authorization.guard";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { BatchService } from "./batch.service";
import {
CreateBatchPaymentsDto,
CreateBatchSplitsDto,
RetryBatchDto,
} from "./dto/create-batch.dto";
import { BatchJobStatus } from "./entities/batch-job.entity";
@Controller("batch")
@UseGuards(JwtAuthGuard, AuthorizationGuard)
export class BatchController {
constructor(private readonly batchService: BatchService) {}
/**
* Create a batch of splits
*/
@Post("splits")
@HttpCode(HttpStatus.CREATED)
@RequirePermissions(Permissions.CAN_CREATE_SPLIT)
async createBatchSplits(@Body() dto: CreateBatchSplitsDto) {
return this.batchService.createBatchSplits(dto);
}
/**
* Create a batch of payments
*/
@Post("payments")
@HttpCode(HttpStatus.CREATED)
@RequirePermissions(Permissions.CAN_CREATE_PAYMENT)
async createBatchPayments(@Body() dto: CreateBatchPaymentsDto) {
return this.batchService.createBatchPayments(dto);
}
/**
* Get batch status by ID
*/
@Get(":batchId/status")
async getBatchStatus(@Param("batchId") batchId: string) {
return this.batchService.getBatchStatus(batchId);
}
/**
* List all batches with pagination
*/
@Get()
async listBatches(
@Query("page") page: number = 1,
@Query("limit") limit: number = 50,
@Query("status") status?: BatchJobStatus,
) {
return this.batchService.listBatches(page, limit, status);
}
/**
* Retry failed operations in a batch
*/
@Post(":batchId/retry")
@HttpCode(HttpStatus.OK)
async retryBatch(
@Param("batchId") batchId: string,
@Body() dto: RetryBatchDto,
) {
return this.batchService.retryFailedOperations(batchId, dto.operationIds);
}
/**
* Cancel a pending or processing batch
*/
@Delete(":batchId/cancel")
@HttpCode(HttpStatus.OK)
async cancelBatch(@Param("batchId") batchId: string) {
return this.batchService.cancelBatch(batchId);
}
/**
* Get operations for a batch
*/
@Get(":batchId/operations")
async getBatchOperations(
@Param("batchId") batchId: string,
@Query("status") status?: string,
) {
return this.batchService.getBatchOperations(batchId, status as any);
}
}