collect-system/apps/server/src/models/department/department.controller.ts

88 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-12-30 08:26:40 +08:00
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { DepartmentService } from './department.service';
import { AuthGuard } from '@server/auth/auth.guard';
2025-01-06 08:45:23 +08:00
import { db } from '@nice/common';
2024-12-30 08:26:40 +08:00
@Controller('dept')
export class DepartmentController {
constructor(private readonly deptService: DepartmentService) { }
@UseGuards(AuthGuard)
@Get('get-detail')
async getDepartmentDetails(@Query('dept-id') deptId: string) {
try {
const result = await this.deptService.findById(deptId);
return {
data: result,
errmsg: 'success',
errno: 0,
};
} catch (e) {
return {
data: {},
errmsg: (e as any)?.message || 'error',
errno: 1,
};
}
}
@UseGuards(AuthGuard)
@Get('get-all-child-dept-ids')
async getAllChildDeptIds(@Query('dept-id') deptId: string) {
try {
const result = await this.deptService.getDescendantIds([deptId]);
return {
data: result,
errmsg: 'success',
errno: 0,
};
} catch (e) {
return {
data: {},
errmsg: (e as any)?.message || 'error',
errno: 1,
};
}
}
@UseGuards(AuthGuard)
@Get('get-all-parent-dept-ids')
async getAllParentDeptIds(@Query('dept-id') deptId: string) {
try {
const result = await this.deptService.getAncestorIds([deptId]);
return {
data: result,
errmsg: 'success',
errno: 0,
};
} catch (e) {
return {
data: {},
errmsg: (e as any)?.message || 'error',
errno: 1,
};
}
}
@UseGuards(AuthGuard)
@Get('find-by-name-in-dom')
async findInDomain(
@Query('domain-id') domainId?: string,
@Query('name') name?: string,
) {
try {
const result = await this.deptService.findInDomain(domainId, name);
return {
data: result,
errmsg: 'success',
errno: 0,
};
} catch (e) {
return {
data: {},
errmsg: (e as any)?.message || 'error',
errno: 1,
};
}
}
}