Spaces:
Runtime error
Runtime error
Download utils/controllerResponses.js from faridaqurr/tinfo-web-server: direct link, hf CLI and curl.
- Browser
- Download file 647 Bytes
-
https://huggingface.co/spaces/faridaqurr/tinfo-web-server/resolve/main/utils/controllerResponses.js
- Command line
-
hf download hf://spaces/faridaqurr/tinfo-web-server/utils/controllerResponses.js
-
curl -L -o controllerResponses.js https://huggingface.co/spaces/faridaqurr/tinfo-web-server/resolve/main/utils/controllerResponses.js
647 Bytes
| const { isValidObjectId } = require('../validation/commonValidation'); | |
| const ensureValidIdOrRespond = (res, id, entityLabel) => { | |
| if (!isValidObjectId(id)) { | |
| res.status(400).json({ message: `Invalid ${entityLabel} ID` }); | |
| return false; | |
| } | |
| return true; | |
| }; | |
| const findByIdOrRespondNotFound = async ({ Model, id, res, notFoundMessage, lean = false }) => { | |
| const query = Model.findById(id); | |
| const doc = lean ? await query.lean() : await query; | |
| if (!doc) { | |
| res.status(404).json({ message: notFoundMessage }); | |
| return null; | |
| } | |
| return doc; | |
| }; | |
| module.exports = { | |
| ensureValidIdOrRespond, | |
| findByIdOrRespondNotFound, | |
| }; | |