Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
);
);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
19 changes: 12 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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')来获取配置
31 changes: 22 additions & 9 deletions src/usercenter/usercenter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, // 跳过记录数
Expand All @@ -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) {
Expand All @@ -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,
};
}
Expand All @@ -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,
};
}

Expand All @@ -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,
};
Expand Down