update bug json

This commit is contained in:
2025-02-04 10:38:59 +01:00
parent 23dbfff014
commit a9cd2a6018
10 changed files with 126 additions and 105 deletions
+21 -21
View File
@@ -33,7 +33,7 @@ exports.getInfos = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
return res.status(500).send({error: error});
return res.status(500).json({error: error});
});
});
@@ -64,7 +64,7 @@ exports.getPictures = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
return res.status(500).send({error: error});
return res.status(500).json({error: error});
});
});
@@ -75,7 +75,7 @@ exports.getLotsBySale = asyncHandler(async (req, res, next) => {
const Sale = await saleDb.get(id);
if(!Sale){
console.error("Sale not found");
return res.status(404).send({error: "Sale not found"});
return res.status(404).json({error: "Sale not found"});
}
Lots = await lotDb.getBySaleId(Sale._id.toString(),Sale.platform);
@@ -91,7 +91,7 @@ exports.NextItem = asyncHandler(async (req, res, next) => {
Sale = await saleDb.getByIDPlatform(req.body.idSalePlatform, req.body.platform);
if(!Sale){
console.error("Sale not found");
return res.status(404).send({error: "Sale not found"});
return res.status(404).json({error: "Sale not found"});
}
let Lot = await lotDb.getByIDPlatform(req.body.idPlatform, req.body.platform);
@@ -127,10 +127,10 @@ exports.NextItem = asyncHandler(async (req, res, next) => {
await lotDb.put(Lot._id, Lot);
}
res.status(204).send({message: "Lot updated"});
res.status(204).json({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -157,13 +157,13 @@ exports.Bid = asyncHandler(async (req, res, next) => {
await lotDb.put(Lot._id, Lot);
}else{
console.error("Lot not found");
return res.status(404).send({error: "Lot not found"});
return res.status(404).json({error: "Lot not found"});
}
res.status(204).send({message: "Lot updated"});
res.status(204).json({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -189,13 +189,13 @@ exports.AuctionedItem = asyncHandler(async (req, res, next) => {
}else{
console.error("Lot not found");
return res.status(404).send({error: "Lot not found"});
return res.status(404).json({error: "Lot not found"});
}
res.status(204).send({message: "Lot updated"});
res.status(204).json({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -205,10 +205,10 @@ exports.get = asyncHandler(async (req, res, next) => {
try{
const id = req.params.id;
let result = await lotDb.get(id);
res.status(200).send(result);
res.status(200).json(result);
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -219,15 +219,15 @@ exports.post = asyncHandler(async (req, res, next) => {
// check if double
let Lot = await lotDb.getByIDPlatform(req.body.idPlatform, req.body.platform);
if(Sale){
return res.status(500).send({ error: "Lot already exists"});
return res.status(500).json({ error: "Lot already exists"});
}
let createLot = await lotDb.post(req.body);
res.status(204).send({message: "Lot created"});
res.status(204).json({message: "Lot created"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -241,10 +241,10 @@ exports.put = asyncHandler(async (req, res, next) => {
console.log(updatedDocument);
let result = await lotDb.put(id, updatedDocument);
console.log(result);
res.status(200).send(result);
res.status(200).json(result);
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@@ -256,10 +256,10 @@ exports.delete = asyncHandler(async (req, res, next) => {
// Remove the lot
await lotDb.remove(id);
res.status(200).send({"message": "Lots deleted"});
res.status(200).json({"message": "Lots deleted"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});