user service
This commit is contained in:
+7
-1
@@ -6,7 +6,13 @@ async function bootstrap() {
|
|||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
// Global validation pipe
|
// Global validation pipe
|
||||||
app.useGlobalPipes(new ValidationPipe());
|
app.useGlobalPipes(
|
||||||
|
new ValidationPipe({
|
||||||
|
whitelist: true,
|
||||||
|
forbidNonWhitelisted: true,
|
||||||
|
transform: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
// Global prefix
|
// Global prefix
|
||||||
app.setGlobalPrefix('api');
|
app.setGlobalPrefix('api');
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { IsOptional, IsString, Length } from 'class-validator';
|
||||||
IsEnum,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
Length,
|
|
||||||
Matches,
|
|
||||||
} from 'class-validator';
|
|
||||||
import { UserRole } from '../enums/user-role.enum';
|
|
||||||
|
|
||||||
export class UpdateUserDto {
|
export class UpdateUserDto {
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -17,12 +10,4 @@ export class UpdateUserDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@Length(1, 100)
|
@Length(1, 100)
|
||||||
lastName?: string;
|
lastName?: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@Matches(/^09\d{9}$/)
|
|
||||||
mobile?: string;
|
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsEnum(UserRole)
|
|
||||||
role?: UserRole;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,6 @@ export class UsersService {
|
|||||||
|
|
||||||
async update(id: string, updateUserDto: UpdateUserDto): Promise<User> {
|
async update(id: string, updateUserDto: UpdateUserDto): Promise<User> {
|
||||||
const user = await this.findOne(id);
|
const user = await this.findOne(id);
|
||||||
if (updateUserDto.mobile) {
|
|
||||||
await this.ensureMobileIsUnique(updateUserDto.mobile, id);
|
|
||||||
}
|
|
||||||
Object.assign(user, updateUserDto);
|
Object.assign(user, updateUserDto);
|
||||||
return this.usersRepository.save(user);
|
return this.usersRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user