152 lines
3.7 KiB
TypeScript
152 lines
3.7 KiB
TypeScript
|
|
/**
|
||
|
|
* Seed script to create a test user for development
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { PrismaClient } from '@prisma/client';
|
||
|
|
import * as bcrypt from 'bcryptjs';
|
||
|
|
|
||
|
|
const prisma = new PrismaClient();
|
||
|
|
|
||
|
|
async function main() {
|
||
|
|
console.log('🌱 Seeding test user...');
|
||
|
|
|
||
|
|
// Create user types if they don't exist
|
||
|
|
const adminType = await prisma.auth_user_type.upsert({
|
||
|
|
where: { name: 'Admin' },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
name: 'Admin',
|
||
|
|
description: 'Administrator with full access',
|
||
|
|
is_admin: true,
|
||
|
|
is_customer: false,
|
||
|
|
is_internal: true,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
const customerType = await prisma.auth_user_type.upsert({
|
||
|
|
where: { name: 'Customer' },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
name: 'Customer',
|
||
|
|
description: 'Customer portal user',
|
||
|
|
is_admin: false,
|
||
|
|
is_customer: true,
|
||
|
|
is_internal: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Create test company
|
||
|
|
const testCompany = await prisma.quest_company.upsert({
|
||
|
|
where: { epicor_cust_id: 'TEST' },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
epicor_cust_id: 'TEST',
|
||
|
|
display_name: 'Test Company',
|
||
|
|
can_access_invoices: true,
|
||
|
|
invoicing_email: 'test@example.com',
|
||
|
|
order_ack_email: 'test@example.com',
|
||
|
|
receives_so_emails: true,
|
||
|
|
is_active: true,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Create admin user
|
||
|
|
const adminPassword = await bcrypt.hash('admin123', 10);
|
||
|
|
const adminUser = await prisma.auth_user.upsert({
|
||
|
|
where: { email: 'admin@vorteq.com' },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
email: 'admin@vorteq.com',
|
||
|
|
password_hash: adminPassword,
|
||
|
|
email_verified: true,
|
||
|
|
name: 'Admin User',
|
||
|
|
auth_user_type_id: adminType.id,
|
||
|
|
deactivated: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Create quest_user for admin
|
||
|
|
const adminQuestUser = await prisma.quest_user.upsert({
|
||
|
|
where: { auth_user_id: adminUser.id },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
auth_user_id: adminUser.id,
|
||
|
|
is_sub_user: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Link admin to test company
|
||
|
|
await prisma.quest_user_company.upsert({
|
||
|
|
where: {
|
||
|
|
quest_user_id_quest_company_id: {
|
||
|
|
quest_user_id: adminQuestUser.id,
|
||
|
|
quest_company_id: testCompany.id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
quest_user_id: adminQuestUser.id,
|
||
|
|
quest_company_id: testCompany.id,
|
||
|
|
is_active_company: true,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Create regular customer user
|
||
|
|
const customerPassword = await bcrypt.hash('customer123', 10);
|
||
|
|
const customerUser = await prisma.auth_user.upsert({
|
||
|
|
where: { email: 'customer@vorteq.com' },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
email: 'customer@vorteq.com',
|
||
|
|
password_hash: customerPassword,
|
||
|
|
email_verified: true,
|
||
|
|
name: 'Customer User',
|
||
|
|
auth_user_type_id: customerType.id,
|
||
|
|
deactivated: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Create quest_user for customer
|
||
|
|
const customerQuestUser = await prisma.quest_user.upsert({
|
||
|
|
where: { auth_user_id: customerUser.id },
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
auth_user_id: customerUser.id,
|
||
|
|
is_sub_user: false,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
// Link customer to test company
|
||
|
|
await prisma.quest_user_company.upsert({
|
||
|
|
where: {
|
||
|
|
quest_user_id_quest_company_id: {
|
||
|
|
quest_user_id: customerQuestUser.id,
|
||
|
|
quest_company_id: testCompany.id,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
update: {},
|
||
|
|
create: {
|
||
|
|
quest_user_id: customerQuestUser.id,
|
||
|
|
quest_company_id: testCompany.id,
|
||
|
|
is_active_company: true,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('✅ Test users created successfully!');
|
||
|
|
console.log('\n📧 Admin Login:');
|
||
|
|
console.log(' Email: admin@vorteq.com');
|
||
|
|
console.log(' Password: admin123');
|
||
|
|
console.log('\n📧 Customer Login:');
|
||
|
|
console.log(' Email: customer@vorteq.com');
|
||
|
|
console.log(' Password: customer123');
|
||
|
|
}
|
||
|
|
|
||
|
|
main()
|
||
|
|
.catch((e) => {
|
||
|
|
console.error(e);
|
||
|
|
process.exit(1);
|
||
|
|
})
|
||
|
|
.finally(async () => {
|
||
|
|
await prisma.$disconnect();
|
||
|
|
});
|