forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-currency.controller.ts
More file actions
61 lines (51 loc) · 1.43 KB
/
Copy pathuser-currency.controller.ts
File metadata and controls
61 lines (51 loc) · 1.43 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
import { Body, Controller, Get, Post, Put, Query, Req } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import type { Request } from 'express';
import { CurrencyService } from './user-currency.service';
interface AuthenticatedRequest extends Request {
user: { id: string };
}
interface ConvertBody {
base: string;
target: string;
amount: number;
}
@ApiExcludeController()
@Controller('legacy/currency')
export class CurrencyController {
constructor(private readonly service: CurrencyService) {}
@Get('detect')
detect(@Req() req: Request) {
return this.service.detectCurrencyFromRequest(req);
}
@Get('preferences')
getPref(@Req() req: AuthenticatedRequest) {
return this.service.getOrCreatePreference(req.user.id, req);
}
@Put('preferences')
updatePref(
@Req() req: AuthenticatedRequest,
@Body('currency') currency: string,
) {
return this.service.updatePreference(req.user.id, currency);
}
@Get('rates')
getRates(
@Query('base') base: string,
@Query('targets') targets: string,
) {
const list = targets
?.split(',')
.map((target) => target.trim())
.filter(Boolean);
return this.service.getRates(base, list);
}
@Post('convert')
convert(@Body() body: ConvertBody) {
return this.service.convert(body.base, body.target, body.amount);
}
@Get('supported')
supported() {
return this.service.getSupportedSummary();
}
}