Skip to content

Commit

Permalink
chore(api): Minor updates to user service
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Jul 29, 2024
1 parent 232a589 commit 249d778
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 69 deletions.
50 changes: 0 additions & 50 deletions apps/api/src/user/dto/create.user/create.user.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,27 @@
import { ApiProperty } from '@nestjs/swagger'
import { IsBoolean, IsEmail, IsOptional, IsString } from 'class-validator'

export class CreateUserDto {
@IsString()
@IsOptional()
@ApiProperty({
name: 'name',
description: 'Full name of the user',
required: false,
type: String,
example: 'John Doe',
default: null
})
name?: string

@IsString()
@IsEmail()
@ApiProperty({
name: 'email',
description: 'Email of the user',
required: true,
type: String,
example: 'johndoe@keyshade.xyz',
format: 'email',
uniqueItems: true
})
email: string

@IsString()
@IsOptional()
@ApiProperty({
name: 'profilePictureUrl',
description: 'URL of the user profile picture',
required: false,
type: String,
example: 'https://example.com/profile.jpg',
default: null
})
profilePictureUrl?: string

@IsBoolean()
@IsOptional()
@ApiProperty({
name: 'isActive',
description: 'Is the user active',
required: false,
type: Boolean,
example: true,
default: true
})
isActive?: boolean

@IsBoolean()
@IsOptional()
@ApiProperty({
name: 'isOnboardingFinished',
description: 'Is the user onboarding finished',
required: false,
type: Boolean,
example: true,
default: false
})
isOnboardingFinished?: boolean

@IsBoolean()
@IsOptional()
@ApiProperty({
name: 'isAdmin',
description: 'Is the user an admin',
required: false,
type: Boolean,
example: false,
default: false
})
isAdmin?: boolean
}
27 changes: 8 additions & 19 deletions apps/api/src/user/service/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import {
ConflictException,
Inject,
Injectable,
Logger,
UnauthorizedException
} from '@nestjs/common'
import { ConflictException, Inject, Injectable, Logger, UnauthorizedException } from '@nestjs/common'
import { UpdateUserDto } from '../dto/update.user/update.user'
import { AuthProvider, User } 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'
import { IMailService, MAIL_SERVICE } from '../../mail/services/interface.service'
import createUser from '../../common/create-user'
import generateOtp from '../../common/generate-otp'
import { EnvSchema } from '../../common/env/env.schema'
Expand Down Expand Up @@ -72,14 +63,12 @@ export class UserService {
}

this.log.log(`Updating user ${user.id} with data ${dto}`)
const updatedUser = await this.prisma.user.update({
return this.prisma.user.update({
where: {
id: user.id
},
data
})

return updatedUser
}

async updateUser(userId: string, dto: UpdateUserDto) {
Expand Down Expand Up @@ -116,7 +105,7 @@ export class UserService {
}

this.log.log(`Updating user ${userId} with data ${dto}`)
return await this.prisma.user.update({
return this.prisma.user.update({
where: {
id: userId
},
Expand Down Expand Up @@ -202,7 +191,7 @@ export class UserService {
}

async getUserById(userId: string) {
return await this.prisma.user.findUnique({
return this.prisma.user.findUnique({
where: {
id: userId
}
Expand All @@ -216,7 +205,7 @@ export class UserService {
order: string,
search: string
): Promise<User[]> {
return await this.prisma.user.findMany({
return this.prisma.user.findMany({
skip: (page - 1) * limit,
take: limit,
orderBy: {
Expand All @@ -240,11 +229,11 @@ export class UserService {
}

async deleteSelf(user: User) {
this.deleteUserById(user.id)
await this.deleteUserById(user.id)
}

async deleteUser(userId: User['id']) {
this.deleteUserById(userId)
await this.deleteUserById(userId)
}

private async deleteUserById(userId: User['id']) {
Expand Down

0 comments on commit 249d778

Please sign in to comment.