feat(games): accept full Steam store URL in create()

Allow callers to pass either a raw Steam app ID or a full store URL (e.g. https://store.steampowered.com/app/730/...) in req.body.steamId.

In create() in controllers/games.js:

- normalize input into a local steamId variable: if the value includes store.steampowered.com, extract the numeric ID via match(/\d+/)[0], otherwise use the value as-is

- use the normalized steamId for both duplicate checks: user-scoped lookup (steamId + accessedBy.user) and global lookup

This lets users paste a copied store link directly without manually stripping the app ID, while keeping existing raw-ID behavior unchanged.
This commit is contained in:
2026-09-05 19:16:14 -04:00
parent a9b9fe1047
commit 748616df9d
+9 -4
View File
@@ -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) {