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.setGlobalPrefix('api');
|
||||||
app.enableCors();
|
app.enableCors();
|
||||||
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
||||||
await app.listen(process.env.PORT ?? 3001);
|
await app.listen(process.env.PORT ?? 3003);
|
||||||
console.log(`Server running on http://localhost:${process.env.PORT ?? 3001}`);
|
console.log(`Server running on http://localhost:${process.env.PORT ?? 3003}`);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -109,27 +109,23 @@ export class RbacService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async seedData(): Promise<void> {
|
async seedData(): Promise<void> {
|
||||||
// Step 1: 幂等插入所有权限点
|
// Step 1: 幂等插入所有权限点(先查后插,兼容 SQLite/MySQL)
|
||||||
for (const p of PRESET_PERMISSIONS) {
|
for (const p of PRESET_PERMISSIONS) {
|
||||||
await this.permRepo
|
const exists = await this.permRepo.findOne({ where: { code: p.code } });
|
||||||
.createQueryBuilder()
|
if (!exists) {
|
||||||
.insert()
|
await this.permRepo.save(this.permRepo.create(p));
|
||||||
.into(Permission)
|
}
|
||||||
.values(p)
|
|
||||||
.orIgnore()
|
|
||||||
.execute();
|
|
||||||
}
|
}
|
||||||
const allPerms = await this.permRepo.find();
|
const allPerms = await this.permRepo.find();
|
||||||
|
|
||||||
// Step 2: 幂等插入预置角色
|
// Step 2: 幂等插入预置角色
|
||||||
for (const r of PRESET_ROLES) {
|
for (const r of PRESET_ROLES) {
|
||||||
await this.roleRepo
|
const exists = await this.roleRepo.findOne({ where: { name: r.name } });
|
||||||
.createQueryBuilder()
|
if (!exists) {
|
||||||
.insert()
|
await this.roleRepo.save(
|
||||||
.into(Role)
|
this.roleRepo.create({ name: r.name, description: r.description, isSystem: r.isSystem }),
|
||||||
.values({ name: r.name, description: r.description, isSystem: r.isSystem })
|
);
|
||||||
.orIgnore()
|
}
|
||||||
.execute();
|
|
||||||
}
|
}
|
||||||
const allRoles = await this.roleRepo.find({ relations: ['permissions'] });
|
const allRoles = await this.roleRepo.find({ relations: ['permissions'] });
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export default defineConfig({
|
|||||||
port: 3002,
|
port: 3002,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'http://localhost:3001',
|
target: 'http://localhost:3003',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user