chore: changed properties to embedProperties in shortcode model

This commit is contained in:
Balu Babu
2023-11-06 13:18:14 +05:30
parent 2064af92fc
commit 3eef6c9b04
6 changed files with 27 additions and 56 deletions

View File

@@ -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;

View File

@@ -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")
}

View File

@@ -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],
})

View File

@@ -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 */

View File

@@ -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(

View File

@@ -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,
},
});