mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-23 19:27:25 +02:00
🌱 Create subscription
This commit is contained in:
parent
156e84c8b6
commit
b1c7e3a275
1 changed files with 26 additions and 1 deletions
|
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue