🌱 Create subscription

This commit is contained in:
Luke Vella 2025-07-14 15:35:26 +01:00
parent 156e84c8b6
commit b1c7e3a275
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C

View file

@ -1,4 +1,5 @@
import { prisma } from "@rallly/database"; import { prisma } from "@rallly/database";
import dayjs from "dayjs";
async function createUser({ async function createUser({
id, id,
@ -14,6 +15,7 @@ async function createUser({
space: { space: {
id: string; id: string;
name: string; name: string;
isPro: boolean;
}; };
}) { }) {
const user = await prisma.user.create({ const user = await prisma.user.create({
@ -23,11 +25,32 @@ async function createUser({
email, email,
timeZone, timeZone,
spaces: { spaces: {
create: space, create: {
id: space.id,
name: space.name,
},
}, },
}, },
}); });
if (space.isPro) {
await prisma.subscription.create({
data: {
id: "sub-1",
spaceId: space.id,
userId: user.id,
active: true,
amount: 700,
currency: "USD",
interval: "month",
periodStart: new Date(),
periodEnd: dayjs().add(1, "month").toDate(),
priceId: "price_1M6ZJZGZJZJZJZJZJZJZJZJZ",
status: "active",
},
});
}
await prisma.spaceMember.create({ await prisma.spaceMember.create({
data: { data: {
spaceId: space.id, spaceId: space.id,
@ -56,6 +79,7 @@ export async function seedUsers() {
space: { space: {
id: "space-1", id: "space-1",
name: "Personal", name: "Personal",
isPro: false,
}, },
}); });
@ -67,6 +91,7 @@ export async function seedUsers() {
space: { space: {
id: "space-2", id: "space-2",
name: "Personal", name: "Personal",
isPro: true,
}, },
}); });