update
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { EntityRepository, FilterQuery } from '@mikro-orm/core';
|
||||
import { User, UserStatus } from './entities/user.entity';
|
||||
import { User } from './entities/user.entity';
|
||||
import { EntityManager } from '@mikro-orm/postgresql';
|
||||
import { UpdateUserDto } from './dto/update-user.dto';
|
||||
import { FindUsersDto } from './dto/find-user.dto';
|
||||
@@ -28,23 +28,23 @@ export class UserService {
|
||||
return user;
|
||||
}
|
||||
|
||||
async updateUser(userId: number, dto: UpdateUserDto): Promise<User> {
|
||||
const user = await this.em.findOneOrFail(User, userId, {}).catch(() => {
|
||||
throw new NotFoundException(`User with ID ${userId} not found.`);
|
||||
});
|
||||
// async updateUser(userId: string, dto: UpdateUserDto): Promise<User> {
|
||||
// const user = await this.em.findOneOrFail(User, userId, {}).catch(() => {
|
||||
// throw new NotFoundException(`User with ID ${userId} not found.`);
|
||||
// });
|
||||
|
||||
this.em.assign(user, { ...dto, status: UserStatus.finished });
|
||||
// this.em.assign(user, { ...dto });
|
||||
|
||||
await this.em.flush();
|
||||
// await this.em.flush();
|
||||
|
||||
return user;
|
||||
}
|
||||
// return user;
|
||||
// }
|
||||
|
||||
async findByPhone(phone: string): Promise<User | null> {
|
||||
return this.userRepository.findOne({ phone });
|
||||
}
|
||||
|
||||
async findById(id: number): Promise<User | null> {
|
||||
async findById(id: string): Promise<User | null> {
|
||||
return this.userRepository.findOne({ id });
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
async findAll(dto: FindUsersDto): Promise<PaginatedResult<User>> {
|
||||
const { page = 1, limit = 10, search, education, orderBy = 'createdAt', order = 'desc' } = dto;
|
||||
const { page = 1, limit = 10, search, orderBy = 'createdAt', order = 'desc' } = dto;
|
||||
|
||||
// 1. Calculate pagination
|
||||
const offset = (page - 1) * limit;
|
||||
@@ -63,10 +63,6 @@ export class UserService {
|
||||
// 2. Build the 'where' filter query
|
||||
const where: FilterQuery<User> = {};
|
||||
|
||||
if (education) {
|
||||
where.education = education;
|
||||
}
|
||||
|
||||
// 4. Add 'search' logic (case-insensitive)
|
||||
if (search) {
|
||||
const searchPattern = `%${search}%`;
|
||||
@@ -75,8 +71,6 @@ export class UserService {
|
||||
{ firstName: { $ilike: searchPattern } },
|
||||
{ lastName: { $ilike: searchPattern } },
|
||||
{ phone: { $ilike: searchPattern } },
|
||||
{ nationalCode: { $ilike: searchPattern } },
|
||||
{ personalCode: { $ilike: searchPattern } },
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user