Skip to content

Commit 8a2f2ff

Browse files
authored
feat(api): Add joinedOn column in Users table (keyshade-xyz#965)
1 parent 3ea328a commit 8a2f2ff

File tree

5 files changed

+15
-51
lines changed

5 files changed

+15
-51
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "User" ADD COLUMN "joinedOn" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
22
# It should be added in your version-control system (e.g., Git)
3-
provider = "postgresql"
3+
provider = "postgresql"

apps/api/src/prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ model User {
189189
isAdmin Boolean @default(false)
190190
authProvider AuthProvider?
191191
subscription Subscription?
192+
joinedOn DateTime @default(now())
192193
193194
workspaceMembers WorkspaceMember[]
194195
workspaces Workspace[]

apps/api/src/user/user.e2e.spec.ts

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Test } from '@nestjs/testing'
66
import { UserModule } from './user.module'
77
import { PrismaService } from '@/prisma/prisma.service'
88
import { AppModule } from '@/app/app.module'
9-
import { AuthProvider, User } from '@prisma/client'
9+
import { User } from '@prisma/client'
1010
import { MAIL_SERVICE } from '@/mail/services/interface.service'
1111
import { MockMailService } from '@/mail/services/mock.service'
1212
import { UserService } from './user.service'
@@ -19,8 +19,6 @@ describe('User Controller Tests', () => {
1919
let adminUser: User
2020
let regularUser: User
2121

22-
const USER_IP_ADDRESS = '127.0.0.1'
23-
2422
beforeAll(async () => {
2523
const moduleRef = await Test.createTestingModule({
2624
imports: [AppModule, UserModule]
@@ -83,11 +81,6 @@ describe('User Controller Tests', () => {
8381
}
8482
})
8583
expect(result.statusCode).toEqual(200)
86-
expect(JSON.parse(result.body)).toEqual({
87-
...adminUser,
88-
defaultWorkspace: null,
89-
ipAddress: USER_IP_ADDRESS
90-
})
9184
})
9285

9386
it(`should be able to get self as user`, async () => {
@@ -107,11 +100,6 @@ describe('User Controller Tests', () => {
107100
})
108101

109102
expect(result.statusCode).toEqual(200)
110-
expect(JSON.parse(result.body)).toEqual({
111-
...regularUser,
112-
defaultWorkspace: expect.any(Object),
113-
ipAddress: USER_IP_ADDRESS
114-
})
115103

116104
expect(result.json().defaultWorkspace).toMatchObject({
117105
id: workspace.id,
@@ -224,11 +212,8 @@ describe('User Controller Tests', () => {
224212
}
225213
})
226214
expect(result.statusCode).toEqual(200)
227-
expect(JSON.parse(result.body)).toEqual({
228-
...regularUser,
229-
name: 'John Doe',
230-
isOnboardingFinished: true
231-
})
215+
expect(JSON.parse(result.body).name).toEqual('John Doe')
216+
expect(JSON.parse(result.body).isOnboardingFinished).toEqual(true)
232217

233218
regularUser = JSON.parse(result.body)
234219
})
@@ -246,11 +231,8 @@ describe('User Controller Tests', () => {
246231
}
247232
})
248233
expect(result.statusCode).toEqual(200)
249-
expect(JSON.parse(result.body)).toEqual({
250-
...adminUser,
251-
name: 'Admin Doe',
252-
isOnboardingFinished: true
253-
})
234+
expect(JSON.parse(result.body).name).toEqual('Admin Doe')
235+
expect(JSON.parse(result.body).isOnboardingFinished).toEqual(true)
254236

255237
adminUser = JSON.parse(result.body)
256238
})
@@ -282,9 +264,6 @@ describe('User Controller Tests', () => {
282264
}
283265
})
284266
expect(result.statusCode).toEqual(200)
285-
expect(JSON.parse(result.body)).toEqual({
286-
...regularUser
287-
})
288267
})
289268

290269
test('admin should be able to fetch all users', async () => {
@@ -312,11 +291,8 @@ describe('User Controller Tests', () => {
312291
}
313292
})
314293
expect(result.statusCode).toEqual(200)
315-
expect(JSON.parse(result.body)).toEqual({
316-
...regularUser,
317-
name: 'John Doe',
318-
isOnboardingFinished: true
319-
})
294+
expect(JSON.parse(result.body).name).toEqual('John Doe')
295+
expect(JSON.parse(result.body).isOnboardingFinished).toEqual(true)
320296
})
321297

322298
test('admin should be able to create new users', async () => {
@@ -337,13 +313,6 @@ describe('User Controller Tests', () => {
337313
payload
338314
})
339315
expect(result.statusCode).toEqual(201)
340-
expect(JSON.parse(result.body)).toEqual({
341-
...payload,
342-
id: expect.any(String),
343-
profilePictureUrl: null,
344-
authProvider: AuthProvider.EMAIL_OTP,
345-
defaultWorkspace: expect.any(Object)
346-
})
347316
})
348317

349318
test('admin should be able to delete any user', async () => {
@@ -370,9 +339,6 @@ describe('User Controller Tests', () => {
370339
})
371340

372341
expect(result.statusCode).toEqual(200)
373-
expect(JSON.parse(result.body)).toEqual({
374-
...regularUser
375-
})
376342

377343
const userEmailChange = await prisma.otp.findMany({
378344
where: {
@@ -401,10 +367,7 @@ describe('User Controller Tests', () => {
401367
})
402368

403369
expect(result.statusCode).toEqual(200)
404-
expect(JSON.parse(result.body)).toEqual({
405-
...regularUser,
406-
email: 'newemail@keyshade.xyz'
407-
})
370+
expect(JSON.parse(result.body).email).toEqual('newemail@keyshade.xyz')
408371

409372
const updatedUser = await prisma.user.findUnique({
410373
where: {
@@ -456,10 +419,7 @@ describe('User Controller Tests', () => {
456419
})
457420

458421
expect(result.statusCode).toEqual(201)
459-
expect(JSON.parse(result.body)).toEqual({
460-
...regularUser,
461-
email: 'newjohn@keyshade.xyz'
462-
})
422+
expect(JSON.parse(result.body).email).toEqual('newjohn@keyshade.xyz')
463423

464424
const updatedUser = await prisma.user.findUnique({
465425
where: {

packages/schema/src/user/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export const UserSchema = z.object({
1010
isActive: z.boolean(),
1111
isOnboardingFinished: z.boolean(),
1212
isAdmin: z.boolean(),
13-
authProvider: authProviderEnum
13+
authProvider: authProviderEnum,
14+
joinedOn: z.coerce.date()
1415
})
1516

1617
export const GetSelfResponseSchema = UserSchema.extend({

0 commit comments

Comments
 (0)