Added rename of Game, Wall and Category
This commit is contained in:
147
src/games.js
147
src/games.js
@@ -83,13 +83,16 @@ export function initGames(app, db) {
|
|||||||
app.post('/game', createGame);
|
app.post('/game', createGame);
|
||||||
app.delete('/game/:gameid', deleteGameRoute);
|
app.delete('/game/:gameid', deleteGameRoute);
|
||||||
app.get('/games', fetchGames);
|
app.get('/games', fetchGames);
|
||||||
|
app.post('/game/rename', renameGame);
|
||||||
|
|
||||||
app.get('/wall', fetchWall);
|
app.get('/wall', fetchWall);
|
||||||
app.get('/walls/:gameid', fetchWalls);
|
app.get('/walls/:gameid', fetchWalls);
|
||||||
app.post('/wall', createWall);
|
app.post('/wall', createWall);
|
||||||
app.delete('/wall/:wallid', deleteWallRoute);
|
app.delete('/wall/:wallid', deleteWallRoute);
|
||||||
|
app.post('/wall/rename', renameWall);
|
||||||
|
|
||||||
app.get('/category', fetchCategory);
|
app.get('/category', fetchCategory);
|
||||||
|
app.post('/category/rename', renameCategory);
|
||||||
|
|
||||||
app.get('/question', fetchQuestion);
|
app.get('/question', fetchQuestion);
|
||||||
}
|
}
|
||||||
@@ -122,6 +125,54 @@ async function createGame(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
|
function renameGame(req, res) {
|
||||||
|
if (!checkStringProp(req.body, 'name')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!checkStringProp(req.body, 'gameid')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
let gameid = req.body.gameid;
|
||||||
|
let _id = new ObjectId(gameid);
|
||||||
|
let name = req.body.name;
|
||||||
|
|
||||||
|
cGames
|
||||||
|
.updateOne(
|
||||||
|
{
|
||||||
|
_id,
|
||||||
|
owner: req.user._id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.then((result) => {
|
||||||
|
if (result.modifiedCount === 1) res.sendStatus(200);
|
||||||
|
else {
|
||||||
|
console.error(
|
||||||
|
`Failed to modify exactly one Document. Instead modified: ${result.modifiedCount}`,
|
||||||
|
);
|
||||||
|
res.sendStatus(400);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
res.sendStatus(500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import('express').Request} req
|
* @param {import('express').Request} req
|
||||||
@@ -260,6 +311,54 @@ async function fetchCategory(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
|
function renameCategory(req, res) {
|
||||||
|
if (!checkStringProp(req.body, 'name')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!checkStringProp(req.body, 'categoryid')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
let categoryid = req.body.categoryid;
|
||||||
|
let _id = new ObjectId(categoryid);
|
||||||
|
let name = req.body.name;
|
||||||
|
|
||||||
|
cCategories
|
||||||
|
.updateOne(
|
||||||
|
{
|
||||||
|
_id,
|
||||||
|
owner: req.user._id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.then((result) => {
|
||||||
|
if (result.modifiedCount === 1) res.sendStatus(200);
|
||||||
|
else {
|
||||||
|
console.error(
|
||||||
|
`Failed to modify exactly one Document. Instead modified: ${result.modifiedCount}`,
|
||||||
|
);
|
||||||
|
res.sendStatus(400);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
res.sendStatus(500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import('express').Request} req
|
* @param {import('express').Request} req
|
||||||
@@ -310,6 +409,54 @@ async function fetchWalls(req, res) {
|
|||||||
res.status(200).send(await fetchedWalls.toArray());
|
res.status(200).send(await fetchedWalls.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
|
function renameWall(req, res) {
|
||||||
|
if (!checkStringProp(req.body, 'name')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!checkStringProp(req.body, 'wallid')) {
|
||||||
|
res.sendStatus(400);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
let wallid = req.body.wallid;
|
||||||
|
let _id = new ObjectId(wallid);
|
||||||
|
let name = req.body.name;
|
||||||
|
|
||||||
|
cWalls
|
||||||
|
.updateOne(
|
||||||
|
{
|
||||||
|
_id,
|
||||||
|
owner: req.user._id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$set: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.then((result) => {
|
||||||
|
if (result.modifiedCount === 1) res.sendStatus(200);
|
||||||
|
else {
|
||||||
|
console.error(
|
||||||
|
`Failed to modify exactly one Document. Instead modified: ${result.modifiedCount}`,
|
||||||
|
);
|
||||||
|
res.sendStatus(400);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
res.sendStatus(500);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {import('express').Request} req
|
* @param {import('express').Request} req
|
||||||
|
|||||||
Reference in New Issue
Block a user