|
|
@@ -1,6 +1,14 @@
|
|
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'
|
|
|
import { SysConfigService } from '../services/sys-config.service'
|
|
|
-import { CreateSysConfigBody, UpdateSysConfigBody, ListSysConfigQuery, CreateTeamConfigBody, UpdateTeamConfigBody, ListTeamConfigQuery, GetTeamConfigParams } from '../dto/sys-config.dto'
|
|
|
+import {
|
|
|
+ CreateSysConfigBody,
|
|
|
+ UpdateSysConfigBody,
|
|
|
+ ListSysConfigQuery,
|
|
|
+ CreateTeamConfigBody,
|
|
|
+ UpdateTeamConfigBody,
|
|
|
+ ListTeamConfigQuery,
|
|
|
+ GetTeamConfigParams
|
|
|
+} from '../dto/sys-config.dto'
|
|
|
import { UserRole } from '../entities/user.entity'
|
|
|
|
|
|
export class SysConfigController {
|
|
|
@@ -21,7 +29,7 @@ export class SysConfigController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async update(request: FastifyRequest<{ Params: { name: string }, Body: UpdateSysConfigBody }>, reply: FastifyReply) {
|
|
|
+ async update(request: FastifyRequest<{ Params: { name: string }; Body: UpdateSysConfigBody }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
const config = await this.sysConfigService.update(request.params.name, request.body, request.body.teamId)
|
|
|
return reply.send(config)
|
|
|
@@ -68,12 +76,15 @@ export class SysConfigController {
|
|
|
}
|
|
|
|
|
|
// 团队配置相关接口
|
|
|
- async createTeamConfig(request: FastifyRequest<{ Body: CreateTeamConfigBody & { teamId?: number } }>, reply: FastifyReply) {
|
|
|
+ async createTeamConfig(
|
|
|
+ request: FastifyRequest<{ Body: CreateTeamConfigBody & { teamId?: number } }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { teamId, ...body } = request.body
|
|
|
const userId = request.user.id
|
|
|
const userRole = request.user.role
|
|
|
-
|
|
|
+
|
|
|
const config = await this.sysConfigService.createTeamConfig(body, userId, userRole, teamId)
|
|
|
return reply.code(201).send(config)
|
|
|
} catch (error) {
|
|
|
@@ -81,13 +92,16 @@ export class SysConfigController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async updateTeamConfig(request: FastifyRequest<{ Params: { name: string }, Body: UpdateTeamConfigBody & { teamId?: number } }>, reply: FastifyReply) {
|
|
|
+ async updateTeamConfig(
|
|
|
+ request: FastifyRequest<{ Params: { name: string }; Body: UpdateTeamConfigBody & { teamId?: number } }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { name } = request.params
|
|
|
const { teamId, ...body } = request.body
|
|
|
const userId = request.user.id
|
|
|
const userRole = request.user.role
|
|
|
-
|
|
|
+
|
|
|
const config = await this.sysConfigService.updateTeamConfig(name, body, userId, userRole, teamId)
|
|
|
return reply.send(config)
|
|
|
} catch (error) {
|
|
|
@@ -95,13 +109,16 @@ export class SysConfigController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async deleteTeamConfig(request: FastifyRequest<{ Params: { name: string }, Body: { teamId?: number } }>, reply: FastifyReply) {
|
|
|
+ async deleteTeamConfig(
|
|
|
+ request: FastifyRequest<{ Params: { name: string }; Body: { teamId?: number } }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { name } = request.params
|
|
|
const { teamId } = request.body
|
|
|
const userId = request.user.id
|
|
|
const userRole = request.user.role
|
|
|
-
|
|
|
+
|
|
|
await this.sysConfigService.deleteTeamConfig(name, userId, userRole, teamId)
|
|
|
return reply.send({ success: true })
|
|
|
} catch (error) {
|
|
|
@@ -109,27 +126,43 @@ export class SysConfigController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getTeamConfig(request: FastifyRequest<{ Params: { name: string }, Querystring: { teamId?: string } }>, reply: FastifyReply) {
|
|
|
+ async getTeamConfig(
|
|
|
+ request: FastifyRequest<{ Params: { name: string }; Querystring: { teamId?: string } }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { name } = request.params
|
|
|
const { teamId } = request.query
|
|
|
const userId = request.user.id
|
|
|
const userRole = request.user.role
|
|
|
-
|
|
|
- const config = await this.sysConfigService.getTeamConfig(name, userId, userRole, teamId ? Number(teamId) : undefined)
|
|
|
+
|
|
|
+ const config = await this.sysConfigService.getTeamConfig(
|
|
|
+ name,
|
|
|
+ userId,
|
|
|
+ userRole,
|
|
|
+ teamId ? Number(teamId) : undefined
|
|
|
+ )
|
|
|
return reply.send(config)
|
|
|
} catch (error) {
|
|
|
return reply.code(500).send(error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async listTeamConfigs(request: FastifyRequest<{ Querystring: ListTeamConfigQuery & { teamId?: string } }>, reply: FastifyReply) {
|
|
|
+ async listTeamConfigs(
|
|
|
+ request: FastifyRequest<{ Querystring: ListTeamConfigQuery & { teamId?: string } }>,
|
|
|
+ reply: FastifyReply
|
|
|
+ ) {
|
|
|
try {
|
|
|
const { teamId, ...query } = request.query
|
|
|
const userId = request.user.id
|
|
|
const userRole = request.user.role
|
|
|
-
|
|
|
- const configs = await this.sysConfigService.listTeamConfigs(query, userId, userRole, teamId ? Number(teamId) : undefined)
|
|
|
+
|
|
|
+ const configs = await this.sysConfigService.listTeamConfigs(
|
|
|
+ query,
|
|
|
+ userId,
|
|
|
+ userRole,
|
|
|
+ teamId ? Number(teamId) : undefined
|
|
|
+ )
|
|
|
return reply.send(configs)
|
|
|
} catch (error) {
|
|
|
return reply.code(500).send(error)
|
|
|
@@ -138,11 +171,14 @@ export class SysConfigController {
|
|
|
|
|
|
async getUserTeamConfigs(request: FastifyRequest, reply: FastifyReply) {
|
|
|
try {
|
|
|
- const userId = request.user.id
|
|
|
+ let userId = undefined
|
|
|
+ if (request.user) {
|
|
|
+ userId = request.user.id
|
|
|
+ }
|
|
|
const configs = await this.sysConfigService.getUserTeamConfigs(userId)
|
|
|
return reply.send(configs)
|
|
|
} catch (error) {
|
|
|
return reply.code(500).send(error)
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|