Skip to content
Snippets Groups Projects
Commit 5df96530 authored by alrwasheda's avatar alrwasheda :speech_balloon:
Browse files

PATCH-Methods: returning 200 + empty response when providing no input at all

parent a9a0990c
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,15 @@ const updateAccount = async (req: Request, res: Response) => {
//take what ever in req.body is, and pass it to update()
const input = req.body;
//return 200 with empty response if no data was given
if (Object.keys(input).length === 0) {
return res
.status(200)
.json({ success: true, result: {}, message: "noInputFound" });
}
//get given id
const givenId = req.params.id;
//check if given ID exists in DB
......
......@@ -120,6 +120,16 @@ const updateBoatById = async (req: Request, res: Response) => {
.json({ success: false, error: "MustBeCoordinator" });
}
//get new input
const input = req.body;
//return 200 with empty response if no data was given
if (Object.keys(input).length === 0) {
return res
.status(200)
.json({ success: true, result: {}, message: "noInputFound" });
}
//get id
const givenId = req.params.id;
......@@ -130,9 +140,6 @@ const updateBoatById = async (req: Request, res: Response) => {
return res.status(404).json({ success: false, error: "boatIdNotFound" });
}
//get new input
const input = req.body;
//try to update
const updatedBoat = await Boat.update(input, {
where: {
......
......@@ -112,6 +112,16 @@ const updateBoatTypeById = async (req: Request, res: Response) => {
.json({ success: false, error: "MustBeCoordinator" });
}
//get new input
const input = req.body;
//return 200 with empty response if no data was given
if (Object.keys(input).length === 0) {
return res
.status(200)
.json({ success: true, result: {}, message: "noInputFound" });
}
//get id
const givenId = req.params.id;
......@@ -124,9 +134,6 @@ const updateBoatTypeById = async (req: Request, res: Response) => {
.json({ success: false, error: "boatTypeIdNotFound" });
}
//get new input
const input = req.body;
//try to update
const updatedBoatType = await BoatType.update(input, {
where: {
......
......@@ -12,18 +12,16 @@ const showCurrentUserController = async (req: Request, res: Response) => {
},
});
res
.status(200)
.json({
success: true,
result: {
id: currentUserData.id,
first_name: currentUserData.first_name,
last_name: currentUserData.last_name,
email: currentUserData.email,
role: currentUserData.role,
},
});
res.status(200).json({
success: true,
result: {
id: currentUserData.id,
first_name: currentUserData.first_name,
last_name: currentUserData.last_name,
email: currentUserData.email,
role: currentUserData.role,
},
});
} catch (error) {
console.log("server error: ", error.message);
res.status(500).json({ success: false, error: "serverError!" });
......@@ -43,6 +41,13 @@ const updateCurrentUser = async (req: Request, res: Response) => {
//take what ever in req.body is, and pass it to update()
const input = req.body; //Data are saved in the DB in camelCase
//return 200 with empty response if no data was given
if (Object.keys(input).length === 0) {
return res
.status(200)
.json({ success: true, result: {}, message: "noInputFound" });
}
if (input.password !== undefined) {
input.password = await bcrypt.hash(input.password, 10);
}
......@@ -61,7 +66,16 @@ const updateCurrentUser = async (req: Request, res: Response) => {
const updatedEmployee = EmployeeDataAfterUpdate[1][0];
delete updatedEmployee.password;
return res.status(200).json({ success: true, result: updatedEmployee });
return res.status(200).json({
success: true,
result: {
id: updatedEmployee.id,
first_name: updatedEmployee.first_name,
last_name: updatedEmployee.last_name,
email: updatedEmployee.email,
role: updatedEmployee.role,
},
});
} catch (error) {
console.error("server error: ", error.message);
return res.status(500).json({ success: false, error: "serverError" });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment