2021-09-02 15:20:36 +00:00
|
|
|
import { hashPassword } from "../lib/auth";
|
|
|
|
import { Prisma, PrismaClient } from "@prisma/client";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
|
|
|
|
async function createUserAndEventType(opts: {
|
|
|
|
user: Omit<Prisma.UserCreateArgs["data"], "password" | "email"> & { password: string; email: string };
|
|
|
|
eventTypes: Array<Prisma.EventTypeCreateArgs["data"]>;
|
|
|
|
}) {
|
|
|
|
const userData: Prisma.UserCreateArgs["data"] = {
|
|
|
|
...opts.user,
|
|
|
|
password: await hashPassword(opts.user.password),
|
|
|
|
emailVerified: new Date(),
|
2021-09-06 13:51:15 +00:00
|
|
|
completedOnboarding: true,
|
2021-09-02 15:20:36 +00:00
|
|
|
};
|
|
|
|
const user = await prisma.user.upsert({
|
|
|
|
where: { email: opts.user.email },
|
|
|
|
update: userData,
|
|
|
|
create: userData,
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log(
|
2021-09-06 13:51:15 +00:00
|
|
|
`👤 Upserted '${opts.user.username}' with email "${opts.user.email}" & password "${opts.user.password}". Booking page 👉 http://localhost:3000/${opts.user.username}`
|
2021-09-02 15:20:36 +00:00
|
|
|
);
|
|
|
|
for (const rawData of opts.eventTypes) {
|
|
|
|
const eventTypeData: Prisma.EventTypeCreateArgs["data"] = { ...rawData };
|
|
|
|
eventTypeData.userId = user.id;
|
|
|
|
await prisma.eventType.upsert({
|
|
|
|
where: {
|
2021-09-06 13:51:15 +00:00
|
|
|
userId_slug: {
|
|
|
|
slug: eventTypeData.slug,
|
|
|
|
userId: user.id,
|
|
|
|
},
|
2021-09-02 15:20:36 +00:00
|
|
|
},
|
|
|
|
update: eventTypeData,
|
|
|
|
create: eventTypeData,
|
|
|
|
});
|
|
|
|
console.log(
|
|
|
|
`\t📆 Event type ${eventTypeData.slug}, length ${eventTypeData.length}: http://localhost:3000/${user.username}/${eventTypeData.slug}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await createUserAndEventType({
|
|
|
|
user: {
|
|
|
|
email: "free@example.com",
|
|
|
|
password: "free",
|
|
|
|
username: "free",
|
2021-09-06 13:51:15 +00:00
|
|
|
plan: "FREE",
|
2021-09-02 15:20:36 +00:00
|
|
|
},
|
|
|
|
eventTypes: [
|
|
|
|
{
|
|
|
|
title: "30min",
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "60min",
|
|
|
|
slug: "60min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2021-09-06 13:51:15 +00:00
|
|
|
|
|
|
|
await createUserAndEventType({
|
|
|
|
user: {
|
|
|
|
email: "free-first-hidden@example.com",
|
|
|
|
password: "free-first-hidden",
|
|
|
|
username: "free-first-hidden",
|
|
|
|
plan: "FREE",
|
|
|
|
},
|
|
|
|
eventTypes: [
|
|
|
|
{
|
|
|
|
title: "30min",
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "60min",
|
|
|
|
slug: "60min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2021-09-02 15:20:36 +00:00
|
|
|
await createUserAndEventType({
|
|
|
|
user: {
|
|
|
|
email: "pro@example.com",
|
|
|
|
password: "pro",
|
|
|
|
username: "pro",
|
2021-09-06 13:51:15 +00:00
|
|
|
plan: "PRO",
|
2021-09-02 15:20:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
eventTypes: [
|
|
|
|
{
|
|
|
|
title: "30min",
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "60min",
|
|
|
|
slug: "60min",
|
|
|
|
length: 60,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
await createUserAndEventType({
|
|
|
|
user: {
|
|
|
|
email: "trial@example.com",
|
|
|
|
password: "trial",
|
|
|
|
username: "trial",
|
2021-09-06 13:51:15 +00:00
|
|
|
plan: "TRIAL",
|
2021-09-02 15:20:36 +00:00
|
|
|
},
|
|
|
|
eventTypes: [
|
|
|
|
{
|
|
|
|
title: "30min",
|
|
|
|
slug: "30min",
|
|
|
|
length: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "60min",
|
|
|
|
slug: "60min",
|
|
|
|
length: 60,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
await prisma.$disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => {
|
|
|
|
console.log("🌱 Seeded db");
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.error(e);
|
|
|
|
process.exit(1);
|
|
|
|
});
|