This commit is contained in:
2024-09-27 17:20:37 +02:00
parent ee932a2339
commit f43e802501
59 changed files with 810 additions and 236 deletions
+23 -16
View File
@@ -20,6 +20,8 @@ exports.getInfos = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
res.json({error: error});
});
});
@@ -35,6 +37,7 @@ exports.getPictures = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
res.json({error: error});
});
});
@@ -44,7 +47,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("Sale not found");
return res.status(404).send({error: "Sale not found"});
}
Lots = await lotDb.getBySaleId(Sale._id.toString(),Sale.platform);
@@ -60,7 +63,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("Sale not found");
return res.status(404).send({error: "Sale not found"});
}
let Lot = await lotDb.getByIDPlatform(req.body.idPlatform, req.body.platform);
@@ -96,10 +99,10 @@ exports.NextItem = asyncHandler(async (req, res, next) => {
await lotDb.put(Lot._id, Lot);
}
res.status(204).send();
res.status(204).send({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -126,13 +129,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("Lot not found");
return res.status(404).send({error: "Lot not found"});
}
res.status(204).send();
res.status(204).send({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -152,15 +155,19 @@ exports.AuctionedItem = asyncHandler(async (req, res, next) => {
}
await lotDb.put(Lot._id, Lot);
//update stats
await saleDb.processStats(Lot.sale_id);
}else{
console.error("Lot not found");
return res.status(404).send("Lot not found");
return res.status(404).send({error: "Lot not found"});
}
res.status(204).send();
res.status(204).send({message: "Lot updated"});
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -173,7 +180,7 @@ exports.get = asyncHandler(async (req, res, next) => {
res.status(200).send(result);
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -184,15 +191,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("Lot already exists");
return res.status(500).send({ error: "Lot already exists"});
}
let createLot = await lotDb.post(req.body);
res.status(204).send();
res.status(204).send({message: "Lot created"});
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -209,7 +216,7 @@ exports.put = asyncHandler(async (req, res, next) => {
res.status(200).send(result);
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});
@@ -224,7 +231,7 @@ exports.delete = asyncHandler(async (req, res, next) => {
res.status(200).send({"message": "Lots deleted"});
}catch(err){
console.log(err);
return res.status(500).send(err);
return res.status(500).send({error: err});
}
});