Skip to content

Commit 57e5690

Browse files
committed
Updates emailer.
1 parent e075337 commit 57e5690

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

apps/api/src/email/email.controller.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,26 @@ class ApiKeyGuard {
77
const request = context.switchToHttp().getRequest();
88
const apiKey = request.headers['authorization']?.replace('Bearer ', '');
99
const expectedKey = process.env.API_KEY_SECRET;
10-
10+
1111
if (!expectedKey) {
1212
throw new Error('API_KEY_SECRET not configured');
1313
}
14-
14+
1515
return apiKey === expectedKey;
1616
}
1717
}
1818

1919
@UseGuards(ApiKeyGuard)
2020
@Controller('email')
2121
export class EmailController {
22-
constructor(private readonly emailService: EmailService) {}
22+
constructor(private readonly emailService: EmailService) { }
2323

2424
@Post('send-prompt')
2525
@HttpCode(HttpStatus.OK)
2626
async sendPrompt(
2727
@Body() body: { email: string; prompt?: string; userId?: string },
28-
@Headers('authorization') auth: string,
2928
) {
30-
const { email, prompt, userId } = body;
29+
const { email, prompt } = body;
3130

3231
// Validate required fields
3332
if (!email) {
@@ -40,9 +39,14 @@ export class EmailController {
4039
throw new UnauthorizedException('Valid email is required');
4140
}
4241

42+
const user = await this.emailService['prisma'].user.findUnique({ where: { email } });
43+
if (!user) {
44+
throw new UnauthorizedException('User not found');
45+
};
46+
4347
try {
4448
const promptContent = prompt || this.getDefaultPrompt();
45-
49+
4650
const result = await this.emailService.sendPrompt(email, promptContent);
4751

4852
return {
@@ -72,7 +76,7 @@ export class EmailController {
7276
'What are you looking forward to tomorrow?',
7377
'What was the most meaningful part of your day?',
7478
];
75-
79+
7680
return prompts[Math.floor(Math.random() * prompts.length)];
7781
}
7882
}

turbo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"PORT",
1616
"WEB_APP_URL",
1717
"STRIPE_SECRET_KEY",
18-
"STRIPE_WEBHOOK_SECRET"
18+
"STRIPE_WEBHOOK_SECRET",
19+
"API_KEY_SECRET"
1920
],
2021
"tasks": {
2122
"dev": {

0 commit comments

Comments
 (0)