forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.controller.ts
More file actions
68 lines (59 loc) · 1.76 KB
/
Copy pathemail.controller.ts
File metadata and controls
68 lines (59 loc) · 1.76 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
import {
Controller,
Get,
Patch,
Body,
Param,
NotFoundException,
} from "@nestjs/common";
import { ApiTags, ApiOperation, ApiResponse } from "@nestjs/swagger";
import { EmailService } from "./email.service";
import { IsBoolean, IsOptional } from "class-validator";
export class UpdateEmailPreferencesDto {
@IsOptional()
@IsBoolean()
invitations?: boolean;
@IsOptional()
@IsBoolean()
reminders?: boolean;
@IsOptional()
@IsBoolean()
receivedConfirmation?: boolean;
@IsOptional()
@IsBoolean()
completion?: boolean;
}
@ApiTags("Notifications")
@Controller("notifications")
export class EmailController {
constructor(private readonly emailService: EmailService) {}
@Get("preferences/:userId")
@ApiOperation({ summary: "Get user email preferences" })
@ApiResponse({ status: 200, description: "Preferences retrieved" })
@ApiResponse({ status: 404, description: "User not found" })
async getPreferences(@Param("userId") userId: string) {
const user = await this.emailService.getUser(userId);
if (!user) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
return user.emailPreferences;
}
@Patch("preferences/:userId")
@ApiOperation({ summary: "Update user email preferences" })
@ApiResponse({ status: 200, description: "Preferences updated" })
async updatePreferences(
@Param("userId") userId: string,
@Body() dto: UpdateEmailPreferencesDto,
) {
const user = await this.emailService.getUser(userId);
if (!user) {
throw new NotFoundException(`User with ID ${userId} not found`);
}
const updatedPreferences = {
...user.emailPreferences,
...dto,
};
await this.emailService.updatePreferences(userId, updatedPreferences);
return updatedPreferences;
}
}