From 3fb490fa2bc36dec5c87aefcf615cf0c5b60b98d Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Fri, 30 Oct 2020 12:20:45 +0530 Subject: [PATCH] :recycle: Change approved location -> approved subnet --- .../approved-subnets.controller.ts | 8 ++-- .../approved-subnets.service.ts | 46 +++++++++---------- src/modules/auth/auth.service.ts | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/modules/approved-subnets/approved-subnets.controller.ts b/src/modules/approved-subnets/approved-subnets.controller.ts index 5fd787b8d..2fc36eed5 100644 --- a/src/modules/approved-subnets/approved-subnets.controller.ts +++ b/src/modules/approved-subnets/approved-subnets.controller.ts @@ -6,7 +6,7 @@ import { ParseIntPipe, Query, } from '@nestjs/common'; -import { approvedLocations } from '@prisma/client'; +import { approvedSubnets } from '@prisma/client'; import { Expose } from 'src/modules/prisma/prisma.interface'; import { CursorPipe } from 'src/pipes/cursor.pipe'; import { OptionalIntPipe } from 'src/pipes/optional-int.pipe'; @@ -28,7 +28,7 @@ export class ApprovedSubnetController { @Query('cursor', CursorPipe) cursor?: Record, @Query('where', WherePipe) where?: Record, @Query('orderBy', OrderByPipe) orderBy?: Record, - ): Promise[]> { + ): Promise[]> { return this.approvedSubnetsService.getApprovedSubnets(userId, { skip, take, @@ -43,7 +43,7 @@ export class ApprovedSubnetController { async get( @Param('userId', ParseIntPipe) userId: number, @Param('id', ParseIntPipe) id: number, - ): Promise> { + ): Promise> { return this.approvedSubnetsService.getApprovedSubnet(userId, Number(id)); } @@ -52,7 +52,7 @@ export class ApprovedSubnetController { async remove( @Param('userId', ParseIntPipe) userId: number, @Param('id', ParseIntPipe) id: number, - ): Promise> { + ): Promise> { return this.approvedSubnetsService.deleteApprovedSubnet(userId, Number(id)); } } diff --git a/src/modules/approved-subnets/approved-subnets.service.ts b/src/modules/approved-subnets/approved-subnets.service.ts index db6d4a3b4..f3477d488 100644 --- a/src/modules/approved-subnets/approved-subnets.service.ts +++ b/src/modules/approved-subnets/approved-subnets.service.ts @@ -5,10 +5,10 @@ import { UnauthorizedException, } from '@nestjs/common'; import { - approvedLocations, - approvedLocationsOrderByInput, - approvedLocationsWhereInput, - approvedLocationsWhereUniqueInput, + approvedSubnets, + approvedSubnetsOrderByInput, + approvedSubnetsWhereInput, + approvedSubnetsWhereUniqueInput, } from '@prisma/client'; import { Expose } from 'src/modules/prisma/prisma.interface'; import { PrismaService } from '../prisma/prisma.service'; @@ -22,64 +22,64 @@ export class ApprovedSubnetsService { params: { skip?: number; take?: number; - cursor?: approvedLocationsWhereUniqueInput; - where?: approvedLocationsWhereInput; - orderBy?: approvedLocationsOrderByInput; + cursor?: approvedSubnetsWhereUniqueInput; + where?: approvedSubnetsWhereInput; + orderBy?: approvedSubnetsOrderByInput; }, - ): Promise[]> { + ): Promise[]> { const { skip, take, cursor, where, orderBy } = params; - const approvedLocations = await this.prisma.approvedLocations.findMany({ + const approvedSubnets = await this.prisma.approvedSubnets.findMany({ skip, take, cursor, where: { ...where, user: { id: userId } }, orderBy, }); - return approvedLocations.map(user => - this.prisma.expose(user), + return approvedSubnets.map(user => + this.prisma.expose(user), ); } async getApprovedSubnet( userId: number, id: number, - ): Promise | null> { - const approvedLocation = await this.prisma.approvedLocations.findOne({ + ): Promise | null> { + const approvedSubnet = await this.prisma.approvedSubnets.findOne({ where: { id }, }); - if (!approvedLocation) + if (!approvedSubnet) throw new HttpException('ApprovedSubnet not found', HttpStatus.NOT_FOUND); - if (approvedLocation.userId !== userId) throw new UnauthorizedException(); - if (!approvedLocation) + if (approvedSubnet.userId !== userId) throw new UnauthorizedException(); + if (!approvedSubnet) throw new HttpException('ApprovedSubnet not found', HttpStatus.NOT_FOUND); - return this.prisma.expose(approvedLocation); + return this.prisma.expose(approvedSubnet); } async deleteApprovedSubnet( userId: number, id: number, - ): Promise> { - const testApprovedSubnet = await this.prisma.approvedLocations.findOne({ + ): Promise> { + const testApprovedSubnet = await this.prisma.approvedSubnets.findOne({ where: { id }, }); if (!testApprovedSubnet) throw new HttpException('ApprovedSubnet not found', HttpStatus.NOT_FOUND); if (testApprovedSubnet.userId !== userId) throw new UnauthorizedException(); - const approvedLocation = await this.prisma.approvedLocations.delete({ + const approvedSubnet = await this.prisma.approvedSubnets.delete({ where: { id }, }); - return this.prisma.expose(approvedLocation); + return this.prisma.expose(approvedSubnet); } async approveNewSubnet(userId: number, ipAddress: string) { const subnet = anonymize(ipAddress); - const approved = await this.prisma.approvedLocations.create({ + const approved = await this.prisma.approvedSubnets.create({ data: { user: { connect: { id: userId } }, subnet, createdAt: new Date(), }, }); - return this.prisma.expose(approved); + return this.prisma.expose(approved); } } diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 65285d5da..fe5c698cb 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -352,7 +352,7 @@ export class AuthService { ): Promise { if (!checkLocationOnLogin) return; const subnet = anonymize(ipAddress); - const isApproved = await this.prisma.approvedLocations.findFirst({ + const isApproved = await this.prisma.approvedSubnets.findFirst({ where: { user: { id }, subnet }, }); if (!isApproved) {