anexado seed estado, municipio, parroquia y localidad en api

This commit is contained in:
2025-06-16 23:16:52 -04:00
parent 8216cb4e09
commit f09e12e68c
14 changed files with 17238 additions and 103 deletions

View File

@@ -1,34 +1,41 @@
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
import * as schema from '../index';
import { users, usersRole } from '../index';
import { users, usersRole } from '../index';
export async function seedUserAdmin(db: NodePgDatabase<typeof schema>) {
// Insert admin user
try {
// Password is already hashed in your SQL, but in a real application you might want to hash it here
// const hashedPassword = await hash('your_password', 10);
const hashedPassword = '$2b$10$6esl7d/BOINamScuReRoPuYFC8iSJgpk61LHm2X3PCU5hu/St8vHW';
const hashedPassword =
'$2b$10$6esl7d/BOINamScuReRoPuYFC8iSJgpk61LHm2X3PCU5hu/St8vHW';
const [adminUser] = await db.insert(users).values({
username: 'superadmin',
email: 'admin@zonastart.com',
fullname: 'Super Administrador',
password: hashedPassword,
state: 1,
municipality: 1,
parish: 1,
isTwoFactorEnabled: false,
isEmailVerified: true,
isActive: true
}).returning({ id: users.id }).onConflictDoNothing();
const [adminUser] = await db
.insert(users)
.values({
username: 'superadmin',
email: 'admin@fondemi.gob.ve',
fullname: 'Super Administrador',
password: hashedPassword,
state: 1,
municipality: 1,
parish: 1,
isTwoFactorEnabled: false,
isEmailVerified: true,
isActive: true,
})
.returning({ id: users.id })
.onConflictDoNothing();
if (adminUser) {
// Assign superadmin role to the user
await db.insert(usersRole).values({
roleId: 1, // Assuming 'superadmin' has ID 1 based on the insert order
userId: adminUser.id
}).onConflictDoNothing();
await db
.insert(usersRole)
.values({
roleId: 1, // Assuming 'superadmin' has ID 1 based on the insert order
userId: adminUser.id,
})
.onConflictDoNothing();
console.log('Admin user created and assigned superadmin role');
} else {
console.log('Admin user already exists, skipping');
@@ -36,4 +43,4 @@ export async function seedUserAdmin(db: NodePgDatabase<typeof schema>) {
} catch (error) {
console.error('Error creating admin user:', error);
}
}
}