diff --git a/controllers/games.js b/controllers/games.js index 1e393cf..530ef6b 100644 --- a/controllers/games.js +++ b/controllers/games.js @@ -77,6 +77,11 @@ export const show = asyncHandler(async (req, res, next) => { */ export const create = asyncHandler(async (req, res, next) => { let oldGame; + let steamId; + + if (req.body.steamId.includes("store.steampowered.com")) + steamId = req.body.steamId.match(/\d+/)[0]; + else steamId = req.body.steamId; if (req.body.shortDesc && isValid(req.body.shortDesc)) req.body.shortDesc = decode(req.body.shortDesc); @@ -115,9 +120,9 @@ export const create = asyncHandler(async (req, res, next) => { )) : ""; - req.body.steamId.length > 0 + steamId.length > 0 ? (oldGame = await Game.findOne({ - steamId: req.body.steamId, + steamId: steamId, "accessedBy.user": req.user.id, })) : (oldGame = await Game.findOne({ @@ -133,8 +138,8 @@ export const create = asyncHandler(async (req, res, next) => { ), ); - req.body.steamId.length > 0 - ? (oldGame = await Game.findOne({ steamId: req.body.steamId })) + steamId.length > 0 + ? (oldGame = await Game.findOne({ steamId: steamId })) : (oldGame = await Game.findOne({ title: req.body.title })); if (oldGame) {