2022-02-10 10:44:44 +01:00
|
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
|
const db = new PrismaClient();
|
|
|
|
|
|
|
|
|
|
async function seed() {
|
2022-02-21 18:08:35 +01:00
|
|
|
const team = await db.team.create({
|
2022-02-10 10:44:44 +01:00
|
|
|
data: {
|
2022-02-21 18:08:35 +01:00
|
|
|
id: "Family",
|
|
|
|
|
description: "My family",
|
2022-02-10 10:44:44 +01:00
|
|
|
icon: "♥️",
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-02-21 18:08:35 +01:00
|
|
|
const user1 = await db.user.create({
|
2022-02-10 10:44:44 +01:00
|
|
|
data: {
|
2022-02-21 18:08:35 +01:00
|
|
|
username: "user1",
|
2022-02-10 10:44:44 +01:00
|
|
|
passwordHash:
|
2022-02-21 18:08:35 +01:00
|
|
|
"$2b$10$K7L1OJ45/4Y2nIvhRVpCe.FSmhDdWoXehVzJptJ/op0lSsvqNu/1u", // twixrox
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
icon: "🧑💻",
|
2022-02-14 11:47:08 +01:00
|
|
|
theme: "dark",
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
});
|
2022-02-21 18:08:35 +01:00
|
|
|
const user2 = await db.user.create({
|
2022-02-10 10:44:44 +01:00
|
|
|
data: {
|
2022-02-21 18:08:35 +01:00
|
|
|
username: "user2",
|
2022-02-10 10:44:44 +01:00
|
|
|
passwordHash:
|
|
|
|
|
"$2b$10$K7L1OJ45/4Y2nIvhRVpCe.FSmhDdWoXehVzJptJ/op0lSsvqNu/1u",
|
2022-02-21 18:08:35 +01:00
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
icon: "💃",
|
2022-02-14 11:47:08 +01:00
|
|
|
theme: "emerald",
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const expenses = [
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Groceries",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: 100,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user1.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Groceries",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: 70,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user2.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Rent",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: 500,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user2.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// transaction between users
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Rent",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: 250,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user1.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Rent",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: -250,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user2.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
2022-02-21 18:08:35 +01:00
|
|
|
description: "Dinner out",
|
2022-02-10 10:44:44 +01:00
|
|
|
amount: 50,
|
2022-02-21 18:08:35 +01:00
|
|
|
userId: user1.id,
|
|
|
|
|
teamId: team.id,
|
2022-02-10 10:44:44 +01:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
|
expenses.map((exp) => {
|
|
|
|
|
const data = { ...exp };
|
|
|
|
|
return db.expense.create({ data });
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
seed();
|