forked from wangziqi/gongxue-base
fix: replace orIgnore with findOne for SQLite compat; set backend port 3003
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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'] });
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export default defineConfig({
|
||||
port: 3002,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:3001',
|
||||
target: 'http://localhost:3003',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user