Skip to content

Scheduling infrastructure for absolutely everyone.

Added Team with 'pro' and 'free' as members (#1063)

Alex van Andel94f3ae1c648c
diff --git a/scripts/seed.ts b/scripts/seed.ts
index dc166327dce..c47181bd82c 100644
--- a/scripts/seed.ts
+++ b/scripts/seed.ts
@@ -1,4 +1,4 @@
-import { Prisma, PrismaClient, UserPlan } from "@prisma/client";
+import { MembershipRole, Prisma, PrismaClient, UserPlan } from "@prisma/client";
import dayjs from "dayjs";
import { uuid } from "short-uuid";
@@ -34,8 +34,9 @@ async function createUserAndEventType(opts: {
});
console.log(
- `πŸ‘€ Upserted '${opts.user.username}' with email "${opts.user.email}" & password "${opts.user.password}". Booking page πŸ‘‰ http://localhost:3000/${opts.user.username}`
+ `πŸ‘€ Upserted '${opts.user.username}' with email "${opts.user.email}" & password "${opts.user.password}". Booking page πŸ‘‰ ${process.env.BASE_URL}/${opts.user.username}`
);
+
for (const eventTypeInput of opts.eventTypes) {
const { _bookings: bookingInputs = [], ...eventTypeData } = eventTypeInput;
eventTypeData.userId = user.id;
@@ -57,7 +58,7 @@ async function createUserAndEventType(opts: {
if (eventType) {
console.log(
- `\tπŸ“† Event type ${eventTypeData.slug} already seems seeded - http://localhost:3000/${user.username}/${eventTypeData.slug}`
+ `\tπŸ“† Event type ${eventTypeData.slug} already seems seeded - ${process.env.BASE_URL}/${user.username}/${eventTypeData.slug}`
);
continue;
}
@@ -66,7 +67,7 @@ async function createUserAndEventType(opts: {
});
console.log(
- `\tπŸ“† Event type ${eventTypeData.slug}, length ${eventTypeData.length}min - http://localhost:3000/${user.username}/${eventTypeData.slug}`
+ `\tπŸ“† Event type ${eventTypeData.slug}, length ${eventTypeData.length}min - ${process.env.BASE_URL}/${user.username}/${eventTypeData.slug}`
);
for (const bookingInput of bookingInputs) {
await prisma.booking.create({
@@ -99,6 +100,49 @@ async function createUserAndEventType(opts: {
);
}
}
+
+ return user;
+}
+
+async function createTeamAndAddUsers(
+ teamInput: Prisma.TeamCreateInput,
+ users: { id: number; username: string; role?: MembershipRole }[]
+) {
+ const createTeam = async (team: Prisma.TeamCreateInput) => {
+ try {
+ return await prisma.team.create({
+ data: {
+ ...team,
+ },
+ });
+ } catch (_err) {
+ if (_err instanceof Error && _err.message.indexOf("Unique constraint failed on the fields") !== -1) {
+ console.log(`Team '${team.name}' already exists, skipping.`);
+ return;
+ }
+ throw _err;
+ }
+ };
+
+ const team = await createTeam(teamInput);
+ if (!team) {
+ return;
+ }
+
+ console.log(`🏒 Created team '${teamInput.name}' - ${process.env.BASE_URL}/team/${team.slug}`);
+
+ for (const user of users) {
+ const { role = MembershipRole.OWNER, id, username } = user;
+ await prisma.membership.create({
+ data: {
+ teamId: team.id,
+ userId: id,
+ role: role,
+ accepted: true,
+ },
+ });
+ console.log(`\tπŸ‘€ Added '${teamInput.name}' membership for '${username}' with role '${role}'`);
+ }
}
async function main() {
@@ -218,6 +262,45 @@ async function main() {
],
});
+ const freeUserTeam = await createUserAndEventType({
+ user: {
+ email: "[email protected]",
+ password: "teamfree",
+ username: "teamfree",
+ name: "Team Free Example",
+ plan: "FREE",
+ },
+ eventTypes: [],
+ });
+
+ const proUserTeam = await createUserAndEventType({
+ user: {
+ email: "[email protected]",
+ password: "teampro",
+ username: "teampro",
+ name: "Team Pro Example",
+ plan: "PRO",
+ },
+ eventTypes: [],
+ });
+
+ await createTeamAndAddUsers(
+ {
+ name: "Seeded Team",
+ slug: "seeded-team",
+ },
+ [
+ {
+ id: proUserTeam.id,
+ username: proUserTeam.name || "Unknown",
+ },
+ {
+ id: freeUserTeam.id,
+ username: freeUserTeam.name || "Unknown",
+ },
+ ]
+ );
+
await prisma.$disconnect();
}