From c4500c9dcd0d4062cc2443e0a596568037091d1d Mon Sep 17 00:00:00 2001 From: Udit Date: Sat, 7 Sep 2024 22:42:10 +0530 Subject: [PATCH 1/6] Included default workspace details in getSelf function --- apps/api/src/user/service/user.service.ts | 21 ++++++++++++++- apps/api/src/user/user.e2e.spec.ts | 32 +++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/apps/api/src/user/service/user.service.ts b/apps/api/src/user/service/user.service.ts index c4f8225b..7a3a7cea 100644 --- a/apps/api/src/user/service/user.service.ts +++ b/apps/api/src/user/service/user.service.ts @@ -30,7 +30,26 @@ export class UserService { } async getSelf(user: User) { - return user + let defaultWorkspace = null + if (!user.isAdmin) { + defaultWorkspace = await this.prisma.workspace.findFirst({ + where: { + ownerId: user.id, + isDefault: true + }, + select: { + id: true, + name: true, + description: true, + isFreeTier: true, + createdAt: true, + updatedAt: true, + lastUpdatedById: true + } + }) + } + + return { ...user, defaultWorkspace } } async updateSelf(user: User, dto: UpdateUserDto) { diff --git a/apps/api/src/user/user.e2e.spec.ts b/apps/api/src/user/user.e2e.spec.ts index 5536211b..456a6575 100644 --- a/apps/api/src/user/user.e2e.spec.ts +++ b/apps/api/src/user/user.e2e.spec.ts @@ -82,7 +82,8 @@ describe('User Controller Tests', () => { }) expect(result.statusCode).toEqual(200) expect(JSON.parse(result.body)).toEqual({ - ...adminUser + ...adminUser, + defaultWorkspace: null }) }) @@ -94,10 +95,37 @@ describe('User Controller Tests', () => { 'x-e2e-user-email': regularUser.email } }) + + const workspace = await prisma.workspace.findFirst({ + where: { + ownerId: regularUser.id, + isDefault: true + } + }) + expect(result.statusCode).toEqual(200) expect(JSON.parse(result.body)).toEqual({ - ...regularUser + ...regularUser, + defaultWorkspace: expect.any(Object) }) + + expect(result.json().defaultWorkspace.id).toEqual(workspace.id) + expect(result.json().defaultWorkspace.name).toEqual(workspace.name) + expect(result.json().defaultWorkspace.description).toEqual( + workspace.description + ) + expect(result.json().defaultWorkspace.isFreeTier).toEqual( + workspace.isFreeTier + ) + expect(result.json().defaultWorkspace.createdAt).toEqual( + workspace.createdAt.toISOString() + ) + expect(result.json().defaultWorkspace.updatedAt).toEqual( + workspace.updatedAt.toISOString() + ) + expect(result.json().defaultWorkspace.lastUpdatedById).toEqual( + workspace.lastUpdatedById + ) }) it('should have created a default workspace', async () => { From 50a6a31c6a2040732f14fd6bdabb4ec5f3c897b1 Mon Sep 17 00:00:00 2001 From: Udit Date: Sat, 7 Sep 2024 23:05:32 +0530 Subject: [PATCH 2/6] comparing whole default workspace object,instead of each property seperately --- apps/api/src/user/user.e2e.spec.ts | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/apps/api/src/user/user.e2e.spec.ts b/apps/api/src/user/user.e2e.spec.ts index 456a6575..488d3b09 100644 --- a/apps/api/src/user/user.e2e.spec.ts +++ b/apps/api/src/user/user.e2e.spec.ts @@ -109,23 +109,15 @@ describe('User Controller Tests', () => { defaultWorkspace: expect.any(Object) }) - expect(result.json().defaultWorkspace.id).toEqual(workspace.id) - expect(result.json().defaultWorkspace.name).toEqual(workspace.name) - expect(result.json().defaultWorkspace.description).toEqual( - workspace.description - ) - expect(result.json().defaultWorkspace.isFreeTier).toEqual( - workspace.isFreeTier - ) - expect(result.json().defaultWorkspace.createdAt).toEqual( - workspace.createdAt.toISOString() - ) - expect(result.json().defaultWorkspace.updatedAt).toEqual( - workspace.updatedAt.toISOString() - ) - expect(result.json().defaultWorkspace.lastUpdatedById).toEqual( - workspace.lastUpdatedById - ) + expect(result.json().defaultWorkspace).toMatchObject({ + id: workspace.id, + name: workspace.name, + description: workspace.description, + isFreeTier: workspace.isFreeTier, + createdAt: workspace.createdAt.toISOString(), + updatedAt: workspace.updatedAt.toISOString(), + lastUpdatedById: workspace.lastUpdatedById + }) }) it('should have created a default workspace', async () => { From 817ed0901054c6b2873329b9b52acf003052c87e Mon Sep 17 00:00:00 2001 From: Udit Date: Sun, 8 Sep 2024 15:51:22 +0530 Subject: [PATCH 3/6] removed partial select in getSelf func; validating only id and name of defaultworkspace for the same --- apps/api/src/user/service/user.service.ts | 33 ++-- apps/api/src/user/user.e2e.spec.ts | 7 +- .../eslint-config-custom/package-lock.json | 174 ++++++++++++++++++ packages/tsconfig/package-lock.json | 13 ++ 4 files changed, 203 insertions(+), 24 deletions(-) create mode 100644 packages/eslint-config-custom/package-lock.json create mode 100644 packages/tsconfig/package-lock.json diff --git a/apps/api/src/user/service/user.service.ts b/apps/api/src/user/service/user.service.ts index 7a3a7cea..2b185f18 100644 --- a/apps/api/src/user/service/user.service.ts +++ b/apps/api/src/user/service/user.service.ts @@ -30,24 +30,21 @@ export class UserService { } async getSelf(user: User) { - let defaultWorkspace = null - if (!user.isAdmin) { - defaultWorkspace = await this.prisma.workspace.findFirst({ - where: { - ownerId: user.id, - isDefault: true - }, - select: { - id: true, - name: true, - description: true, - isFreeTier: true, - createdAt: true, - updatedAt: true, - lastUpdatedById: true - } - }) - } + const defaultWorkspace = await this.prisma.workspace.findFirst({ + where: { + ownerId: user.id, + isDefault: true + }, + select: { + id: true, + name: true, + description: true, + isFreeTier: true, + createdAt: true, + updatedAt: true, + lastUpdatedById: true + } + }) return { ...user, defaultWorkspace } } diff --git a/apps/api/src/user/user.e2e.spec.ts b/apps/api/src/user/user.e2e.spec.ts index 488d3b09..80dba297 100644 --- a/apps/api/src/user/user.e2e.spec.ts +++ b/apps/api/src/user/user.e2e.spec.ts @@ -111,12 +111,7 @@ describe('User Controller Tests', () => { expect(result.json().defaultWorkspace).toMatchObject({ id: workspace.id, - name: workspace.name, - description: workspace.description, - isFreeTier: workspace.isFreeTier, - createdAt: workspace.createdAt.toISOString(), - updatedAt: workspace.updatedAt.toISOString(), - lastUpdatedById: workspace.lastUpdatedById + name: workspace.name }) }) diff --git a/packages/eslint-config-custom/package-lock.json b/packages/eslint-config-custom/package-lock.json new file mode 100644 index 00000000..49957b9b --- /dev/null +++ b/packages/eslint-config-custom/package-lock.json @@ -0,0 +1,174 @@ +{ + "name": "eslint-config-custom", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "eslint-config-custom", + "version": "0.0.0", + "license": "MIT", + "devDependencies": { + "@vercel/style-guide": "^5.0.0", + "eslint-config-turbo": "^1.10.12", + "typescript": "^4.5.3" + } + }, + "../../node_modules/.pnpm/@vercel+style-guide@5.2.0_@next+eslint-plugin-next@13.5.6_eslint@8.57.0_jest@29.7.0_@types+no_sdq2icpzhfmze3wlrhq5gaoyxi/node_modules/@vercel/style-guide": { + "version": "5.2.0", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "@babel/core": "^7.22.11", + "@babel/eslint-parser": "^7.22.11", + "@rushstack/eslint-patch": "^1.3.3", + "@typescript-eslint/eslint-plugin": "^6.5.0", + "@typescript-eslint/parser": "^6.5.0", + "eslint-config-prettier": "^9.0.0", + "eslint-import-resolver-alias": "^1.1.2", + "eslint-import-resolver-typescript": "^3.6.0", + "eslint-plugin-eslint-comments": "^3.2.0", + "eslint-plugin-import": "^2.28.1", + "eslint-plugin-jest": "^27.2.3", + "eslint-plugin-jsx-a11y": "^6.7.1", + "eslint-plugin-playwright": "^0.16.0", + "eslint-plugin-react": "^7.33.2", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-testing-library": "^6.0.1", + "eslint-plugin-tsdoc": "^0.2.17", + "eslint-plugin-unicorn": "^48.0.1", + "prettier-plugin-packagejson": "^2.4.5" + }, + "devDependencies": { + "@commitlint/cli": "^17.7.1", + "@commitlint/config-conventional": "^17.7.0", + "@semantic-release/git": "^10.0.1", + "eslint": "^8.48.0", + "husky": "^8.0.3", + "lint-staged": "^14.0.1", + "prettier": "^3.0.2", + "semantic-release": "^21.1.1", + "typescript": "^5.2.2" + }, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "@next/eslint-plugin-next": ">=12.3.0 <15", + "eslint": ">=8.48.0 <9", + "prettier": ">=3.0.0 <4", + "typescript": ">=4.8.0 <6" + }, + "peerDependenciesMeta": { + "@next/eslint-plugin-next": { + "optional": true + }, + "eslint": { + "optional": true + }, + "prettier": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, + "../../node_modules/.pnpm/eslint-config-turbo@1.13.4_eslint@8.57.0/node_modules/eslint-config-turbo": { + "version": "1.13.4", + "dev": true, + "license": "MPL-2.0", + "dependencies": { + "eslint-plugin-turbo": "1.13.4" + }, + "devDependencies": { + "@turbo/eslint-config": "0.0.0", + "@types/eslint": "^8.44.2" + }, + "peerDependencies": { + "eslint": ">6.6.0" + } + }, + "../../node_modules/.pnpm/typescript@4.9.5/node_modules/typescript": { + "version": "4.9.5", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "devDependencies": { + "@octokit/rest": "latest", + "@types/chai": "latest", + "@types/fancy-log": "^2.0.0", + "@types/fs-extra": "^9.0.13", + "@types/glob": "latest", + "@types/gulp": "^4.0.9", + "@types/gulp-concat": "latest", + "@types/gulp-newer": "latest", + "@types/gulp-rename": "latest", + "@types/gulp-sourcemaps": "latest", + "@types/merge2": "latest", + "@types/microsoft__typescript-etw": "latest", + "@types/minimist": "latest", + "@types/mkdirp": "latest", + "@types/mocha": "latest", + "@types/ms": "latest", + "@types/node": "latest", + "@types/source-map-support": "latest", + "@types/which": "^2.0.1", + "@types/xml2js": "^0.4.11", + "@typescript-eslint/eslint-plugin": "^5.33.1", + "@typescript-eslint/parser": "^5.33.1", + "@typescript-eslint/utils": "^5.33.1", + "azure-devops-node-api": "^11.2.0", + "chai": "latest", + "chalk": "^4.1.2", + "del": "^6.1.1", + "diff": "^5.1.0", + "eslint": "^8.22.0", + "eslint-formatter-autolinkable-stylish": "^1.2.0", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-jsdoc": "^39.3.6", + "eslint-plugin-local": "^1.0.0", + "eslint-plugin-no-null": "^1.0.2", + "fancy-log": "latest", + "fs-extra": "^9.1.0", + "glob": "latest", + "gulp": "^4.0.2", + "gulp-concat": "latest", + "gulp-insert": "latest", + "gulp-newer": "latest", + "gulp-rename": "latest", + "gulp-sourcemaps": "latest", + "merge2": "latest", + "minimist": "latest", + "mkdirp": "latest", + "mocha": "latest", + "mocha-fivemat-progress-reporter": "latest", + "ms": "^2.1.3", + "node-fetch": "^3.2.10", + "source-map-support": "latest", + "typescript": "^4.8.4", + "vinyl": "latest", + "which": "^2.0.2", + "xml2js": "^0.4.23" + }, + "engines": { + "node": ">=4.2.0" + } + }, + "node_modules/@vercel/style-guide": { + "resolved": "../../node_modules/.pnpm/@vercel+style-guide@5.2.0_@next+eslint-plugin-next@13.5.6_eslint@8.57.0_jest@29.7.0_@types+no_sdq2icpzhfmze3wlrhq5gaoyxi/node_modules/@vercel/style-guide", + "link": true + }, + "node_modules/eslint-config-turbo": { + "resolved": "../../node_modules/.pnpm/eslint-config-turbo@1.13.4_eslint@8.57.0/node_modules/eslint-config-turbo", + "link": true + }, + "node_modules/typescript": { + "resolved": "../../node_modules/.pnpm/typescript@4.9.5/node_modules/typescript", + "link": true + } + } +} diff --git a/packages/tsconfig/package-lock.json b/packages/tsconfig/package-lock.json new file mode 100644 index 00000000..b5f3c5d1 --- /dev/null +++ b/packages/tsconfig/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "tsconfig", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "tsconfig", + "version": "0.0.0", + "license": "MIT" + } + } +} From 3c6645f391a0c7b0d1260a09c1711d93b7ef13ac Mon Sep 17 00:00:00 2001 From: Udit Date: Sun, 8 Sep 2024 17:08:41 +0530 Subject: [PATCH 4/6] added package lock json in gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ab84fc8c..4a1572b2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ tmp # dependencies node_modules - +package-lock.json # IDEs and editors /.idea .project From a1dd53fba97fe225380db89965f8ab6111fdd6e2 Mon Sep 17 00:00:00 2001 From: Udit Date: Sun, 8 Sep 2024 17:13:13 +0530 Subject: [PATCH 5/6] fetching just workplace id and name in getself func --- apps/api/src/user/service/user.service.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/apps/api/src/user/service/user.service.ts b/apps/api/src/user/service/user.service.ts index 2b185f18..74ba438b 100644 --- a/apps/api/src/user/service/user.service.ts +++ b/apps/api/src/user/service/user.service.ts @@ -37,12 +37,7 @@ export class UserService { }, select: { id: true, - name: true, - description: true, - isFreeTier: true, - createdAt: true, - updatedAt: true, - lastUpdatedById: true + name: true } }) From 31992774ecd1b2463d3782267bcc3d9e7fe2733e Mon Sep 17 00:00:00 2001 From: Udit Date: Sun, 8 Sep 2024 18:56:00 +0530 Subject: [PATCH 6/6] sending full workspace details instead of partial select in getself func --- apps/api/src/user/service/user.service.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/api/src/user/service/user.service.ts b/apps/api/src/user/service/user.service.ts index 74ba438b..7b1a3093 100644 --- a/apps/api/src/user/service/user.service.ts +++ b/apps/api/src/user/service/user.service.ts @@ -6,7 +6,7 @@ import { UnauthorizedException } from '@nestjs/common' import { UpdateUserDto } from '../dto/update.user/update.user' -import { AuthProvider, User } from '@prisma/client' +import { AuthProvider, User, Workspace } from '@prisma/client' import { PrismaService } from '@/prisma/prisma.service' import { CreateUserDto } from '../dto/create.user/create.user' import { IMailService, MAIL_SERVICE } from '@/mail/services/interface.service' @@ -30,16 +30,13 @@ export class UserService { } async getSelf(user: User) { - const defaultWorkspace = await this.prisma.workspace.findFirst({ - where: { - ownerId: user.id, - isDefault: true - }, - select: { - id: true, - name: true - } - }) + const defaultWorkspace: Workspace | null = + await this.prisma.workspace.findFirst({ + where: { + ownerId: user.id, + isDefault: true + } + }) return { ...user, defaultWorkspace } }