-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulatedb.js
134 lines (112 loc) · 4.49 KB
/
populatedb.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/env node
const fs = require('fs');
// Get arguments passed on command line
const userArgs = process.argv.slice(2);
const Game = require("./models/game");
const Category = require("./models/category");
const games = [];
const categories = [];
const mongoose = require("mongoose");
mongoose.set("strictQuery", false);
const mongoDB = userArgs[0];
main().catch((err) => console.log(err));
async function main() {
console.log("Debug: About to connect");
await mongoose.connect(mongoDB);
console.log("Debug: Should be connected?");
await createCategories();
await createGames();
console.log("Debug: Closing mongoose");
mongoose.connection.close();
}
// We pass the index to the ...Create functions so that, for example,
// genre[0] will always be the Fantasy genre, regardless of the order
// in which the elements of promise.all's argument complete.
async function categoryCreate(index, name, desc) {
const category = new Category({ name: name, description: desc });
await category.save();
categories[index] = category;
console.log(`Added category: ${name}`);
}
async function gameCreate(index, name, dev, desc, price, category, stock, imgObj) {
const gameDetail = {
name: name,
developer: dev,
description: desc,
price: price,
category: category,
stock: stock,
img: imgObj
};
const game = new Game(gameDetail);
await game.save();
games[index] = game;
console.log(`Added game: ${name}`);
}
async function createCategories() {
console.log("Adding categories");
await Promise.all([
categoryCreate(0, "Action", "The action game category is an electrifying realm of gaming that thrusts players into adrenaline-charged scenarios filled with intense combat, daring feats, and heart-pounding excitement."),
categoryCreate(1, "Strategy", "The strategy game category is a captivating world where players immerse themselves in the art of planning, decision-making, and tactical mastery."),
categoryCreate(2, "Sports", "The sports game category immerses players in the exhilarating world of athletic competition, offering realistic simulations and arcade-style experiences across a wide variety of sports."),
]);
}
async function createGames() {
console.log("Adding Games");
await Promise.all([
gameCreate(0,
"Elden Ring",
"FromSoftware Inc.",
"THE NEW FANTASY ACTION RPG. Rise, Tarnished, and be guided by grace to brandish the power of the Elden Ring and become an Elden Lord in the Lands Between.",
39.99,
[categories[0]],
200,
{data: fs.readFileSync(__dirname + '/public/images/elden-ring.jpg'), contentType: 'image/jpg'}
),
gameCreate(1,
"Tekken 8",
"Bandai Namco Studios Inc.FromSoftware Inc.",
"Tekken 8 is a fighting game developed by Bandai Namco Studios and Arika.",
69.99,
[categories[0]],
100,
{data: fs.readFileSync(__dirname + '/public/images/tekken.jpeg'), contentType: 'image/jpg'}
),
gameCreate(2,
"Sid Meier's Civilization VI",
"Firaxis Games, Aspyr (Mac), Aspyr (Linux)",
"Sid Meier's Civilization VI is a turn-based strategy 4X video game developed by Firaxis Games and published by 2K.",
30.15,
[categories[1]],
250,
{data: fs.readFileSync(__dirname + '/public/images/civilization-4.jpg'), contentType: 'image/jpg'}
),
gameCreate(3,
"Hearts of Iron IV",
"Paradox Development Studio Valve",
"Victory is at your fingertips! Your ability to lead your nation is your supreme weapon, the strategy game Hearts of Iron IV lets you take command of any nation in World War II; the most engaging conflict in world history.",
11.99,
[categories[1]],
50,
{data: fs.readFileSync(__dirname + '/public/images/hearts-iron.jpg'), contentType: 'image/jpg'}
),
gameCreate(4,
"NBA 2K24",
"Visual Concepts ",
"NBA 2K24 is a 2023 basketball video game developed by Visual Concepts Austin and published by 2K, based on the National Basketball Association.",
9.59,
[categories[2]],
300,
{data: fs.readFileSync(__dirname + '/public/images/nba.jpeg'), contentType: 'image/jpg'}
),
gameCreate(5,
"eFootball™ 2024",
"KONAMI",
"The classic action soccer game with the most up-to-date data! Enjoy the fever pitch of 'real soccer' in eFootball™ 2024!",
11.99,
[categories[2]],
456,
{data: fs.readFileSync(__dirname + '/public/images/football.jpeg'), contentType: 'image/jpg'}
)
]);
}