Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(API): Included default workspace details in getSelf function #414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
rajdip-b marked this conversation as resolved.
Show resolved Hide resolved
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.

Loading