-
-
Notifications
You must be signed in to change notification settings - Fork 678
/
helpers.ts
43 lines (39 loc) · 1.15 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
39
40
41
42
43
import { dataSource } from "./datasource";
import { Rating, Recipe, User } from "./entities";
export async function seedDatabase() {
const recipeRepository = dataSource.getRepository(Recipe);
const ratingRepository = dataSource.getRepository(Rating);
const userRepository = dataSource.getRepository(User);
const defaultUser = userRepository.create({
email: "[email protected]",
nickname: "administrator",
password: "s3cr3tp4ssw0rd",
});
await userRepository.save(defaultUser);
const recipes = recipeRepository.create([
{
title: "Recipe 1",
description: "Desc 1",
author: defaultUser,
ratings: ratingRepository.create([
{ value: 2, user: defaultUser },
{ value: 4, user: defaultUser },
{ value: 5, user: defaultUser },
{ value: 3, user: defaultUser },
{ value: 4, user: defaultUser },
]),
},
{
title: "Recipe 2",
author: defaultUser,
ratings: ratingRepository.create([
{ value: 2, user: defaultUser },
{ value: 4, user: defaultUser },
]),
},
]);
await recipeRepository.save(recipes);
return {
defaultUser,
};
}