Skip to content

Commit a832611

Browse files
committed
feat: 部门查询
1 parent 1020a59 commit a832611

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/api/department/department.controller.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {
88
Param,
99
ParseIntPipe,
1010
Query,
11+
UseGuards,
1112
} from '@nestjs/common';
1213
import { DepartmentService } from './department.service';
1314
import { DepartmentDto } from './dto/department.dto';
1415
import { CurrentUser, ICurrentUserType } from '@src/decorators';
1516
import { DepartmentPageVo, DepartmentVo } from './vo/department.vo';
1617
import { QueryDepartmentDto } from './dto/department.query';
17-
18+
import { AuthGuard } from '@src/guard/auth.guard';
19+
@UseGuards(AuthGuard)
1820
@Controller('department')
1921
export class DepartmentController {
2022
constructor(private readonly departmentService: DepartmentService) {}

src/api/department/department.service.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ export class DepartmentService {
133133
* @LastEditors: 水痕
134134
* @Description: 分页获取部门
135135
* @param {QueryDepartmentDto} queryOption
136-
* @param {ICurrentUserType} currentInfo
136+
* @param {ICurrentUserType} currentUser
137137
* @return {*}
138138
*/
139139
async getDepartmentPageApi(
140140
queryOption: QueryDepartmentDto,
141-
currentInfo: ICurrentUserType
141+
currentUser: ICurrentUserType
142142
): Promise<DepartmentPageVo> {
143143
const {
144144
status,
@@ -154,7 +154,7 @@ export class DepartmentService {
154154
if ([StatusEnum.NORMAL, StatusEnum.FORBIDDEN].includes(status)) {
155155
query.set('status', Equal(status + ''));
156156
}
157-
const { accountType, id, tenantId } = currentInfo;
157+
const { accountType, id, tenantId } = currentUser;
158158
/**
159159
* 1.如果是超管,查询到全部的账号
160160
* 2.如果不是超管,是主账号的时候查询下面全部的账号
@@ -172,13 +172,13 @@ export class DepartmentService {
172172
}
173173
}
174174
const total = await this.departmentRepository
175-
.createQueryBuilder('account')
175+
.createQueryBuilder('department')
176176
.where(mapToObj(query))
177177
.getCount();
178178
const queryBuilder = this.queryDepartmentBuilder;
179179
const data = await queryBuilder
180180
.where(mapToObj(query))
181-
.orderBy({ accountType: 'DESC', id: 'DESC' })
181+
.orderBy({ id: 'DESC' })
182182
.offset((pageNumber - 1) * pageSize)
183183
.limit(pageSize)
184184
.getRawMany();
@@ -266,14 +266,14 @@ export class DepartmentService {
266266
.addSelect('department.parentId', 'parentId')
267267
.addSelect('department.sort', 'sort')
268268
.addSelect('department.status', 'status')
269-
.addSelect('account.createdAt', 'createdAt')
270-
.addSelect('account.updatedAt', 'updatedAt')
269+
.addSelect('department.createdAt', 'createdAt')
270+
.addSelect('department.updatedAt', 'updatedAt')
271271
.leftJoinAndMapOne(
272272
'xx',
273273
(qb) =>
274274
qb
275-
.select('department.id', 'parentId')
276-
.addSelect('department.title', 'parentTitle')
275+
.select('department1.id', 'parentId')
276+
.addSelect('department1.title', 'parentTitle')
277277
.from(DepartmentEntity, 'department1'),
278278
'department1',
279279
'department.parentId=department1.parentId'

0 commit comments

Comments
 (0)