97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
import { PrismaClient } from '@prisma/client'
|
|
import bcrypt from 'bcryptjs'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function main() {
|
|
const password = await bcrypt.hash('Android@2020', 12)
|
|
|
|
// 1. Criar Admin
|
|
await prisma.admin.upsert({
|
|
where: { email: 'admin@temfut.com' },
|
|
update: {},
|
|
create: {
|
|
email: 'admin@temfut.com',
|
|
name: 'Super Admin',
|
|
password: password,
|
|
role: 'SUPER_ADMIN'
|
|
}
|
|
})
|
|
|
|
// 2. Criar Pelada de Exemplo
|
|
const group = await prisma.group.upsert({
|
|
where: { email: 'erik@idealpages.com.br' },
|
|
update: {},
|
|
create: {
|
|
name: 'Fut de Quarta',
|
|
slug: 'futdequarta',
|
|
email: 'erik@idealpages.com.br',
|
|
password: password,
|
|
status: 'ACTIVE',
|
|
plan: 'PRO',
|
|
primaryColor: '#10b981',
|
|
secondaryColor: '#000000'
|
|
}
|
|
})
|
|
|
|
// 3. Criar Jogador Líder (Rei)
|
|
await prisma.player.upsert({
|
|
where: { number_groupId: { number: 10, groupId: group.id } },
|
|
update: {},
|
|
create: {
|
|
name: 'Erik Ideal',
|
|
number: 10,
|
|
position: 'MEI',
|
|
level: 5,
|
|
// @ts-ignore
|
|
isLeader: true,
|
|
groupId: group.id
|
|
}
|
|
})
|
|
|
|
// 4. Adicionar alguns jogadores para teste
|
|
const players = [
|
|
{ name: 'Ricardo Rocha', number: 4, position: 'ZAG', level: 4 },
|
|
{ name: 'Bebeto', number: 7, position: 'ATA', level: 5 },
|
|
{ name: 'Dunga', number: 8, position: 'VOL', level: 4 },
|
|
{ name: 'Taffarel', number: 1, position: 'GOL', level: 5 },
|
|
]
|
|
|
|
for (const p of players) {
|
|
await prisma.player.upsert({
|
|
where: { number_groupId: { number: p.number, groupId: group.id } },
|
|
update: {},
|
|
create: {
|
|
...p,
|
|
groupId: group.id
|
|
}
|
|
})
|
|
}
|
|
|
|
// 5. Criar uma partida agendada
|
|
const nextWednesday = new Date()
|
|
nextWednesday.setDate(nextWednesday.getDate() + ((7 - nextWednesday.getDay() + 3) % 7 || 7))
|
|
nextWednesday.setHours(20, 0, 0, 0)
|
|
|
|
await prisma.match.create({
|
|
data: {
|
|
groupId: group.id,
|
|
date: nextWednesday,
|
|
location: 'Arena Central',
|
|
maxPlayers: 20,
|
|
status: 'SCHEDULED'
|
|
}
|
|
})
|
|
|
|
console.log('Seed concluído com sucesso!')
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|