apps/api:add UpdateAccountDto
This commit is contained in:
parent
01f4378e11
commit
f8c78bfa40
@ -4,6 +4,7 @@
|
||||
import { AccountService } from './account.service';
|
||||
import { CreateAccountDto } from './dto/create-account.dto';
|
||||
import { ResetPasswordDto } from './dto/reset-password.dto';
|
||||
import { UpdateAccountDto } from './dto/update-account.dto';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
@ -75,9 +76,9 @@ export class AccountController {
|
||||
status: HttpStatus.OK,
|
||||
type: Account,
|
||||
})
|
||||
async update(@Body() createAccountDto: CreateAccountDto, @Res() reply: FastifyReply) {
|
||||
async update(@Body() updateAccountDto: UpdateAccountDto, @Res() reply: FastifyReply) {
|
||||
try {
|
||||
const updatedAccount = await this.accountService.update(createAccountDto);
|
||||
const updatedAccount = await this.accountService.update(updateAccountDto);
|
||||
|
||||
return reply.status(HttpStatus.OK).send(updatedAccount);
|
||||
} catch (error) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import type { CreateAccountDto } from './dto/create-account.dto';
|
||||
import type { ResetPasswordDto } from './dto/reset-password.dto';
|
||||
import type { UpdateAccountDto } from './dto/update-account.dto';
|
||||
import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
@ -48,7 +49,7 @@ export class AccountService {
|
||||
return this.accountModel.findOneAndDelete({ username }).exec();
|
||||
}
|
||||
|
||||
public async update({ username, ...props }: CreateAccountDto): Promise<Account> {
|
||||
public async update({ username, ...props }: UpdateAccountDto): Promise<Account> {
|
||||
Object.keys(props).forEach((field) => {
|
||||
if (['_id', '__v', 'password'].includes(field))
|
||||
throw new BadRequestException(`Prop ${field} is not allowed`);
|
||||
|
||||
11
apps/api/src/account/dto/update-account.dto.ts
Normal file
11
apps/api/src/account/dto/update-account.dto.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class UpdateAccountDto {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public readonly username: string;
|
||||
|
||||
readonly [key: string]: unknown;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user