Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified build-start.sh
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions middlewares/fighter.validation.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { FIGHTER } from "../models/fighter.js";

const createFighterValid = (req, res, next) => {
// TODO: Implement validatior for FIGHTER entity during creation
const fighter = new FIGHTER(req.body);
if (!fighter.isValid()) {
return res.status(400).send({ error: "Invalid fighter" });
}
next();
};

const updateFighterValid = (req, res, next) => {
// TODO: Implement validatior for FIGHTER entity during update
req.fighter = req.db.getFighterById(req.params.id);
next();
};

Expand Down
11 changes: 11 additions & 0 deletions middlewares/response.middleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
const responseMiddleware = (req, res, next) => {
// TODO: Implement middleware that returns result of the query
console.log('Request received');
if (!res.locals.data) return next(new Error("No data found in locals"));
else {
let statusCode = res.statusCode || 200;
res.jsonp({
status: 'success',
statusCode,
message: null,
data: res.locals.data
});
}
next();
};

Expand Down
11 changes: 11 additions & 0 deletions middlewares/user.validation.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import { USER } from "../models/user.js";

const createUserValid = (req, res, next) => {
// TODO: Implement validatior for USER entity during creation
const userData = req.body;
if (!USER.isValid(userData)) {
return res.status(400).send({ error: "Invalid User Data" });
}
next();
};

const updateUserValid = (req, res, next) => {
// TODO: Implement validatior for user entity during update
const id = req.params.id;
const data = req.body;
if (!data || !Object.keys(data).length) {
return res.status(400).json({ error: "No fields provided to update" });
} else if (!USER.hasId(id)) {
return res.status(400).json({ error: `User with ID ${id} not found`});
}
next();
};

Expand Down
Loading