Skip to content

Commit bbe7050

Browse files
committed
fix codeql
1 parent 9331d46 commit bbe7050

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

services/hexathons/src/routes/food-batch.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,18 @@ foodBatchRouter.route("/batch/:id").get(
6060
foodBatchRouter.route("/batch/:id").put(
6161
checkAbility("update", "FoodBatch"),
6262
asyncHandler(async (req, res) => {
63-
const updatedBatch = await FoodBatchModel.findByIdAndUpdate(req.params.id, req.body, {
64-
new: true,
65-
});
63+
const updatedBatch = await FoodBatchModel.findByIdAndUpdate(
64+
req.params.id,
65+
{
66+
hexathon: req.body.hexathon,
67+
name: req.body.name,
68+
start: req.body.start,
69+
end: req.body.end,
70+
},
71+
{
72+
new: true,
73+
}
74+
);
6675

6776
res.status(200).json(updatedBatch);
6877
})
@@ -79,7 +88,8 @@ foodBatchRouter.route("/batch/:id").delete(
7988
foodBatchRouter.route("/my-batch").get(
8089
checkAbility("read", "FoodBatch"),
8190
asyncHandler(async (req, res) => {
82-
const team = await TeamModel.findById(req.body.teamId);
91+
const teamId = new Types.ObjectId(req.body.teamId);
92+
const team = await TeamModel.findById(teamId);
8393

8494
if (!team) {
8595
throw new BadRequestError("Team not found.");
@@ -110,7 +120,8 @@ foodBatchRouter.route("/my-batch").get(
110120
foodBatchRouter.route("/join").post(
111121
checkAbility("update", "FoodBatch"),
112122
asyncHandler(async (req, res) => {
113-
const team = await TeamModel.findById(req.body.teamId);
123+
const teamId = new Types.ObjectId(req.body.teamId);
124+
const team = await TeamModel.findById(teamId);
114125

115126
if (!team) {
116127
throw new BadRequestError("Team not found.");
@@ -161,7 +172,7 @@ foodBatchRouter.route("/join").post(
161172
throw new ServerError("Failed to find suitable batch to join.");
162173
}
163174

164-
await TeamModel.findByIdAndUpdate(req.body.teamId, { batch: new Types.ObjectId(batchToJoin) });
175+
await TeamModel.findByIdAndUpdate(teamId, { batch: new Types.ObjectId(batchToJoin) });
165176

166177
batchCounts[batchToJoin] += 1;
167178

0 commit comments

Comments
 (0)