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