From 3eef6c9b04faa0f07fd391a6b5523262a2f0dc53 Mon Sep 17 00:00:00 2001 From: Balu Babu Date: Mon, 6 Nov 2023 13:18:14 +0530 Subject: [PATCH] chore: changed properties to embedProperties in shortcode model --- .../migration.sql | 16 ---------- .../hoppscotch-backend/prisma/schema.prisma | 14 ++++----- .../src/shortcode/shortcode.module.ts | 10 +------ .../src/shortcode/shortcode.resolver.ts | 4 --- .../src/shortcode/shortcode.service.spec.ts | 30 +++++++++---------- .../src/shortcode/shortcode.service.ts | 9 +++--- 6 files changed, 27 insertions(+), 56 deletions(-) delete mode 100644 packages/hoppscotch-backend/prisma/migrations/20231103083443_shared_requests/migration.sql diff --git a/packages/hoppscotch-backend/prisma/migrations/20231103083443_shared_requests/migration.sql b/packages/hoppscotch-backend/prisma/migrations/20231103083443_shared_requests/migration.sql deleted file mode 100644 index b828b5101..000000000 --- a/packages/hoppscotch-backend/prisma/migrations/20231103083443_shared_requests/migration.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[id]` on the table `Shortcode` will be added. If there are existing duplicate values, this will fail. - - Added the required column `updatedOn` to the `Shortcode` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "Shortcode" ADD COLUMN "properties" JSONB, -ADD COLUMN "updatedOn" TIMESTAMP(3) NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX "Shortcode_id_key" ON "Shortcode"("id"); - --- AddForeignKey -ALTER TABLE "Shortcode" ADD CONSTRAINT "Shortcode_creatorUid_fkey" FOREIGN KEY ("creatorUid") REFERENCES "User"("uid") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/packages/hoppscotch-backend/prisma/schema.prisma b/packages/hoppscotch-backend/prisma/schema.prisma index d3f8512a9..814682e5c 100644 --- a/packages/hoppscotch-backend/prisma/schema.prisma +++ b/packages/hoppscotch-backend/prisma/schema.prisma @@ -68,13 +68,13 @@ model TeamRequest { } model Shortcode { - id String @id @unique - request Json - properties Json? // if properties is null, SharedRequest is an shortcode else embed - creatorUid String? - User User? @relation(fields: [creatorUid], references: [uid]) - createdOn DateTime @default(now()) - updatedOn DateTime @updatedAt + id String @id @unique + request Json + embedProperties Json? + creatorUid String? + User User? @relation(fields: [creatorUid], references: [uid]) + createdOn DateTime @default(now()) + updatedOn DateTime @updatedAt @@unique(fields: [id, creatorUid], name: "creator_uid_shortcode_unique") } diff --git a/packages/hoppscotch-backend/src/shortcode/shortcode.module.ts b/packages/hoppscotch-backend/src/shortcode/shortcode.module.ts index eb696a23b..7febeadf0 100644 --- a/packages/hoppscotch-backend/src/shortcode/shortcode.module.ts +++ b/packages/hoppscotch-backend/src/shortcode/shortcode.module.ts @@ -1,5 +1,4 @@ import { Module } from '@nestjs/common'; -import { JwtModule } from '@nestjs/jwt'; import { PrismaModule } from 'src/prisma/prisma.module'; import { PubSubModule } from 'src/pubsub/pubsub.module'; import { UserModule } from 'src/user/user.module'; @@ -7,14 +6,7 @@ import { ShortcodeResolver } from './shortcode.resolver'; import { ShortcodeService } from './shortcode.service'; @Module({ - imports: [ - PrismaModule, - UserModule, - PubSubModule, - JwtModule.register({ - secret: process.env.JWT_SECRET, - }), - ], + imports: [PrismaModule, UserModule, PubSubModule], providers: [ShortcodeService, ShortcodeResolver], exports: [ShortcodeService], }) diff --git a/packages/hoppscotch-backend/src/shortcode/shortcode.resolver.ts b/packages/hoppscotch-backend/src/shortcode/shortcode.resolver.ts index 81f7410ce..60128087b 100644 --- a/packages/hoppscotch-backend/src/shortcode/shortcode.resolver.ts +++ b/packages/hoppscotch-backend/src/shortcode/shortcode.resolver.ts @@ -11,14 +11,12 @@ import * as E from 'fp-ts/Either'; import { UseGuards } from '@nestjs/common'; import { Shortcode } from './shortcode.model'; import { ShortcodeService } from './shortcode.service'; -import { UserService } from 'src/user/user.service'; import { throwErr } from 'src/utils'; import { GqlUser } from 'src/decorators/gql-user.decorator'; import { GqlAuthGuard } from 'src/guards/gql-auth.guard'; import { User } from 'src/user/user.model'; import { PubSubService } from 'src/pubsub/pubsub.service'; import { AuthUser } from '../types/AuthUser'; -import { JwtService } from '@nestjs/jwt'; import { PaginationArgs } from 'src/types/input-types.args'; import { GqlThrottlerGuard } from 'src/guards/gql-throttler.guard'; import { SkipThrottle } from '@nestjs/throttler'; @@ -28,9 +26,7 @@ import { SkipThrottle } from '@nestjs/throttler'; export class ShortcodeResolver { constructor( private readonly shortcodeService: ShortcodeService, - private readonly userService: UserService, private readonly pubsub: PubSubService, - private jwtService: JwtService, ) {} /* Queries */ diff --git a/packages/hoppscotch-backend/src/shortcode/shortcode.service.spec.ts b/packages/hoppscotch-backend/src/shortcode/shortcode.service.spec.ts index 5e7c9fff6..862cdf0d1 100644 --- a/packages/hoppscotch-backend/src/shortcode/shortcode.service.spec.ts +++ b/packages/hoppscotch-backend/src/shortcode/shortcode.service.spec.ts @@ -57,7 +57,7 @@ const user: AuthUser = { const mockEmbed = { id: '123', request: '{}', - properties: '{}', + embedProperties: '{}', createdOn: createdOn, creatorUid: user.uid, updatedOn: createdOn, @@ -66,7 +66,7 @@ const mockEmbed = { const mockShortcode = { id: '123', request: '{}', - properties: null, + embedProperties: null, createdOn: createdOn, creatorUid: user.uid, updatedOn: createdOn, @@ -78,7 +78,7 @@ const shortcodes = [ request: { hello: 'there', }, - properties: { + embedProperties: { foo: 'bar', }, creatorUid: user.uid, @@ -90,7 +90,7 @@ const shortcodes = [ request: { hello: 'there', }, - properties: { + embedProperties: { foo: 'bar', }, creatorUid: user.uid, @@ -109,7 +109,7 @@ describe('ShortcodeService', () => { id: mockEmbed.id, createdOn: mockEmbed.createdOn, request: JSON.stringify(mockEmbed.request), - properties: JSON.stringify(mockEmbed.properties), + properties: JSON.stringify(mockEmbed.embedProperties), }); }); @@ -135,13 +135,13 @@ describe('ShortcodeService', () => { { id: shortcodes[0].id, request: JSON.stringify(shortcodes[0].request), - properties: JSON.stringify(shortcodes[0].properties), + properties: JSON.stringify(shortcodes[0].embedProperties), createdOn: shortcodes[0].createdOn, }, { id: shortcodes[1].id, request: JSON.stringify(shortcodes[1].request), - properties: JSON.stringify(shortcodes[1].properties), + properties: JSON.stringify(shortcodes[1].embedProperties), createdOn: shortcodes[1].createdOn, }, ]); @@ -158,7 +158,7 @@ describe('ShortcodeService', () => { { id: shortcodes[1].id, request: JSON.stringify(shortcodes[1].request), - properties: JSON.stringify(shortcodes[1].properties), + properties: JSON.stringify(shortcodes[1].embedProperties), createdOn: shortcodes[1].createdOn, }, ]); @@ -229,7 +229,7 @@ describe('ShortcodeService', () => { id: mockEmbed.id, createdOn: mockEmbed.createdOn, request: JSON.stringify(mockEmbed.request), - properties: JSON.stringify(mockEmbed.properties), + properties: JSON.stringify(mockEmbed.embedProperties), }); }); @@ -245,7 +245,7 @@ describe('ShortcodeService', () => { id: mockShortcode.id, createdOn: mockShortcode.createdOn, request: JSON.stringify(mockShortcode.request), - properties: mockShortcode.properties, + properties: mockShortcode.embedProperties, }); }); @@ -264,7 +264,7 @@ describe('ShortcodeService', () => { id: mockShortcode.id, createdOn: mockShortcode.createdOn, request: JSON.stringify(mockShortcode.request), - properties: mockShortcode.properties, + properties: mockShortcode.embedProperties, }, ); }); @@ -284,7 +284,7 @@ describe('ShortcodeService', () => { id: mockEmbed.id, createdOn: mockEmbed.createdOn, request: JSON.stringify(mockEmbed.request), - properties: JSON.stringify(mockEmbed.properties), + properties: JSON.stringify(mockEmbed.embedProperties), }, ); }); @@ -346,7 +346,7 @@ describe('ShortcodeService', () => { id: mockEmbed.id, createdOn: mockEmbed.createdOn, request: JSON.stringify(mockEmbed.request), - properties: JSON.stringify(mockEmbed.properties), + properties: JSON.stringify(mockEmbed.embedProperties), }, ); }); @@ -404,7 +404,7 @@ describe('ShortcodeService', () => { test('should successfully update a Shortcodes with valid inputs', async () => { mockPrisma.shortcode.update.mockResolvedValueOnce({ ...mockEmbed, - properties: '{"foo":"bar"}', + embedProperties: '{"foo":"bar"}', }); const result = await shortcodeService.updateShortcode( @@ -423,7 +423,7 @@ describe('ShortcodeService', () => { test('should send pubsub message to `shortcode/{uid}/updated` on successful Update of Shortcode', async () => { mockPrisma.shortcode.update.mockResolvedValueOnce({ ...mockEmbed, - properties: '{"foo":"bar"}', + embedProperties: '{"foo":"bar"}', }); const result = await shortcodeService.updateShortcode( diff --git a/packages/hoppscotch-backend/src/shortcode/shortcode.service.ts b/packages/hoppscotch-backend/src/shortcode/shortcode.service.ts index fcf153494..c058fa271 100644 --- a/packages/hoppscotch-backend/src/shortcode/shortcode.service.ts +++ b/packages/hoppscotch-backend/src/shortcode/shortcode.service.ts @@ -5,7 +5,6 @@ import * as TO from 'fp-ts/TaskOption'; import * as E from 'fp-ts/Either'; import { PrismaService } from 'src/prisma/prisma.service'; import { - SHORTCODE_INVALID_JSON, SHORTCODE_INVALID_PROPERTIES_JSON, SHORTCODE_INVALID_REQUEST_JSON, SHORTCODE_NOT_FOUND, @@ -57,8 +56,8 @@ export class ShortcodeService implements UserDataHandler, OnModuleInit { id: shortcodeInfo.id, request: JSON.stringify(shortcodeInfo.request), properties: - shortcodeInfo.properties != null - ? JSON.stringify(shortcodeInfo.properties) + shortcodeInfo.embedProperties != null + ? JSON.stringify(shortcodeInfo.embedProperties) : null, createdOn: shortcodeInfo.createdOn, }; @@ -137,7 +136,7 @@ export class ShortcodeService implements UserDataHandler, OnModuleInit { data: { id: generatedShortCode.right, request: requestData.right, - properties: parsedProperties.right ?? undefined, + embedProperties: parsedProperties.right ?? undefined, creatorUid: userInfo.uid, }, }); @@ -250,7 +249,7 @@ export class ShortcodeService implements UserDataHandler, OnModuleInit { }, }, data: { - properties: parsedProperties.right, + embedProperties: parsedProperties.right, }, });