实现管理段用户增删改查改密码
This commit is contained in:
@@ -4,12 +4,14 @@ import { AdminUserController } from './controller/admin-user.controller';
|
||||
import { AdminUserService } from './service/admin-user.service';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from 'src/user/entities/user.entity';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
User,
|
||||
])
|
||||
]),
|
||||
UserModule,
|
||||
],
|
||||
controllers: [
|
||||
AdminController,
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { Controller, Get, Query } from "@nestjs/common";
|
||||
import { Body, Controller, Delete, Get, Param, ParseUUIDPipe, Post, Put, Query } from "@nestjs/common";
|
||||
import { AdminUserService } from "../service/admin-user.service";
|
||||
import { ListDto } from "../dto/admin-user/list.dto";
|
||||
import { CreateDto } from "../dto/admin-user/create.dto";
|
||||
import { UserService } from "src/user/user.service";
|
||||
import { UpdateDto } from "../dto/admin-user/update.dto";
|
||||
import { UpdatePasswordDto } from "../dto/admin-user/update-password.dto";
|
||||
|
||||
@Controller('admin/user')
|
||||
export class AdminUserController {
|
||||
|
||||
constructor(
|
||||
private readonly adminUserService: AdminUserService,
|
||||
private readonly userService: UserService,
|
||||
) { }
|
||||
|
||||
@Get()
|
||||
@@ -15,4 +20,34 @@ export class AdminUserController {
|
||||
) {
|
||||
return this.adminUserService.getUser(listDto.page, listDto.pageSize);
|
||||
}
|
||||
|
||||
@Post()
|
||||
async create(
|
||||
@Body() createDto: CreateDto
|
||||
) {
|
||||
return this.userService.create(createDto);
|
||||
}
|
||||
|
||||
@Put(':userId')
|
||||
async update(
|
||||
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
|
||||
@Body() updateDto: UpdateDto,
|
||||
) {
|
||||
return this.userService.update(userId, updateDto);
|
||||
}
|
||||
|
||||
@Delete(':userId')
|
||||
async delete(
|
||||
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
|
||||
) {
|
||||
return this.userService.delete(userId);
|
||||
}
|
||||
|
||||
@Post(':userId/password')
|
||||
async setPassword(
|
||||
@Param('userId', new ParseUUIDPipe({ version: '4' })) userId: string,
|
||||
@Body() updatePasswordDto: UpdatePasswordDto,
|
||||
) {
|
||||
return this.userService.setPassword(userId, updatePasswordDto.password);
|
||||
}
|
||||
}
|
||||
23
tone-page-server/src/admin/dto/admin-user/create.dto.ts
Normal file
23
tone-page-server/src/admin/dto/admin-user/create.dto.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class CreateDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
nickname?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
avatar?: string;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IsString, Length, Matches } from "class-validator";
|
||||
|
||||
export class UpdatePasswordDto {
|
||||
@IsString()
|
||||
@Length(6, 32)
|
||||
@Matches(/^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/)
|
||||
password: string;
|
||||
}
|
||||
23
tone-page-server/src/admin/dto/admin-user/update.dto.ts
Normal file
23
tone-page-server/src/admin/dto/admin-user/update.dto.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { IsOptional, IsString } from "class-validator";
|
||||
|
||||
export class UpdateDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
username?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
nickname?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
email?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
phone?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
avatar?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user