forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfraud-detection.controller.ts
More file actions
122 lines (112 loc) · 3.19 KB
/
Copy pathfraud-detection.controller.ts
File metadata and controls
122 lines (112 loc) · 3.19 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {
Controller,
Get,
Post,
Body,
Param,
Query,
UseGuards,
HttpCode,
HttpStatus,
} from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { FraudDetectionService } from "./fraud-detection.service";
import { FraudAlert, AlertStatus } from "./entities/fraud-alert.entity";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { AuthorizationGuard } from "../auth/guards/authorization.guard";
import { RequirePermissions } from "../auth/decorators/permissions.decorator";
import { Permissions } from "../auth/decorators/permissions.decorator";
import {
AnalyzeSplitRequestDto,
AnalyzePaymentRequestDto,
FeedbackRequestDto,
ResolveAlertDto,
} from "./dto/analyze-split.dto";
@Controller("fraud")
@UseGuards(JwtAuthGuard, AuthorizationGuard)
export class FraudDetectionController {
constructor(
private readonly fraudDetectionService: FraudDetectionService,
@InjectRepository(FraudAlert)
private fraudAlertRepository: Repository<FraudAlert>,
) {}
/**
* Get all fraud alerts
*/
@Get("alerts")
@RequirePermissions(Permissions.CAN_READ_FRAUD_ALERTS)
async getAlerts(
@Query("status") status?: AlertStatus,
@Query("page") page: number = 1,
@Query("limit") limit: number = 50,
) {
return this.fraudDetectionService.getAlerts(status, page, limit);
}
/**
* Get a single alert
*/
@Get("alerts/:id")
@RequirePermissions(Permissions.CAN_READ_SPLIT)
async getAlert(@Param("id") id: string) {
const alert = await this.fraudDetectionService.getAlert(id);
if (!alert) {
return { error: "Alert not found" };
}
return alert;
}
/**
* Resolve a fraud alert
*/
@Post("alerts/:id/resolve")
@RequirePermissions(Permissions.CAN_UPDATE_SPLIT)
@HttpCode(HttpStatus.OK)
async resolveAlert(
@Param("id") id: string,
@Body() resolveData: ResolveAlertDto,
@Query("resolvedBy") resolvedBy: string,
) {
return this.fraudDetectionService.resolveAlert(id, resolveData, resolvedBy);
}
/**
* Get analysis for a specific split
*/
@Get("splits/:id/analysis")
@RequirePermissions(Permissions.CAN_READ_SPLIT)
async getSplitAnalysis(@Param("id") id: string) {
return this.fraudDetectionService.getSplitAnalysis(id);
}
/**
* Get fraud detection statistics
*/
@Get("stats")
@RequirePermissions(Permissions.CAN_READ_SPLIT)
async getStats() {
return this.fraudDetectionService.getStats();
}
/**
* Submit feedback on an alert
*/
@Post("feedback")
@HttpCode(HttpStatus.OK)
async submitFeedback(@Body() feedback: FeedbackRequestDto) {
await this.fraudDetectionService.submitFeedback(feedback);
return { success: true };
}
/**
* Analyze a split (admin/debug endpoint)
*/
@Post("analyze/split")
@HttpCode(HttpStatus.OK)
async analyzeSplit(@Body() request: AnalyzeSplitRequestDto) {
return this.fraudDetectionService.analyzeSplit(request);
}
/**
* Analyze a payment (admin/debug endpoint)
*/
@Post("analyze/payment")
@HttpCode(HttpStatus.OK)
async analyzePayment(@Body() request: AnalyzePaymentRequestDto) {
return this.fraudDetectionService.analyzePayment(request);
}
}