-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.ts
50 lines (44 loc) · 1.31 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
44
45
46
47
48
49
50
import { getRepository, Column, ColumnOptions } from "typeorm";
import { Recipe } from "./entities/recipe";
import { Rate } from "./entities/rate";
import { User } from "./entities/user";
export async function seedDatabase() {
const recipeRepository = getRepository(Recipe);
const ratingsRepository = getRepository(Rate);
const userRepository = getRepository(User);
const defaultUser = userRepository.create({
email: "test@github.com",
nickname: "19majkel94",
password: "s3cr3tp4ssw0rd",
});
await userRepository.save(defaultUser);
const recipes = recipeRepository.create([
{
title: "Recipe 1",
description: "Desc 1",
author: defaultUser,
ratings: ratingsRepository.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: ratingsRepository.create([
{ value: 2, user: defaultUser },
{ value: 4, user: defaultUser },
]),
},
]);
await recipeRepository.save(recipes);
return {
defaultUser,
};
}
export function RelationColumn(options?: ColumnOptions) {
return Column({ nullable: true, ...options });
}