-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f8122f
commit 92fa8fb
Showing
13 changed files
with
226 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Model, Field } from "json-modelizer"; | ||
|
||
export default class History extends Model { | ||
static _table = "history"; | ||
static schema = {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Model, Field } from "json-modelizer"; | ||
|
||
export default class Recipe extends Model { | ||
static _table = "recipes"; | ||
static schema = { | ||
name: Field.String, | ||
cuisine: Field.String, | ||
recipes: Field.String, | ||
imageUrl: Field.String, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import User from "./User.js"; | ||
import Recipe from "./Recipe.js"; | ||
import History from "./History.js"; | ||
|
||
Recipe.hasMany(History); | ||
History.belongsTo(User).as("user"); | ||
|
||
User.hasMany(History); | ||
History.belongsTo(Recipe).as("recipe"); | ||
|
||
export { User, Recipe, History }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default class RecipeResponse { | ||
static create(recipes) { | ||
return recipes.map((recipe) => ({ | ||
id: recipe.id, | ||
name: recipe.name, | ||
cuisine: recipe.cuisine, | ||
recipes: recipe.recipes, | ||
imageUrl: recipe.imageUrl, | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { History } from "../model/index.js"; | ||
|
||
History.clear(); | ||
|
||
History.create({ | ||
recipeId: 1, | ||
userId: 1, | ||
}); | ||
|
||
History.create({ | ||
recipeId: 2, | ||
userId: 1, | ||
}); | ||
|
||
History.create({ | ||
recipeId: 3, | ||
userId: 1, | ||
}); | ||
|
||
History.create({ | ||
recipeId: 2, | ||
userId: 2, | ||
}); | ||
|
||
History.create({ | ||
recipeId: 3, | ||
userId: 2, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Recipe } from "../model/index.js"; | ||
|
||
Recipe.clear(); | ||
|
||
Recipe.create({ | ||
name: "Nasi Goreng", | ||
cuisine: "Indonesia", | ||
recipes: "https://www.masakapahariini.com/resep/resep-nasi-goreng/", | ||
imageUrl: | ||
"https://kurio-img.kurioapps.com/20/10/10/a7e9eaa0-1c22-42b0-a11f-0a5ad1d30126.jpeg", | ||
}); | ||
|
||
Recipe.create({ | ||
name: "Nasi Kuning", | ||
cuisine: "Indonesia", | ||
recipes: "https://www.masakapahariini.com/resep/resep-nasi-kuning/", | ||
imageUrl: | ||
"https://www.sasa.co.id/medias/page_medias/nasi_kuning_rice_cooker.jpg", | ||
}); | ||
|
||
Recipe.create({ | ||
name: "Nasi Uduk", | ||
cuisine: "Indonesia", | ||
recipes: "https://www.masakapahariini.com/resep/resep-nasi-uduk/", | ||
imageUrl: | ||
"https://www.blibli.com/friends-backend/wp-content/uploads/2023/04/B300028-Cover-resep-nasi-uduk.jpg", | ||
}); | ||
|
||
Recipe.create({ | ||
name: "Nasi Liwet", | ||
cuisine: "Indonesia", | ||
recipes: "https://www.masakapahariini.com/resep/resep-nasi-liwet/", | ||
imageUrl: | ||
"https://assets.tmecosys.com/image/upload/t_web767x639/img/recipe/ras/Assets/a5786edc81a00587a470c25b13b10924/Derivates/b346197f18531cd806d52165903f8da023e3bf84.jpg", | ||
}); | ||
|
||
Recipe.create({ | ||
name: "Nasi Bakar", | ||
cuisine: "Indonesia", | ||
recipes: "https://www.masakapahariini.com/resep/resep-nasi-bakar/", | ||
imageUrl: | ||
"https://asset.kompas.com/crops/5GT-nmWVwnzqL6JiiAiyevIqSXU=/0x1774:3376x4025/750x500/data/photo/2022/12/06/638ee2b3e1b20.jpg", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { User } from "../model/index.js"; | ||
|
||
User.clear(); | ||
|
||
User.create({ | ||
name: "Fauzan", | ||
email: "fauzan@email.com", | ||
password: "12345678", | ||
token: generateToken(64), | ||
}); | ||
|
||
User.create({ | ||
name: "Hanif", | ||
email: "hanif@email.com", | ||
password: "12345678", | ||
token: generateToken(64), | ||
}); | ||
|
||
function generateToken(length) { | ||
let result = ""; | ||
const characters = | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
const charactersLength = characters.length; | ||
|
||
for (let i = 0; i < length; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
console.log("Seeding database..."); | ||
console.log("Seeding users..."); | ||
import "./UserSeeder.js"; | ||
|
||
console.log("Seeding recipes..."); | ||
import "./RecipeSeeder.js"; | ||
|
||
console.log("Seeding histories..."); | ||
import "./HistorySeeder.js"; | ||
|
||
console.log("Done!"); |