diff --git a/src/common/entities/base.entity.ts b/src/common/entities/base.entity.ts index 8d5b529..844aa53 100755 --- a/src/common/entities/base.entity.ts +++ b/src/common/entities/base.entity.ts @@ -1,4 +1,4 @@ -import { PrimaryKey, Property, sql, Filter, OptionalProps } from '@mikro-orm/core'; +import { PrimaryKey, Property, Filter, OptionalProps } from '@mikro-orm/core'; import { ulid } from 'ulid'; @Filter({ name: 'notDeleted', cond: { deletedAt: null }, default: true }) @@ -8,7 +8,7 @@ export abstract class BaseEntity { @PrimaryKey({ type: 'string', columnType: 'char(26)' }) id: string = ulid(); - @Property({ default: sql.now(), type: 'timestamptz' }) + @Property({ defaultRaw: 'now()', columnType: 'timestamptz' }) createdAt: Date = new Date(); @Property({ diff --git a/src/modules/users/dto/find-user.dto.ts b/src/modules/users/dto/find-user.dto.ts index 3b7de24..8e60665 100644 --- a/src/modules/users/dto/find-user.dto.ts +++ b/src/modules/users/dto/find-user.dto.ts @@ -1,7 +1,7 @@ -import { IsOptional, IsString, IsNumber, Min, IsEnum, IsIn } from 'class-validator'; +import { IsOptional, IsString, IsNumber, Min, IsIn } from 'class-validator'; import { Type } from 'class-transformer'; -import { ApiPropertyOptional } from '@nestjs/swagger'; -import { EducationLevel, User } from '../entities/user.entity'; +import { ApiPropertyOptional } from '@nestjs/swagger'; +import { User } from '../entities/user.entity'; // Define the valid sort directions const sortOrderOptions = ['asc', 'desc'] as const; @@ -53,18 +53,6 @@ export class FindUsersDto { @IsString() search?: string; - /** - * Filter by a specific education level. - */ - @ApiPropertyOptional({ - description: 'Filter by a specific education level.', - enum: EducationLevel, // Use the actual enum - example: EducationLevel.bachelor, - }) - @IsOptional() - @IsEnum(EducationLevel) - education?: EducationLevel; - /** * The field to sort the results by. * @default "createdAt" diff --git a/src/modules/users/dto/update-user.dto.ts b/src/modules/users/dto/update-user.dto.ts index f2bdfce..7d959c8 100644 --- a/src/modules/users/dto/update-user.dto.ts +++ b/src/modules/users/dto/update-user.dto.ts @@ -1,6 +1,5 @@ -import { IsString, IsNotEmpty, IsBoolean, IsNumber, IsEnum, MinLength } from 'class-validator'; +import { IsString, IsNotEmpty, IsBoolean, IsNumber, MinLength } from 'class-validator'; import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { EducationLevel } from '../entities/user.entity'; export class UpdateUserDto { @ApiProperty({ example: ' ', description: "User's first name" }) @@ -51,13 +50,4 @@ export class UpdateUserDto { @IsNotEmpty() @IsNumber() workExperienceYear: number; - - @ApiPropertyOptional({ - enum: EducationLevel, - example: EducationLevel.master, - description: 'Highest level of education achieved', - }) - @IsNotEmpty() - @IsEnum(EducationLevel) - education: EducationLevel; } diff --git a/src/modules/users/entities/user.entity.ts b/src/modules/users/entities/user.entity.ts index bf671b9..cacb7ed 100644 --- a/src/modules/users/entities/user.entity.ts +++ b/src/modules/users/entities/user.entity.ts @@ -1,5 +1,6 @@ -import { Entity, Property, BaseEntity, OneToMany, Collection } from '@mikro-orm/core'; +import { Entity, Property, OneToMany, Collection } from '@mikro-orm/core'; import { RefreshToken } from './refresh-token.entity'; +import { BaseEntity } from 'src/common/entities/base.entity'; @Entity({ tableName: 'users' }) export class User extends BaseEntity { @@ -13,7 +14,7 @@ export class User extends BaseEntity { phone!: string; @Property({ default: true }) - isActive: boolean = true; + isActive?: boolean; @OneToMany(() => RefreshToken, token => token.user) refreshTokens = new Collection(this); diff --git a/src/modules/users/user.controller.ts b/src/modules/users/user.controller.ts index 92bef0b..ca9e439 100644 --- a/src/modules/users/user.controller.ts +++ b/src/modules/users/user.controller.ts @@ -1,8 +1,8 @@ -import { Controller, Get, Patch, Body, Req, UseGuards, Query, ValidationPipe } from '@nestjs/common'; -import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody } from '@nestjs/swagger'; +import { Controller, Get, Req, UseGuards, Query, ValidationPipe } from '@nestjs/common'; +import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; import { AuthGuard, type AuthRequest } from 'src/modules/auth/guards/auth.guard'; import { UserService } from './user.service'; -import { UpdateUserDto } from './dto/update-user.dto'; +// import { UpdateUserDto } from './dto/update-user.dto'; import { FindUsersDto } from './dto/find-user.dto'; import { AdminAuthGuard } from 'src/modules/auth/guards/auth.admin.guard'; @@ -17,7 +17,7 @@ export class UserController { @Get('/') async getUser(@Req() req: AuthRequest) { const userId = req.user.sub; - const user = await this.userService.findById(+userId); + const user = await this.userService.findById(userId); return { message: `GET request: Retrieving profile for authenticated user `, user, @@ -25,20 +25,20 @@ export class UserController { } // 2. Update User Specification (PATCH /user/spec) - @UseGuards(AuthGuard) - @ApiBearerAuth() - @ApiOperation({ summary: 'Update the user specification' }) - @ApiBody({ type: UpdateUserDto }) - @Patch('/') - async updateUserSpec(@Req() req: AuthRequest, @Body() dto: UpdateUserDto) { - const userId = req.user.sub; - const user = await this.userService.updateUser(+userId, dto); - return { - message: `PATCH request: Updating specification for user ${userId} `, - userId, - user, - }; - } + // @UseGuards(AuthGuard) + // @ApiBearerAuth() + // @ApiOperation({ summary: 'Update the user specification' }) + // @ApiBody({ type: UpdateUserDto }) + // @Patch('/') + // async updateUserSpec(@Req() req: AuthRequest, @Body() dto: UpdateUserDto) { + // const userId = req.user.sub; + // const user = await this.userService.updateUser(userId, dto); + // return { + // message: `PATCH request: Updating specification for user ${userId} `, + // userId, + // user, + // }; + // } @UseGuards(AdminAuthGuard) @ApiBearerAuth() diff --git a/src/modules/users/user.service.ts b/src/modules/users/user.service.ts index 1313df9..5afc9db 100644 --- a/src/modules/users/user.service.ts +++ b/src/modules/users/user.service.ts @@ -3,7 +3,7 @@ import { InjectRepository } from '@mikro-orm/nestjs'; import { EntityRepository, FilterQuery } from '@mikro-orm/core'; import { User } from './entities/user.entity'; import { EntityManager } from '@mikro-orm/postgresql'; -import { UpdateUserDto } from './dto/update-user.dto'; +// import { UpdateUserDto } from './dto/update-user.dto'; import { FindUsersDto } from './dto/find-user.dto'; import { PaginatedResult } from 'src/common/interfaces/pagination.interface';