-
-
Notifications
You must be signed in to change notification settings - Fork 678
/
helpers.ts
38 lines (34 loc) · 1.18 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { type EntityManager } from "@mikro-orm/core";
import { Rating, Recipe, User } from "./entities";
export async function seedDatabase(em: EntityManager) {
const defaultUser = em.create(User, {
email: "[email protected]",
nickname: "administrator",
password: "s3cr3tp4ssw0rd",
});
em.persist(defaultUser);
const recipe1 = em.create(Recipe, {
title: "Recipe 1",
description: "Desc 1",
author: defaultUser,
});
recipe1.ratings.add(
em.create(Rating, { value: 2, user: defaultUser, recipe: recipe1 }),
em.create(Rating, { value: 4, user: defaultUser, recipe: recipe1 }),
em.create(Rating, { value: 5, user: defaultUser, recipe: recipe1 }),
em.create(Rating, { value: 3, user: defaultUser, recipe: recipe1 }),
em.create(Rating, { value: 4, user: defaultUser, recipe: recipe1 }),
);
em.persist(recipe1);
const recipe2 = em.create(Recipe, {
title: "Recipe 2",
author: defaultUser,
});
recipe2.ratings.add(
em.create(Rating, { value: 2, user: defaultUser, recipe: recipe2 }),
em.create(Rating, { value: 4, user: defaultUser, recipe: recipe2 }),
);
em.persist(recipe2);
await em.flush();
return { defaultUser };
}