136 lines
3.4 KiB
TypeScript
136 lines
3.4 KiB
TypeScript
/**
|
|
* Party User seed data generator
|
|
* Creates initial user accounts for development and testing
|
|
* Includes:
|
|
* - Fixed demo accounts (alice, demo)
|
|
* - Randomly generated test accounts with CJK locale data
|
|
*/
|
|
import { faker as enFaker } from '@faker-js/faker/locale/en_US';
|
|
import { faker as zhFaker } from '@faker-js/faker/locale/zh_CN';
|
|
import { faker as jaFaker } from '@faker-js/faker/locale/ja';
|
|
import { faker as koFaker } from '@faker-js/faker/locale/ko';
|
|
import { faker as twFaker } from '@faker-js/faker/locale/zh_TW';
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
const prisma = new PrismaClient();
|
|
|
|
const ROLE = [
|
|
`CEO`,
|
|
`CTO`,
|
|
`Project Coordinator`,
|
|
`Team Leader`,
|
|
`Software Developer`,
|
|
`Marketing Strategist`,
|
|
`Data Analyst`,
|
|
`Product Owner`,
|
|
`Graphic Designer`,
|
|
`Operations Manager`,
|
|
`Customer Support Specialist`,
|
|
`Sales Manager`,
|
|
`HR Recruiter`,
|
|
`Business Consultant`,
|
|
`Financial Planner`,
|
|
`Network Engineer`,
|
|
`Content Creator`,
|
|
`Quality Assurance Tester`,
|
|
`Public Relations Officer`,
|
|
`IT Administrator`,
|
|
`Compliance Officer`,
|
|
`Event Planner`,
|
|
`Legal Counsel`,
|
|
`Training Coordinator`,
|
|
];
|
|
|
|
const STATUS = ['active', 'pending', 'banned'];
|
|
|
|
async function partyUser() {
|
|
const alice = await prisma.partyUser.upsert({
|
|
where: { email: 'alice@prisma.io' },
|
|
update: {},
|
|
create: {
|
|
email: 'alice@prisma.io',
|
|
name: 'Alice',
|
|
username: 'pualice',
|
|
password: 'Aa12345678',
|
|
emailVerified: new Date(),
|
|
phoneNumber: '+85291234567',
|
|
company: 'helloworld company',
|
|
status: STATUS[0],
|
|
role: ROLE[0],
|
|
isVerified: true,
|
|
sex: 'F',
|
|
},
|
|
});
|
|
|
|
await prisma.partyUser.upsert({
|
|
where: { email: 'demo@minimals.cc' },
|
|
update: {},
|
|
create: {
|
|
email: 'demo@minimals.cc',
|
|
password: '@2Minimal',
|
|
//
|
|
username: 'pudemo',
|
|
name: 'Demo',
|
|
emailVerified: new Date(),
|
|
phoneNumber: '+85291234568',
|
|
company: 'helloworld company',
|
|
status: STATUS[1],
|
|
role: ROLE[1],
|
|
isVerified: true,
|
|
avatarUrl: 'https://images.unsplash.com/photo-1619970096024-c7b438a3b82a',
|
|
rank: 'user',
|
|
sex: 'M',
|
|
},
|
|
});
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
const CJK_LOCALES = {
|
|
en: enFaker,
|
|
zh: zhFaker,
|
|
ja: jaFaker,
|
|
ko: koFaker,
|
|
tw: twFaker,
|
|
};
|
|
|
|
function getRandomCJKFaker() {
|
|
const locales = Object.keys(CJK_LOCALES);
|
|
const randomKey = locales[Math.floor(Math.random() * locales.length)] as keyof typeof CJK_LOCALES;
|
|
return CJK_LOCALES[randomKey];
|
|
}
|
|
|
|
const randomFaker = getRandomCJKFaker();
|
|
|
|
await prisma.partyUser.upsert({
|
|
where: { email: `party_user${i}@prisma.io` },
|
|
update: {},
|
|
create: {
|
|
email: `party_user${i}@prisma.io`,
|
|
name: `Party Dummy ${i}`,
|
|
username: `pu${i.toString()}`,
|
|
password: 'Aa12345678',
|
|
emailVerified: new Date(),
|
|
phoneNumber: `+8529123456${i.toString()}`,
|
|
company: randomFaker.company.name(),
|
|
role: ROLE[Math.floor(Math.random() * ROLE.length)],
|
|
status: STATUS[Math.floor(Math.random() * STATUS.length)],
|
|
isVerified: true,
|
|
sex: i % 2 ? 'F' : 'M',
|
|
},
|
|
});
|
|
}
|
|
|
|
console.log('seed partyUser done');
|
|
}
|
|
|
|
const partyUserSeed = partyUser()
|
|
.then(async () => {
|
|
await prisma.$disconnect();
|
|
})
|
|
.catch(async (e) => {
|
|
console.error(e);
|
|
await prisma.$disconnect();
|
|
process.exit(1);
|
|
});
|
|
|
|
export { partyUserSeed };
|