feat: Add seeder module and services for all lookup tables

This commit is contained in:
faris Aljohari
2024-05-18 21:53:27 +03:00
parent 50a3d8ee49
commit ad15164e15
10 changed files with 233 additions and 28 deletions

View File

@ -13,6 +13,7 @@ import { BuildingModule } from './building/building.module';
import { FloorModule } from './floor/floor.module';
import { UnitModule } from './unit/unit.module';
import { RoleModule } from './role/role.module';
import { SeederModule } from '@app/common/seed/seeder.module';
@Module({
imports: [
ConfigModule.forRoot({
@ -30,6 +31,7 @@ import { RoleModule } from './role/role.module';
GroupModule,
DeviceModule,
UserDevicePermissionModule,
SeederModule,
],
controllers: [AuthenticationController],
})

View File

@ -4,7 +4,7 @@ import rateLimit from 'express-rate-limit';
import helmet from 'helmet';
import { setupSwaggerAuthentication } from '../libs/common/src/util/user-auth.swagger.utils';
import { ValidationPipe } from '@nestjs/common';
import { SuperAdminService } from '@app/common/helper/services/super.admin.sarvice';
import { SeederService } from '@app/common/seed/services/seeder.service';
async function bootstrap() {
const app = await NestFactory.create(AuthModule);
@ -34,10 +34,14 @@ async function bootstrap() {
},
}),
);
// Create super admin user
const superAdminService = app.get(SuperAdminService);
await superAdminService.createSuperAdminIfNotFound();
const seederService = app.get(SeederService);
try {
await seederService.seed();
console.log('Seeding complete!');
} catch (error) {
console.error('Seeding failed!', error);
}
await app.listen(process.env.PORT || 4000);
}
console.log('Starting auth at port ...', process.env.PORT || 4000);