-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed file sturucture and incorporated feedback
- Loading branch information
1 parent
6c9e8ed
commit 9fc996b
Showing
8 changed files
with
105 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
import { Post, Body, Controller } from '@nestjs/common'; | ||
import { Controller } from '@nestjs/common'; | ||
import { AppService } from './app.service'; | ||
import { EmailProto } from 'juno-proto'; | ||
|
||
@Controller() | ||
export class AppController { | ||
constructor(private readonly appService: AppService) {} | ||
@Post('/register-sender') | ||
async registerSender( | ||
@Body() req: EmailProto.RegisterSenderRequest, | ||
): Promise<EmailProto.RegisterSenderResponse> { | ||
return await this.appService.registerSender(req); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { EmailProto } from 'juno-proto'; | ||
import axios from 'axios'; | ||
import { RpcException } from '@nestjs/microservices'; | ||
|
||
@Injectable() | ||
export class AppService { | ||
async registerSender( | ||
req: EmailProto.RegisterSenderRequest, | ||
): Promise<EmailProto.RegisterEmailResponse> { | ||
if (!req.from_email) { | ||
throw new RpcException('Cannot register sender (no email supplied)'); | ||
} | ||
if (!req.from_name) { | ||
throw new RpcException('Cannot register sender (no name supplied)'); | ||
} | ||
if (!req.reply_to) { | ||
throw new RpcException('Cannot register sender (no reply to specified)'); | ||
} | ||
|
||
const sendgridApiKey = process.env.SENDGRID_API_KEY; | ||
|
||
if (!sendgridApiKey) { | ||
throw new RpcException( | ||
'Cannot register sender (sendgrid API key is missing)', | ||
); | ||
} | ||
const sendgridUrl = 'https://api.sendgrid.com/v3/verified_senders'; | ||
|
||
try { | ||
const res = await axios.post( | ||
sendgridUrl, | ||
{ | ||
from_email: req.from_email, | ||
from_name: req.from_name, | ||
reply_to: req.reply_to, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${sendgridApiKey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
return { | ||
statusCode: res.status, | ||
message: 'Sender registered successfully', | ||
}; | ||
} catch (err) { | ||
console.error('error registering sender:', err); | ||
throw new RpcException('Unable to register sender'); | ||
} | ||
} | ||
} | ||
export class AppService {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,20 @@ beforeAll(async () => { | |
|
||
const protoGRPC = GRPC.loadPackageDefinition(proto) as any; | ||
|
||
const resetClient = new protoGRPC.juno.reset_db.DatabaseReset( | ||
process.env.DB_SERVICE_ADDR, | ||
GRPC.credentials.createInsecure(), | ||
); | ||
|
||
const emailClient = new protoGRPC.juno.emailService( | ||
process.env.DB_SERVICE_ADDR, | ||
GRPC.credentials.createInsecure(), | ||
); | ||
|
||
await new Promise((resolve) => { | ||
resetClient.resetDb({}, () => { | ||
resolve(0); | ||
}); | ||
emailClient.resetDb({}, () => { | ||
resolve(0); | ||
}); | ||
|
@@ -59,9 +67,9 @@ it('should successfully register a sender', async () => { | |
(resolve, reject) => { | ||
emailClient.registerSender( | ||
{ | ||
from_email: '[email protected]', | ||
from_name: 'example', | ||
reply_to: '[email protected]', | ||
fromEmail: '[email protected]', | ||
fromName: 'example', | ||
replyTo: '[email protected]', | ||
}, | ||
(err: any, response: EmailProto.RegisterSenderResponse) => { | ||
if (err) { | ||
|
@@ -83,9 +91,9 @@ it('should fail to register a sender', async () => { | |
(resolve, reject) => { | ||
emailClient.registerSender( | ||
{ | ||
from_email: '', | ||
from_name: '', | ||
reply_to: '', | ||
fromEmail: '', | ||
fromName: '', | ||
replyTo: '', | ||
}, | ||
(err: any, response: EmailProto.RegisterSenderResponse) => { | ||
if (err) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1828,7 +1828,7 @@ [email protected]: | |
form-data "^4.0.0" | ||
proxy-from-env "^1.1.0" | ||
|
||
axios@^1.6.0, axios@^1.6.4: | ||
axios@^1.6.0, axios@^1.6.4, axios@^1.6.7: | ||
version "1.6.8" | ||
resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.8.tgz#66d294951f5d988a00e87a0ffb955316a619ea66" | ||
integrity sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ== | ||
|