parent
dcbe19c36e
commit
1e05f977f6
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,65 @@ |
|||||||
|
import {Controller, Get, Post, Body, Patch, Param, Delete, Query} from '@nestjs/common'; |
||||||
|
import { AuthPostService } from './auth-post.service'; |
||||||
|
import { CreateAuthPostDto } from './dto/create-auth-post.dto'; |
||||||
|
import { UpdateAuthPostDto } from './dto/update-auth-post.dto'; |
||||||
|
import { ApiOperation, ApiProduces, ApiTags } from '@nestjs/swagger'; |
||||||
|
import { PacInfo } from '@common/decorator/pac-info/pac-info.decorator'; |
||||||
|
import { PacInfoType } from '@utils/myType'; |
||||||
|
import {GetAuthPostDto} from "@app/auth-post/dto/get-auth-post.dto"; |
||||||
|
|
||||||
|
@ApiTags('岗位服务') |
||||||
|
@Controller('authPost') |
||||||
|
export class AuthPostController { |
||||||
|
constructor(private readonly authPostService: AuthPostService) {} |
||||||
|
|
||||||
|
@ApiOperation({ |
||||||
|
summary: '添加岗位', |
||||||
|
description: '岗位', |
||||||
|
}) |
||||||
|
@ApiProduces('application/json') |
||||||
|
@Post() |
||||||
|
@Post() |
||||||
|
create(@Body() createAuthPostDto: CreateAuthPostDto, @PacInfo() pacInfo: PacInfoType) { |
||||||
|
return this.authPostService.create(createAuthPostDto, pacInfo); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation({ |
||||||
|
summary: '获取岗位列表', |
||||||
|
description: '查询岗位分页或者列表', |
||||||
|
}) |
||||||
|
@ApiProduces('application/json') |
||||||
|
@Get() |
||||||
|
findAll(@Query() getAuthPostDto: GetAuthPostDto) { |
||||||
|
return this.authPostService.findAll(getAuthPostDto); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation({ |
||||||
|
summary: '获取岗位详细信息', |
||||||
|
description: '查询岗位详细信息,目录菜单列表,数据权限范围', |
||||||
|
}) |
||||||
|
@ApiProduces('application/json') |
||||||
|
@Get(':id') |
||||||
|
findOne(@Param('id') id: string) { |
||||||
|
return this.authPostService.findOne(id); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation({ |
||||||
|
summary: '更新岗位信息', |
||||||
|
description: '更新岗位信息', |
||||||
|
}) |
||||||
|
@ApiProduces('application/json') |
||||||
|
@Patch(':id') |
||||||
|
update(@Param('id') id: string, @Body() updateAuthPostDto: UpdateAuthPostDto, @PacInfo() pacInfo: PacInfoType) { |
||||||
|
return this.authPostService.update(id, updateAuthPostDto, pacInfo); |
||||||
|
} |
||||||
|
|
||||||
|
@ApiOperation({ |
||||||
|
summary: '删除目标岗位', |
||||||
|
description: '删除目标岗位信息', |
||||||
|
}) |
||||||
|
@ApiProduces('application/json') |
||||||
|
@Delete(':id') |
||||||
|
remove(@Param('id') id: string, @PacInfo() pacInfo: PacInfoType) { |
||||||
|
return this.authPostService.remove(id, pacInfo); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
import { Module } from '@nestjs/common'; |
||||||
|
import { AuthPostService } from './auth-post.service'; |
||||||
|
import { AuthPostController } from './auth-post.controller'; |
||||||
|
|
||||||
|
@Module({ |
||||||
|
controllers: [AuthPostController], |
||||||
|
providers: [AuthPostService], |
||||||
|
}) |
||||||
|
export class AuthPostModule {} |
@ -0,0 +1,301 @@ |
|||||||
|
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; |
||||||
|
import { CreateAuthPostDto } from './dto/create-auth-post.dto'; |
||||||
|
import { UpdateAuthPostDto } from './dto/update-auth-post.dto'; |
||||||
|
import { LoggerService } from '@service/logger/logger.service'; |
||||||
|
import { MysqlService } from '@common/service/mysql/mysql.service'; |
||||||
|
import { RedisService } from '@common/service/redis/redis.service'; |
||||||
|
import { Snowflake } from '@service/snowflake/snowflake.service'; |
||||||
|
import { ConfigService } from '@nestjs/config'; |
||||||
|
import {pacAuthDept, pacAuthPost, pacAuthUser, pacCoreDict} from '@entities/schema'; |
||||||
|
import { and, asc, desc, eq, isNull, like, or, sql } from 'drizzle-orm'; |
||||||
|
import { PacInfoType } from '@utils/myType'; |
||||||
|
import { isExistKey, isTrueEnum } from '@utils/boolean.enum'; |
||||||
|
import { GetAuthPostDto } from '@app/auth-post/dto/get-auth-post.dto'; |
||||||
|
import { likeQuery } from '@utils/likeQuery'; |
||||||
|
import { alias } from 'drizzle-orm/mysql-core'; |
||||||
|
|
||||||
|
@Injectable() |
||||||
|
export class AuthPostService { |
||||||
|
// 分页数据格式
|
||||||
|
private readonly postPageType = { |
||||||
|
postId: pacAuthPost.postId, |
||||||
|
postKey: pacAuthPost.postKey, |
||||||
|
postName: pacAuthPost.postName, |
||||||
|
postType: pacAuthPost.postType, |
||||||
|
postTypeName: pacCoreDict.dictName, |
||||||
|
postTypeKey: pacCoreDict.dictKey, |
||||||
|
postDesc: pacAuthPost.postDesc, |
||||||
|
orderNum: pacAuthPost.orderNum, |
||||||
|
status: pacAuthPost.status, |
||||||
|
createby: pacAuthPost.createby, |
||||||
|
createtime: pacAuthPost.createtime, |
||||||
|
updateby: pacAuthPost.updateby, |
||||||
|
updatetime: pacAuthPost.updatetime, |
||||||
|
}; |
||||||
|
|
||||||
|
// 列表数据格式
|
||||||
|
private readonly postListType = { |
||||||
|
postId: pacAuthPost.postId, |
||||||
|
postKey: pacAuthPost.postKey, |
||||||
|
postName: pacAuthPost.postName, |
||||||
|
postType: pacAuthPost.postType, |
||||||
|
postTypeName: pacCoreDict.dictName, |
||||||
|
postTypeKey: pacCoreDict.dictKey, |
||||||
|
orderNum: pacAuthPost.orderNum, |
||||||
|
}; |
||||||
|
constructor( |
||||||
|
private readonly logger: LoggerService, |
||||||
|
private readonly mysqlService: MysqlService, |
||||||
|
private readonly redisService: RedisService, |
||||||
|
private readonly snowflake: Snowflake, |
||||||
|
private readonly config: ConfigService, |
||||||
|
) {} |
||||||
|
|
||||||
|
/** Service |
||||||
|
* NAME: create |
||||||
|
* DESC: 创建岗位信息 |
||||||
|
* DATE: 2024-06-29 13:13:44 - |
||||||
|
* */ |
||||||
|
public async create(createAuthPostDto: CreateAuthPostDto, pacInfo: PacInfoType) { |
||||||
|
// ! 加目标锁,同级,而不是全局
|
||||||
|
const lock = await this.redisService.distributedLock('POST' + createAuthPostDto.postKey, createAuthPostDto.postKey); |
||||||
|
|
||||||
|
// ? 存在正在进行写入的岗位
|
||||||
|
if (!lock) throw new HttpException('服务繁忙,岗位名称重复!', HttpStatus.CONFLICT); |
||||||
|
|
||||||
|
// @ 核心逻辑
|
||||||
|
|
||||||
|
try { |
||||||
|
// ! 查重
|
||||||
|
const result = await this.checkRepeatForPostKey(createAuthPostDto.postKey); |
||||||
|
|
||||||
|
// ? 是否存在重复的岗位
|
||||||
|
if (result.length > 0) throw new HttpException('岗位标识重复!', HttpStatus.CONFLICT); |
||||||
|
|
||||||
|
// ! 添加岗位数据
|
||||||
|
const newPacCoreDict = await this.addPost(createAuthPostDto, pacInfo.userId as any); |
||||||
|
|
||||||
|
// ! 解锁
|
||||||
|
lock(); |
||||||
|
|
||||||
|
// ! 返回结果
|
||||||
|
return newPacCoreDict; |
||||||
|
} catch (e) { |
||||||
|
// ! 解锁
|
||||||
|
lock(); |
||||||
|
|
||||||
|
// ! 抛出错误
|
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** Service |
||||||
|
* NAME: findAll |
||||||
|
* DESC: 获取岗位分页/列表 |
||||||
|
* DATE: 2024-06-29 13:13:47 - |
||||||
|
* */ |
||||||
|
public async findAll(getAuthPostDto: GetAuthPostDto) { |
||||||
|
if (isTrueEnum(getAuthPostDto['isList'])) { |
||||||
|
return await this.getList(getAuthPostDto); |
||||||
|
} else { |
||||||
|
return await this.getPage(getAuthPostDto); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** Service |
||||||
|
* NAME: findOne |
||||||
|
* DESC: 获取岗位详细信息 |
||||||
|
* DATE: 2024-06-29 13:13:49 - |
||||||
|
* */ |
||||||
|
public findOne(id: string) { |
||||||
|
return `This action returns a #${id} authPost`; |
||||||
|
} |
||||||
|
|
||||||
|
/** Service |
||||||
|
* NAME: update |
||||||
|
* DESC: 更新岗位信息 |
||||||
|
* DATE: 2024-06-29 13:13:52 - |
||||||
|
* */ |
||||||
|
public async update(id: string, updateAuthPostDto: UpdateAuthPostDto, pacInfo: PacInfoType) { |
||||||
|
return await this.updatePost(id, updateAuthPostDto, pacInfo.userId as any); |
||||||
|
} |
||||||
|
|
||||||
|
/** Service |
||||||
|
* NAME: remove |
||||||
|
* DESC: 删除岗位信息 |
||||||
|
* DATE: 2024-06-29 13:13:55 - |
||||||
|
* */ |
||||||
|
public remove(id: string, pacInfo: PacInfoType) { |
||||||
|
return this.deletePost(id, pacInfo.userId as any); |
||||||
|
} |
||||||
|
|
||||||
|
// DB 查重Key
|
||||||
|
private checkRepeatForPostKey(postKey) { |
||||||
|
return this.mysqlService.db |
||||||
|
.select({ id: pacAuthPost.postId }) |
||||||
|
.from(pacAuthPost) |
||||||
|
.where(and(isNull(pacAuthPost.deleteby), eq(pacAuthPost.postKey, postKey))); |
||||||
|
} |
||||||
|
|
||||||
|
// DB 写入岗位信息
|
||||||
|
private async addPost(createAuthPostDto: CreateAuthPostDto, userId: string) { |
||||||
|
// ! 生成雪花id,用于岗位主键
|
||||||
|
const id = await this.snowflake.generate(); |
||||||
|
|
||||||
|
// ! 定义写入的岗位数据
|
||||||
|
const newPostData: typeof pacAuthPost.$inferInsert = { |
||||||
|
postId: id as any, |
||||||
|
postKey: createAuthPostDto.postKey, |
||||||
|
postName: createAuthPostDto.postName, |
||||||
|
postType: createAuthPostDto.postType, |
||||||
|
postDesc: createAuthPostDto.postDesc, |
||||||
|
orderNum: createAuthPostDto.orderNum, |
||||||
|
createby: userId, |
||||||
|
createtime: sql`now()` as any, |
||||||
|
}; |
||||||
|
return await this.mysqlService.db.insert(pacAuthPost).values(newPostData); |
||||||
|
} |
||||||
|
|
||||||
|
// DB 查询构建器
|
||||||
|
private queryBuilder(getAuthPostDto: GetAuthPostDto, selectData) { |
||||||
|
// ! 定义基础查询函数
|
||||||
|
// 启用动态查询模式 $dynamic
|
||||||
|
const query = this.mysqlService.db |
||||||
|
.select(selectData) |
||||||
|
.from(pacAuthPost) |
||||||
|
.orderBy( |
||||||
|
isTrueEnum(getAuthPostDto.isAsc) ? asc(pacAuthPost.orderNum) : desc(pacAuthPost.orderNum), |
||||||
|
isTrueEnum(getAuthPostDto.isAsc) ? asc(pacAuthPost.postId) : desc(pacAuthPost.postId), |
||||||
|
) |
||||||
|
.leftJoin(pacCoreDict, eq(pacAuthPost.postType, pacCoreDict.dictId)) |
||||||
|
.$dynamic(); |
||||||
|
|
||||||
|
// 查询条件集合
|
||||||
|
const wl = []; |
||||||
|
|
||||||
|
// ? 未删除
|
||||||
|
wl.push(isNull(pacAuthPost.deleteby)); |
||||||
|
|
||||||
|
// ? 模糊查询
|
||||||
|
wl.push( |
||||||
|
or( |
||||||
|
like(pacAuthPost.postName, likeQuery(getAuthPostDto.postInfo)), |
||||||
|
like(pacAuthPost.postKey, likeQuery(getAuthPostDto.postInfo)), |
||||||
|
like(pacAuthPost.postDesc, likeQuery(getAuthPostDto.postInfo)), |
||||||
|
).if(isExistKey(pacAuthPost, 'postInfo')), |
||||||
|
); |
||||||
|
|
||||||
|
// ? 按照层级查
|
||||||
|
|
||||||
|
// ? 是否查岗位类型
|
||||||
|
wl.push(eq(pacAuthPost.postType, getAuthPostDto.postType).if(isExistKey(getAuthPostDto, 'postType'))); |
||||||
|
|
||||||
|
// ? 是否查字典状态
|
||||||
|
wl.push(eq(pacAuthPost.status, getAuthPostDto.status as any).if(isExistKey(getAuthPostDto, 'status'))); |
||||||
|
|
||||||
|
query.where(and(...wl)); |
||||||
|
return query; |
||||||
|
} |
||||||
|
|
||||||
|
// DB 查分页
|
||||||
|
private async getPage(getAuthPostDto: GetAuthPostDto) { |
||||||
|
const offset = (getAuthPostDto.pageNumber - 1) * getAuthPostDto.pageSize; |
||||||
|
|
||||||
|
// ! 使用基础查询构建查询总记录数
|
||||||
|
const totalCountQuery = this.queryBuilder(getAuthPostDto, { |
||||||
|
totalCount: sql`COUNT(*)`, |
||||||
|
}); |
||||||
|
|
||||||
|
// ! 使用基础查询构建分页查询
|
||||||
|
// 重命名表
|
||||||
|
const userTable1 = alias(pacAuthUser, 'userTable1'); |
||||||
|
const userTable2 = alias(pacAuthUser, 'userTable2'); |
||||||
|
const paginatedQuery = this.queryBuilder(getAuthPostDto, { |
||||||
|
...this.postPageType, |
||||||
|
updateName: userTable1.nickname, |
||||||
|
createName: userTable2.nickname, |
||||||
|
}) |
||||||
|
.leftJoin(userTable2, eq(pacAuthPost.createby, userTable2.userId)) |
||||||
|
.leftJoin(userTable1, eq(pacAuthPost.updateby, userTable1.userId)) |
||||||
|
.limit(getAuthPostDto.pageSize) |
||||||
|
.offset(offset); |
||||||
|
|
||||||
|
return { |
||||||
|
total: (await totalCountQuery)[0].totalCount, |
||||||
|
rowData: await paginatedQuery, |
||||||
|
searchData: getAuthPostDto, |
||||||
|
}; |
||||||
|
} |
||||||
|
|
||||||
|
// DB 查列表
|
||||||
|
private getList(getAuthPostDto: GetAuthPostDto) { |
||||||
|
return this.queryBuilder(getAuthPostDto, this.postListType); |
||||||
|
} |
||||||
|
|
||||||
|
// DB 删除岗位
|
||||||
|
private deletePost(id: string, userId: string) { |
||||||
|
// ! 删除岗位数据
|
||||||
|
return this.mysqlService.db |
||||||
|
.update(pacAuthPost) |
||||||
|
.set({ |
||||||
|
deletetime: sql`now()`, |
||||||
|
deleteby: userId, |
||||||
|
}) |
||||||
|
.where(eq(pacAuthPost.postId, id)); |
||||||
|
} |
||||||
|
|
||||||
|
// DB 更新岗位
|
||||||
|
private async updatePost(id: string, updateAuthPostDto: UpdateAuthPostDto, userId: string) { |
||||||
|
// ! 查岗位
|
||||||
|
const post = await this.mysqlService.db |
||||||
|
.select() |
||||||
|
.from(pacAuthPost) |
||||||
|
.where(and(isNull(pacAuthPost.deleteby), eq(pacAuthPost.postId, id))); |
||||||
|
|
||||||
|
if (post.length === 0) throw new HttpException('未找到目标岗位信息,无法修改!', HttpStatus.BAD_REQUEST); |
||||||
|
|
||||||
|
// ! 加目标锁,同级,而不是全局
|
||||||
|
const lock = await this.redisService.distributedLock('POST' + updateAuthPostDto.postKey, updateAuthPostDto.postKey); |
||||||
|
|
||||||
|
// ? 存在正在进行写入的岗位
|
||||||
|
if (!lock) throw new HttpException('服务繁忙,岗位标识重复!', HttpStatus.CONFLICT); |
||||||
|
|
||||||
|
// @ 核心逻辑
|
||||||
|
|
||||||
|
try { |
||||||
|
// ! 查重
|
||||||
|
const result = await this.checkRepeatForPostKey(updateAuthPostDto.postKey); |
||||||
|
|
||||||
|
|
||||||
|
// ? 是否存在重复的岗位
|
||||||
|
if (result.length > 0 && result[0].id != id) throw new HttpException('岗位标识重复!', HttpStatus.CONFLICT); |
||||||
|
|
||||||
|
// ! 添加岗位数据
|
||||||
|
const newPacCoreDict = await this.mysqlService.db |
||||||
|
.update(pacAuthPost) |
||||||
|
.set({ |
||||||
|
postKey: updateAuthPostDto.postKey, |
||||||
|
postName: updateAuthPostDto.postName, |
||||||
|
postType: updateAuthPostDto.postType, |
||||||
|
postDesc: updateAuthPostDto.postDesc, |
||||||
|
orderNum: updateAuthPostDto.orderNum, |
||||||
|
status: updateAuthPostDto.status, |
||||||
|
updateby: userId, |
||||||
|
updatetime: sql`now()`, |
||||||
|
}) |
||||||
|
.where(eq(pacAuthPost.postId, id)); |
||||||
|
|
||||||
|
// ! 解锁
|
||||||
|
lock(); |
||||||
|
|
||||||
|
// ! 返回结果
|
||||||
|
return newPacCoreDict; |
||||||
|
} catch (e) { |
||||||
|
// ! 解锁
|
||||||
|
lock(); |
||||||
|
|
||||||
|
// ! 抛出错误
|
||||||
|
throw e; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,80 @@ |
|||||||
|
import { ApiProperty } from '@nestjs/swagger'; |
||||||
|
import Trim from '@common/decorator/trim/trim.decorator'; |
||||||
|
import ChangeCase, { CaseType } from '@common/decorator/change-case/change-case.decorator'; |
||||||
|
import { IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator'; |
||||||
|
|
||||||
|
export class CreateAuthPostDto { |
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位标志', |
||||||
|
type: String, |
||||||
|
example: 'Country', |
||||||
|
required: true, |
||||||
|
minLength: 1, |
||||||
|
maxLength: 32, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@ChangeCase(CaseType.constant) |
||||||
|
@IsString({ message: '岗位标志应为字符串格式!' }) |
||||||
|
@Length(1, 32, { message: '请将岗位标志长度控制在1到32位之间!' }) |
||||||
|
readonly postKey: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位名称', |
||||||
|
type: String, |
||||||
|
example: '研发经理', |
||||||
|
required: true, |
||||||
|
minLength: 1, |
||||||
|
maxLength: 32, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@IsString({ message: '岗位名称应为字符串格式!' }) |
||||||
|
@Length(1, 32, { message: '岗位名称长度控制在1到32位之间!' }) |
||||||
|
readonly postName: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位类型,来自于字典', |
||||||
|
type: String, |
||||||
|
example: '0', |
||||||
|
required: true, |
||||||
|
minLength: 19, |
||||||
|
maxLength: 19, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@IsString({ message: '岗位类型格式不正确!' }) |
||||||
|
@Length(19, 19, { message: '岗位类型格式不正确!' }) |
||||||
|
readonly postType: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位描述', |
||||||
|
type: String, |
||||||
|
example: '0', |
||||||
|
required: false, |
||||||
|
minLength: 1, |
||||||
|
maxLength: 255, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@IsString({ message: '岗位描述应为字符串格式!' }) |
||||||
|
@Length(1, 255, { message: '请将岗位描述长度控制在1到255位之间!' }) |
||||||
|
@IsOptional() |
||||||
|
readonly postDesc: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '排序', |
||||||
|
type: Number, |
||||||
|
example: 10, |
||||||
|
required: false, |
||||||
|
minimum: -1000, |
||||||
|
maximum: 1000, |
||||||
|
}) |
||||||
|
@IsOptional() |
||||||
|
@IsInt({ |
||||||
|
message: '排序必须是整数!', |
||||||
|
}) |
||||||
|
@Min(-1000, { |
||||||
|
message: '排序不能小于-1000!', |
||||||
|
}) |
||||||
|
@Max(1000, { |
||||||
|
message: '排序不能超过1000', |
||||||
|
}) |
||||||
|
readonly orderNum?: number = 0; |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
// | ------------------------------------------------------------
|
||||||
|
// | @版本: version 0.1
|
||||||
|
// | @创建人: 【Nie-x7129】
|
||||||
|
// | @E-mail: x71291@outlook.com
|
||||||
|
// | @所在项目: pac-auth
|
||||||
|
// | @文件描述: get-auth-dept.dto.ts -
|
||||||
|
// | @创建时间: 2024-06-28 11:20
|
||||||
|
// | @更新时间: 2024-06-28 11:20
|
||||||
|
// | @修改记录:
|
||||||
|
// | -*-*-*- (时间--修改人--修改说明) -*-*-*-
|
||||||
|
// | =
|
||||||
|
// | ------------------------------------------------------------
|
||||||
|
|
||||||
|
import { GetDto } from '@dto/get.dto'; |
||||||
|
import { ApiProperty } from '@nestjs/swagger'; |
||||||
|
import Trim from '@common/decorator/trim/trim.decorator'; |
||||||
|
import { IsInt, IsOptional, IsString, Length, Max, Min } from 'class-validator'; |
||||||
|
import Int from '@common/decorator/int/int.descrator'; |
||||||
|
|
||||||
|
export class GetAuthPostDto extends GetDto { |
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位', |
||||||
|
type: String, |
||||||
|
example: '管理员', |
||||||
|
required: false, |
||||||
|
minLength: 1, |
||||||
|
maxLength: 128, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@IsString({ message: '岗位信息应为字符串格式!' }) |
||||||
|
@Length(0, 128, { message: '请将岗位信息长度控制在1到128位之间!' }) |
||||||
|
@IsOptional() |
||||||
|
readonly postInfo?: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位类型,来自于字典', |
||||||
|
type: String, |
||||||
|
example: '0', |
||||||
|
required: false, |
||||||
|
minLength: 19, |
||||||
|
maxLength: 19, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@IsString({ message: '岗位类型格式不正确!' }) |
||||||
|
@Length(19, 19, { message: '岗位类型格式不正确!' }) |
||||||
|
@IsOptional() |
||||||
|
readonly postType: string; |
||||||
|
|
||||||
|
@ApiProperty({ |
||||||
|
description: '岗位状态', |
||||||
|
type: Number, |
||||||
|
example: 0, |
||||||
|
required: false, |
||||||
|
minimum: -100, |
||||||
|
maximum: 100, |
||||||
|
}) |
||||||
|
@Trim() |
||||||
|
@Int() |
||||||
|
@IsInt({ |
||||||
|
message: '岗位状态必须是整数!', |
||||||
|
}) |
||||||
|
@Min(-100, { |
||||||
|
message: '岗位状态需要大于-100!', |
||||||
|
}) |
||||||
|
@Max(100, { |
||||||
|
message: '岗位状态不能超过100', |
||||||
|
}) |
||||||
|
@IsOptional() |
||||||
|
readonly status?: string; |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
import { ApiProperty, PartialType } from '@nestjs/swagger'; |
||||||
|
import { CreateAuthPostDto } from './create-auth-post.dto'; |
||||||
|
import { IsInt, IsOptional, Max, Min } from 'class-validator'; |
||||||
|
|
||||||
|
export class UpdateAuthPostDto extends PartialType(CreateAuthPostDto) { |
||||||
|
@ApiProperty({ |
||||||
|
description: '状态', |
||||||
|
type: Number, |
||||||
|
example: 10, |
||||||
|
required: false, |
||||||
|
minimum: -100, |
||||||
|
maximum: 100, |
||||||
|
}) |
||||||
|
@IsOptional() |
||||||
|
@IsInt({ |
||||||
|
message: '状态必须是整数!', |
||||||
|
}) |
||||||
|
@Min(-1000, { |
||||||
|
message: '状态不能小于-100!', |
||||||
|
}) |
||||||
|
@Max(1000, { |
||||||
|
message: '状态不能超过100', |
||||||
|
}) |
||||||
|
readonly status: number; |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
export class AuthPost {} |
@ -0,0 +1,34 @@ |
|||||||
|
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; |
||||||
|
import { AuthUserService } from './auth-user.service'; |
||||||
|
import { CreateAuthUserDto } from './dto/create-auth-user.dto'; |
||||||
|
import { UpdateAuthUserDto } from './dto/update-auth-user.dto'; |
||||||
|
|
||||||
|
@Controller('auth-user') |
||||||
|
export class AuthUserController { |
||||||
|
constructor(private readonly authUserService: AuthUserService) {} |
||||||
|
|
||||||
|
@Post() |
||||||
|
create(@Body() createAuthUserDto: CreateAuthUserDto) { |
||||||
|
return this.authUserService.create(createAuthUserDto); |
||||||
|
} |
||||||
|
|
||||||
|
@Get() |
||||||
|
findAll() { |
||||||
|
return this.authUserService.findAll(); |
||||||
|
} |
||||||
|
|
||||||
|
@Get(':id') |
||||||
|
findOne(@Param('id') id: string) { |
||||||
|
return this.authUserService.findOne(+id); |
||||||
|
} |
||||||
|
|
||||||
|
@Patch(':id') |
||||||
|
update(@Param('id') id: string, @Body() updateAuthUserDto: UpdateAuthUserDto) { |
||||||
|
return this.authUserService.update(+id, updateAuthUserDto); |
||||||
|
} |
||||||
|
|
||||||
|
@Delete(':id') |
||||||
|
remove(@Param('id') id: string) { |
||||||
|
return this.authUserService.remove(+id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
import { Module } from '@nestjs/common'; |
||||||
|
import { AuthUserService } from './auth-user.service'; |
||||||
|
import { AuthUserController } from './auth-user.controller'; |
||||||
|
|
||||||
|
@Module({ |
||||||
|
controllers: [AuthUserController], |
||||||
|
providers: [AuthUserService], |
||||||
|
}) |
||||||
|
export class AuthUserModule {} |
@ -0,0 +1,26 @@ |
|||||||
|
import { Injectable } from '@nestjs/common'; |
||||||
|
import { CreateAuthUserDto } from './dto/create-auth-user.dto'; |
||||||
|
import { UpdateAuthUserDto } from './dto/update-auth-user.dto'; |
||||||
|
|
||||||
|
@Injectable() |
||||||
|
export class AuthUserService { |
||||||
|
create(createAuthUserDto: CreateAuthUserDto) { |
||||||
|
return 'This action adds a new authUser'; |
||||||
|
} |
||||||
|
|
||||||
|
findAll() { |
||||||
|
return `This action returns all authUser`; |
||||||
|
} |
||||||
|
|
||||||
|
findOne(id: number) { |
||||||
|
return `This action returns a #${id} authUser`; |
||||||
|
} |
||||||
|
|
||||||
|
update(id: number, updateAuthUserDto: UpdateAuthUserDto) { |
||||||
|
return `This action updates a #${id} authUser`; |
||||||
|
} |
||||||
|
|
||||||
|
remove(id: number) { |
||||||
|
return `This action removes a #${id} authUser`; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
export class CreateAuthUserDto {} |
@ -0,0 +1,4 @@ |
|||||||
|
import { PartialType } from '@nestjs/swagger'; |
||||||
|
import { CreateAuthUserDto } from './create-auth-user.dto'; |
||||||
|
|
||||||
|
export class UpdateAuthUserDto extends PartialType(CreateAuthUserDto) {} |
@ -0,0 +1 @@ |
|||||||
|
export class AuthUser {} |
@ -1,2 +1,3 @@ |
|||||||
import { relations } from 'drizzle-orm/relations'; |
import { relations } from "drizzle-orm/relations"; |
||||||
import {} from './schema'; |
import { } from "./schema"; |
||||||
|
|
||||||
|
Loading…
Reference in new issue