fix: replace orIgnore with findOne for SQLite compat; set backend port 3003

This commit is contained in:
2026-07-02 14:31:51 +08:00
parent db7ccaf5a0
commit 4704adcba1
3 changed files with 14 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ async function bootstrap() {
app.setGlobalPrefix('api');
app.enableCors();
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
await app.listen(process.env.PORT ?? 3001);
console.log(`Server running on http://localhost:${process.env.PORT ?? 3001}`);
await app.listen(process.env.PORT ?? 3003);
console.log(`Server running on http://localhost:${process.env.PORT ?? 3003}`);
}
bootstrap();

View File

@@ -109,27 +109,23 @@ export class RbacService {
) {}
async seedData(): Promise<void> {
// Step 1: 幂等插入所有权限点
// Step 1: 幂等插入所有权限点(先查后插,兼容 SQLite/MySQL
for (const p of PRESET_PERMISSIONS) {
await this.permRepo
.createQueryBuilder()
.insert()
.into(Permission)
.values(p)
.orIgnore()
.execute();
const exists = await this.permRepo.findOne({ where: { code: p.code } });
if (!exists) {
await this.permRepo.save(this.permRepo.create(p));
}
}
const allPerms = await this.permRepo.find();
// Step 2: 幂等插入预置角色
for (const r of PRESET_ROLES) {
await this.roleRepo
.createQueryBuilder()
.insert()
.into(Role)
.values({ name: r.name, description: r.description, isSystem: r.isSystem })
.orIgnore()
.execute();
const exists = await this.roleRepo.findOne({ where: { name: r.name } });
if (!exists) {
await this.roleRepo.save(
this.roleRepo.create({ name: r.name, description: r.description, isSystem: r.isSystem }),
);
}
}
const allRoles = await this.roleRepo.find({ relations: ['permissions'] });

View File

@@ -8,7 +8,7 @@ export default defineConfig({
port: 3002,
proxy: {
'/api': {
target: 'http://localhost:3001',
target: 'http://localhost:3003',
changeOrigin: true,
},
},