forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerchant.controller.ts
More file actions
97 lines (91 loc) · 3.17 KB
/
Copy pathmerchant.controller.ts
File metadata and controls
97 lines (91 loc) · 3.17 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
import { Controller, Get, Patch, Body, UseGuards } from "@nestjs/common";
import { Auth, CurrentUser } from "../auth/guard/auth.guard";
import { User } from "../users/user.entity";
import { MerchantService } from "./merchant.service";
import { UpdateMerchantSettingsDto } from "./dto/update-merchant-settings.dto";
import { UpdateChecklistDto } from "./dto/update-checklist.dto";
import { PrismaService } from "../prisma/prisma.service";
import { Roles } from "../common/decorators/roles.decorator";
import { MerchantRole } from "../common/enums/merchant-role.enum";
import { MerchantRolesGuard } from "../common/guards/merchant-roles.guard";
/**
* MerchantController
* Exposes merchant profile and settings management endpoints.
* All routes require JWT authentication; the merchant is scoped
* to the authenticated user's merchantId.
*/
@Controller("merchants")
export class MerchantController {
constructor(
private readonly merchantService: MerchantService,
private readonly prisma: PrismaService,
) {}
/**
* GET /merchants/profile
* Returns the merchant profile for the authenticated user.
*/
@Auth()
@Get("profile")
async getProfile(@CurrentUser() user: User) {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.merchantService.getProfile(user.merchantId),
);
}
/**
* PATCH /merchants/settings
* Updates merchant settings (name, payout key, preferred asset, webhook).
* Validates Stellar public key format before persisting.
* Restricted to merchant OWNERs and ADMINs.
*/
@Roles(MerchantRole.OWNER, MerchantRole.ADMIN)
@UseGuards(MerchantRolesGuard)
@Patch("settings")
async updateSettings(
@CurrentUser() user: User,
@Body() dto: UpdateMerchantSettingsDto,
) {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.merchantService.updateSettings(user.merchantId, dto),
);
}
/**
* GET /merchants/checklist
* Returns the activation checklist for the authenticated merchant.
*/
@Auth()
@Get("checklist")
async getChecklist(@CurrentUser() user: User) {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.merchantService.getChecklist(user.merchantId),
);
}
/**
* PATCH /merchants/checklist
* Updates checklist completion status.
* Restricted to merchant OWNERs, ADMINs and OPERATORs.
*/
@Roles(MerchantRole.OWNER, MerchantRole.ADMIN, MerchantRole.OPERATOR)
@UseGuards(MerchantRolesGuard)
@Patch("checklist")
async updateChecklist(
@CurrentUser() user: User,
@Body() dto: UpdateChecklistDto,
) {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.merchantService.updateChecklist(user.merchantId, dto),
);
}
/**
* POST /merchants/checklist/sync
* Syncs checklist based on current merchant state.
* Restricted to merchant OWNERs, ADMINs and OPERATORs.
*/
@Roles(MerchantRole.OWNER, MerchantRole.ADMIN, MerchantRole.OPERATOR)
@UseGuards(MerchantRolesGuard)
@Patch("checklist/sync")
async syncChecklist(@CurrentUser() user: User) {
return this.prisma.runWithMerchantScope(user.merchantId, () =>
this.merchantService.syncChecklist(user.merchantId),
);
}
}