From 670e7b31937ba1e457fb32d85aa7894774466a6a Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sat, 9 Jan 2021 18:30:19 +0530 Subject: [PATCH] :recycle: Update email module with imports --- src/modules/emails/emails.controller.ts | 8 ++++++-- src/modules/emails/emails.module.ts | 4 ++++ src/modules/emails/emails.service.ts | 20 ++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/modules/emails/emails.controller.ts b/src/modules/emails/emails.controller.ts index af0204b9e..5dc9e9b10 100644 --- a/src/modules/emails/emails.controller.ts +++ b/src/modules/emails/emails.controller.ts @@ -22,6 +22,7 @@ import { EmailsService } from './emails.service'; export class EmailController { constructor(private emailsService: EmailsService) {} + /** Create a new email for a user */ @Post() @Scopes('user-{userId}:write-email-*') async create( @@ -31,6 +32,7 @@ export class EmailController { return this.emailsService.createEmail(userId, data); } + /** Get emails for a user */ @Get() @Scopes('user-{userId}:read-email-*') async getAll( @@ -50,21 +52,23 @@ export class EmailController { }); } + /** Get an email for a user */ @Get(':id') @Scopes('user-{userId}:read-email-{id}') async get( @Param('userId', ParseIntPipe) userId: number, @Param('id', ParseIntPipe) id: number, ): Promise> { - return this.emailsService.getEmail(userId, Number(id)); + return this.emailsService.getEmail(userId, id); } + /** Delete an email for a user */ @Delete(':id') @Scopes('user-{userId}:delete-email-{id}') async remove( @Param('userId', ParseIntPipe) userId: number, @Param('id', ParseIntPipe) id: number, ): Promise> { - return this.emailsService.deleteEmail(userId, Number(id)); + return this.emailsService.deleteEmail(userId, id); } } diff --git a/src/modules/emails/emails.module.ts b/src/modules/emails/emails.module.ts index 3e1f103a9..5d74d4201 100644 --- a/src/modules/emails/emails.module.ts +++ b/src/modules/emails/emails.module.ts @@ -11,6 +11,8 @@ import { TwilioModule } from '../../providers/twilio/twilio.module'; import { UsersService } from '../users/users.service'; import { EmailController } from './emails.controller'; import { EmailsService } from './emails.service'; +import { S3Module } from '../../providers/s3/s3.module'; +import { ApiKeysModule } from '../api-keys/api-keys.module'; @Module({ imports: [ @@ -20,6 +22,8 @@ import { EmailsService } from './emails.service'; TwilioModule, PwnedModule, TokensModule, + S3Module, + ApiKeysModule, ], controllers: [EmailController], providers: [ diff --git a/src/modules/emails/emails.service.ts b/src/modules/emails/emails.service.ts index b6e546148..085d0c6b8 100644 --- a/src/modules/emails/emails.service.ts +++ b/src/modules/emails/emails.service.ts @@ -49,14 +49,18 @@ export class EmailsService { }, ): Promise[]> { const { skip, take, cursor, where, orderBy } = params; - const emails = await this.prisma.email.findMany({ - skip, - take, - cursor, - where: { ...where, user: { id: userId } }, - orderBy, - }); - return emails.map((user) => this.prisma.expose(user)); + try { + const emails = await this.prisma.email.findMany({ + skip, + take, + cursor, + where: { ...where, user: { id: userId } }, + orderBy, + }); + return emails.map((user) => this.prisma.expose(user)); + } catch (error) { + return []; + } } async getEmail(userId: number, id: number): Promise> {