diff --git a/eslint.config.mjs b/eslint.config.mjs index 32465cc..943e790 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -27,9 +27,10 @@ export default tseslint.config( }, { rules: { - '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-floating-promises': 'warn', - '@typescript-eslint/no-unsafe-argument': 'warn' + '@typescript-eslint/no-unsafe-argument': 'warn', + '@typescript-eslint/no-unused-vars': 'off', }, }, -); \ No newline at end of file +); diff --git a/package.json b/package.json index dc7159c..65ad7da 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "cp-central-server", - "version": "0.0.1", - "description": "", - "author": "", + "version": "1.0.0", + "description": "CodePaint Central Server", + "author": "codepaint", "private": true, "license": "UNLICENSED", "scripts": { diff --git a/src/main.ts b/src/main.ts index f0a47b2..1fc842c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,17 +1,22 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; -import { getConfig, IS_DEV } from './utils/config'; +import { getConfig } from './utils/config'; import { ResponseInterceptor } from './common/response'; -const config = getConfig(); +const config = getConfig() as { server: { PORT?: number } }; const PORT = config.server.PORT || 8254; async function bootstrap() { - const app = await NestFactory.create(AppModule); - app.useGlobalInterceptors(new ResponseInterceptor()); - await app.listen(PORT); + try { + const app = await NestFactory.create(AppModule); + app.useGlobalInterceptors(new ResponseInterceptor()); + await app.listen(PORT); - console.log('正在监听端口:', PORT); + console.log('正在监听端口:', PORT); + } catch (error) { + console.error('应用启动失败:', error); + process.exit(1); + } } -bootstrap(); +void bootstrap(); //在其他地方使用this.configService.get('PORT')来获取配置 diff --git a/src/usercenter/usercenter.service.ts b/src/usercenter/usercenter.service.ts index 811cd8c..9a9f075 100644 --- a/src/usercenter/usercenter.service.ts +++ b/src/usercenter/usercenter.service.ts @@ -27,15 +27,18 @@ export class UsercenterService { throw new BadRequestException('创建失败,请检查参数'); } const data = await this.userRepository.save(newUser); + + // 删除密码字段 + const { userPassword, ...userWithoutPassword } = data; + const newData = userWithoutPassword as UserEntity; return { - success: true, status: 200, - data: data, + data: newData, message: '创建成功', }; } - async findAll(page, limit) { + async findAll(page: number, limit: number) { const skip = (page - 1) * limit; // 计算跳过的记录数 const [data, total] = await this.userRepository.findAndCount({ skip, // 跳过记录数 @@ -45,7 +48,12 @@ export class UsercenterService { if (total === 0) { throw new InternalServerErrorException(`数量为0`); } - return { total, data, message: '查询成功', success: true, status: 200 }; + // 删除密码字段 + data.forEach((user) => { + const { userPassword, ...userWithoutPassword } = user; + user = userWithoutPassword as UserEntity; + }); + return { total, data, message: '查询成功', status: 200 }; } async findOne(identifier: string) { @@ -70,10 +78,12 @@ export class UsercenterService { throw new InternalServerErrorException(`未找到匹配 ${identifier} 的记录`); } + const { userPassword, ...userWithoutPassword } = user; + user = userWithoutPassword as UserEntity; + return { data: user, message: '查询成功', - success: true, status: 200, }; } @@ -87,12 +97,15 @@ export class UsercenterService { // 合并更新数据 Object.assign(user, updateUsercenterDto); user.updateTime = new Date(); // 更新时间 - const data = await this.userRepository.save(user); + let newUser = await this.userRepository.save(user); + + const { userPassword, ...userWithoutPassword } = newUser; + newUser = userWithoutPassword as UserEntity; + return { message: '更新成功', - success: true, status: 200, - data: data, + data: newUser, }; } @@ -102,9 +115,9 @@ export class UsercenterService { throw new InternalServerErrorException(`用户 ID 为 ${id} 的记录不存在`); } const data = await this.userRepository.delete(id); + return { message: '删除成功', - success: true, status: 200, data: data, };