Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加ITreeNode字段/新增role接口/新增getUser分页 #144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/toolkits/pro/template/server/nestJs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ REDIS_HOST = 'localhost'
REDIS_PORT = 6379

EXPIRES_IN = '2h'

PAGINATION_PAGE = 1
PAGINATION_LIMIT = 10
1 change: 1 addition & 0 deletions packages/toolkits/pro/template/server/nestJs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"dotenv": "^16.4.5",
"ioredis": "^5.4.1",
"mysql2": "3.4.3",
"nestjs-typeorm-paginate": "^4.0.4",
"redis": "^4.6.15",
"reflect-metadata": "0.1.13",
"rimraf": "5.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AuthService {
async login(dto: CreateAuthDto) {
const { email, password } = dto;
const userInfo = await this.user.findOne({ where: { email } });
if (userInfo === null || userInfo.deleteAt !== null) {
if (userInfo === null || userInfo.deleteAt != 0) {
throw new HttpException('该用户不存在', HttpStatus.NOT_FOUND);
}
if (encry(password, userInfo.salt) !== userInfo.password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export interface ITreeNodeData {
// 子节点
children?: ITreeNodeData[];
// 链接
url?: string;
url: string;
//组件
component: string;
}

interface MenuMap {
Expand All @@ -27,6 +29,7 @@ const toNode = (menu: Menu): ITreeNodeData => {
id: menu.id,
children: [],
url: menu.path,
component: menu.component,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@ export class RoleController {
deleteRole(@Body() dto: DeleteRoleDto) {
return this.roleService.delete(dto);
}

@Permission('role::get')
@Get('/info/:id')
getRoleInfo(@Param('id') id: string) {
return this.roleService.findOne(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ export class RoleService {
findAll() {
return this.role.find();
}

async findOne(id: string) {
const roleInfo = await this.role.find({
where: {
id: parseInt(id),
},
});
if (roleInfo.length===0) {
throw new HttpException('角色不存在', HttpStatus.NOT_FOUND);
}
return roleInfo;
}

async update(data: UpdateRoleDto) {
const permission = await this.permission.find({
where: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IsOptional } from 'class-validator';

export class PaginationQueryDto {
@IsOptional()
page?: number;

@IsOptional()
limit?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { Permission } from '../public/permission.decorator';
import { UpdateUserDto } from './dto/update-user.dto';
import { PaginationQueryDto } from './dto/pagination-query.dto'

@Controller('user')
export class UserController {
Expand All @@ -38,7 +39,9 @@ export class UserController {
}
@Get()
@Permission('user::query')
async getAllUser() {
return this.userService.getAllUser();
async getAllUser(
@Query() paginationQuery: PaginationQueryDto,
) {
return this.userService.getAllUser(paginationQuery);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import { PaginationQueryDto } from "./dto/pagination-query.dto";
import { InjectRepository } from '@nestjs/typeorm';
import { Role, User } from '@app/models';
import { In, Repository } from 'typeorm';
import * as crypto from 'crypto';
import { AuthService } from '../auth/auth.service';
import { paginate, IPaginationOptions } from 'nestjs-typeorm-paginate';
import * as process from "process";

@Injectable()
export class UserService {
Expand Down Expand Up @@ -48,9 +51,13 @@ export class UserService {
}

//获取所有用户信息
async getAllUser() {
return this.userRep.find({
where: { deleteAt: 0 },
async getAllUser(paginationQuery: PaginationQueryDto): Promise<any> {
const { page, limit } = paginationQuery; // 从DTO获取分页参数
return await paginate<User>(this.userRep, {
GaoNeng-wWw marked this conversation as resolved.
Show resolved Hide resolved
page: Number(page) || Number(process.env.PAGITION_PAGE),
limit: Number(limit) || Number(process.env.PAGITION_LIMIT),
},{
where: {deleteAt: 0},
select: ['id', 'name', 'email', 'createTime', 'updateTime'],
});
}
Expand Down Expand Up @@ -107,7 +114,7 @@ export class UserService {
async updateUserPwd(updateUserDto: UpdateUserDto) {
const { email, newPassword, oldPassword } = updateUserDto;
const user = this.userRep.findOne({
where: { email, deleteAt: null },
where: { email, deleteAt: 0 },
select: [
'id',
'name',
Expand Down