🗃️ Store active space for user (#1807)

This commit is contained in:
Luke Vella 2025-07-11 10:35:28 +01:00 committed by GitHub
parent d93baeafd9
commit d672eb1012
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 196 additions and 94 deletions

View file

@ -1,68 +1,72 @@
import { prisma } from "@rallly/database";
import dayjs from "dayjs";
async function createUser({
id,
name,
email,
timeZone,
space,
}: {
id: string;
name: string;
email: string;
timeZone: string;
space: {
id: string;
name: string;
};
}) {
const user = await prisma.user.create({
data: {
id,
name,
email,
timeZone,
spaces: {
create: space,
},
},
});
await prisma.spaceMember.create({
data: {
spaceId: space.id,
userId: id,
role: "OWNER",
},
});
await prisma.user.update({
where: { id },
data: {
activeSpaceId: space.id,
},
});
return user;
}
export async function seedUsers() {
console.info("Seeding users...");
const freeUser = await prisma.user.upsert({
where: { email: "dev@rallly.co" },
update: {},
create: {
id: "free-user",
name: "Dev User",
email: "dev@rallly.co",
timeZone: "America/New_York",
spaces: {
create: {
id: "space-1",
name: "Personal",
},
},
const freeUser = await createUser({
id: "free-user",
name: "Dev User",
email: "dev@rallly.co",
timeZone: "America/New_York",
space: {
id: "space-1",
name: "Personal",
},
});
await prisma.spaceMember.create({
data: {
spaceId: "space-1",
userId: "free-user",
role: "OWNER",
},
});
const proUser = await prisma.user.upsert({
where: { email: "dev+pro@rallly.co" },
update: {},
create: {
id: "pro-user",
name: "Pro User",
email: "dev+pro@rallly.co",
spaces: {
create: {
id: "space-2",
name: "Personal",
},
},
subscription: {
create: {
id: "sub_123",
currency: "usd",
amount: 700,
interval: "month",
status: "active",
active: true,
priceId: "price_123",
periodStart: new Date(),
periodEnd: dayjs().add(1, "month").toDate(),
spaceId: "space-2",
},
},
},
});
await prisma.spaceMember.create({
data: {
spaceId: "space-2",
userId: "pro-user",
role: "OWNER",
const proUser = await createUser({
id: "pro-user",
name: "Pro User",
email: "dev+pro@rallly.co",
timeZone: "America/New_York",
space: {
id: "space-2",
name: "Personal",
},
});