This commit is contained in:
2025-11-10 23:00:59 +03:30
parent bca4b75b6a
commit 6a25bf9116
6 changed files with 28 additions and 49 deletions
+2 -2
View File
@@ -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({
+3 -15
View File
@@ -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"
+1 -11
View File
@@ -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;
}
+3 -2
View File
@@ -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<RefreshToken>(this);
+18 -18
View File
@@ -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()
+1 -1
View File
@@ -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';