fix for game controller
This commit is contained in:
parent
9f21d37002
commit
9992dda27a
@ -20,7 +20,7 @@ module.exports = {
|
||||
|
||||
|
||||
create: async function (req, res) {
|
||||
const gameCode = req.body.code;
|
||||
var gameCode = req.body.code;
|
||||
const passp = req.body.pass;
|
||||
|
||||
try {
|
||||
@ -45,18 +45,25 @@ module.exports = {
|
||||
'Authorization': 'Bearer ' + mData.access_token
|
||||
}
|
||||
|
||||
gameCode = parseInt(gameCode)
|
||||
|
||||
response = await fetch(
|
||||
"https://api.igdb.com/v4/games",
|
||||
{
|
||||
method: 'POST',
|
||||
headers: mheaders,
|
||||
body: `fields name; where id = ${gameCode};`
|
||||
body: `fields name, first_release_date; where id = ${gameCode};`
|
||||
}
|
||||
)
|
||||
const gameData = await response.json()
|
||||
if (gameData.length == 0) {
|
||||
return res.status(404).json({ message: 'wrong code' });
|
||||
}
|
||||
|
||||
var date = new Date(gameData[0].first_release_date * 1000);
|
||||
const options = { day: 'numeric', month: 'short', year: 'numeric' }
|
||||
var dateStr = date.toLocaleDateString(undefined, options);
|
||||
|
||||
|
||||
response = await fetch(
|
||||
"https://api.igdb.com/v4/covers",
|
||||
@ -67,21 +74,11 @@ module.exports = {
|
||||
}
|
||||
)
|
||||
const coverData = await response.json()
|
||||
|
||||
response = await fetch(
|
||||
"https://api.igdb.com/v4/release_dates",
|
||||
{
|
||||
method: 'POST',
|
||||
headers: mheaders,
|
||||
body: `fields human; where game = ${gameCode};`
|
||||
}
|
||||
)
|
||||
const releasedData = await response.json()
|
||||
|
||||
|
||||
const game = new GameModel({
|
||||
code: gameCode,
|
||||
title: gameData[0].name,
|
||||
released: releasedData[0].human,
|
||||
released: dateStr,
|
||||
webImg: `https://images.igdb.com/igdb/image/upload/t_cover_big/${coverData[0].image_id}.jpg`,
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user