mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 03:37:56 +00:00
refactor: handle kyc journey for customers
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
console.log('Starting seeder script...');
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
console.error('Uncaught Exception:', err);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
||||
});
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { Repository } from 'typeorm';
|
||||
import { UserRepository } from '..//user/repositories';
|
||||
import { AppModule } from '../app.module';
|
||||
import { Roles } from '../auth/enums';
|
||||
import { User } from '../user/entities';
|
||||
import { initializeTransactionalContext } from 'typeorm-transactional';
|
||||
const SALT_ROUNDS = 10;
|
||||
|
||||
async function bootstrap() {
|
||||
initializeTransactionalContext();
|
||||
const app = await NestFactory.createApplicationContext(AppModule);
|
||||
const userRepository = app.get<Repository<User>>('UserRepository');
|
||||
const adminEmail = process.env.SUPER_ADMIN_EMAIL;
|
||||
const adminPassword = process.env.SUPER_ADMIN_PASSWORD;
|
||||
if (!adminEmail || !adminPassword) {
|
||||
console.error('Missing SUPER_ADMIN_EMAIL or SUPER_ADMIN_PASSWORD in .env file');
|
||||
process.exit(1);
|
||||
}
|
||||
const existingAdmin = await userRepository.findOne({ where: { email: adminEmail } });
|
||||
if (!existingAdmin) {
|
||||
const hashedPassword = await bcrypt.hash(adminPassword, SALT_ROUNDS);
|
||||
const superAdmin = userRepository.create({
|
||||
email: adminEmail,
|
||||
password: hashedPassword,
|
||||
roles: [Roles.SUPER_ADMIN],
|
||||
isEmailVerified: true,
|
||||
isPhoneVerified: true,
|
||||
});
|
||||
await userRepository.save(superAdmin);
|
||||
console.log('Super Admin created successfully.');
|
||||
} else {
|
||||
console.log('Super Admin already exists.');
|
||||
}
|
||||
await app.close();
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user