Skip to content

Commit

Permalink
updated structure, return type, and placeholder return
Browse files Browse the repository at this point in the history
  • Loading branch information
syaamkhandaker committed Mar 3, 2024
1 parent 24aa099 commit 83d3521
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 10 additions & 4 deletions packages/api-gateway/src/modules/domain/domain.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 };
}
}
6 changes: 2 additions & 4 deletions packages/db-service/src/modules/domain/domain.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export class DomainDbController implements DomainProto.DomainServiceController {
async verifyDomain(
request: DomainProto.VerifyDomainRequest,
): Promise<DomainProto.VerifyDomainResponse> {
await this.domainService.verifyDomain(request, client);
return undefined;
return await this.domainService.verifyDomain(request, client);
}
async registerDomain(
request: DomainProto.RegisterDomainRequest,
): Promise<DomainProto.RegisterDomainResponse> {
await this.domainService.registerDomain(request, client);
return undefined;
return await this.domainService.registerDomain(request, client);
}
}
12 changes: 9 additions & 3 deletions packages/db-service/src/modules/domain/domain.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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<Domain> {
const domainEntry = await this.prisma.domain.findUnique({
where: { domain: request.domain },
});
Expand All @@ -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<Domain> {
const data = {
domain: request.domain,
subdomain: request.subDomain,
Expand All @@ -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;
}
}

0 comments on commit 83d3521

Please sign in to comment.