Skip to content

Commit

Permalink
feat(api): Included default workspace details in getSelf function (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
unamdev0 authored Sep 9, 2024
1 parent 907e369 commit e67bbd6
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tmp

# dependencies
node_modules

package-lock.json
# IDEs and editors
/.idea
.project
Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/user/service/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,7 +30,15 @@ export class UserService {
}

async getSelf(user: User) {
return user
const defaultWorkspace: Workspace | null =
await this.prisma.workspace.findFirst({
where: {
ownerId: user.id,
isDefault: true
}
})

return { ...user, defaultWorkspace }
}

async updateSelf(user: User, dto: UpdateUserDto) {
Expand Down
19 changes: 17 additions & 2 deletions apps/api/src/user/user.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ describe('User Controller Tests', () => {
})
expect(result.statusCode).toEqual(200)
expect(JSON.parse(result.body)).toEqual({
...adminUser
...adminUser,
defaultWorkspace: null
})
})

Expand All @@ -94,9 +95,23 @@ 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).toMatchObject({
id: workspace.id,
name: workspace.name
})
})

Expand Down
174 changes: 174 additions & 0 deletions packages/eslint-config-custom/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/tsconfig/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e67bbd6

Please sign in to comment.