explit/prisma/seed.ts

84 lines
1.6 KiB
TypeScript
Raw Normal View History

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