From 83d3521e67dcfa21d7f717e6b8c261f8dc4519f2 Mon Sep 17 00:00:00 2001 From: Syaam Khandaker Date: Sat, 2 Mar 2024 19:18:34 -0500 Subject: [PATCH] updated structure, return type, and placeholder return --- .../src/modules/domain/domain.controller.ts | 14 ++++++++++---- .../src/modules/domain/domain.controller.ts | 6 ++---- .../src/modules/domain/domain.service.ts | 12 +++++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/api-gateway/src/modules/domain/domain.controller.ts b/packages/api-gateway/src/modules/domain/domain.controller.ts index 5c22678a..b80924b7 100644 --- a/packages/api-gateway/src/modules/domain/domain.controller.ts +++ b/packages/api-gateway/src/modules/domain/domain.controller.ts @@ -27,8 +27,11 @@ export class DomainController { if (!body.domain) { throw new Error('Invalid body.'); } - this.domainService.verifyDomain(body); - return undefined; + const domain = this.domainService.verifyDomain(body); + if (!domain) { + throw new Error('This domain does not exist.'); + } + return { success: true }; } @Post('register') @@ -38,7 +41,10 @@ export class DomainController { if (!body.domain || !body.subDomain) { throw new Error('Invalid body.'); } - this.domainService.registerDomain(body); - return undefined; + const domain = this.domainService.registerDomain(body); + if (!domain) { + throw new Error('This domain could not be registered.'); + } + return { success: true }; } } diff --git a/packages/db-service/src/modules/domain/domain.controller.ts b/packages/db-service/src/modules/domain/domain.controller.ts index 2858b54d..0f5e8927 100644 --- a/packages/db-service/src/modules/domain/domain.controller.ts +++ b/packages/db-service/src/modules/domain/domain.controller.ts @@ -12,13 +12,11 @@ export class DomainDbController implements DomainProto.DomainServiceController { async verifyDomain( request: DomainProto.VerifyDomainRequest, ): Promise { - await this.domainService.verifyDomain(request, client); - return undefined; + return await this.domainService.verifyDomain(request, client); } async registerDomain( request: DomainProto.RegisterDomainRequest, ): Promise { - await this.domainService.registerDomain(request, client); - return undefined; + return await this.domainService.registerDomain(request, client); } } diff --git a/packages/db-service/src/modules/domain/domain.service.ts b/packages/db-service/src/modules/domain/domain.service.ts index a83fe722..69c77cf4 100644 --- a/packages/db-service/src/modules/domain/domain.service.ts +++ b/packages/db-service/src/modules/domain/domain.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common'; +import { Domain } from '@prisma/client'; import { DomainProto } from 'juno-proto'; import { PrismaService } from 'src/prisma.service'; @@ -18,7 +19,10 @@ type HttpMethod = export class DomainService { constructor(private prisma: PrismaService) {} - async verifyDomain(request: DomainProto.VerifyDomainRequest, client: any) { + async verifyDomain( + request: DomainProto.VerifyDomainRequest, + client: any, + ): Promise { const domainEntry = await this.prisma.domain.findUnique({ where: { domain: request.domain }, }); @@ -36,12 +40,13 @@ export class DomainService { if (response[0].statusCode !== 200) { throw new Error('There was an error with your request'); } + return domainEntry; } async registerDomain( request: DomainProto.RegisterDomainRequest, client: any, - ) { + ): Promise { const data = { domain: request.domain, subdomain: request.subDomain, @@ -57,12 +62,13 @@ export class DomainService { if (response[0].statusCode !== 200) { throw new Error('There was an error with your request'); } - await this.prisma.domain.create({ + const domain = await this.prisma.domain.create({ data: { domain: request.domain, subdomain: request.subDomain, id: response[0].body['id'], }, }); + return domain; } }