update bug json

This commit is contained in:
Cyril Rouillon 2025-02-04 10:38:59 +01:00
parent 23dbfff014
commit a9cd2a6018
10 changed files with 126 additions and 105 deletions

View File

@ -45,3 +45,7 @@ docker Compose up -d
Dashboard Agendash
https://jucundus-api.saucisse.ninja/dash/
# Prod Update
git stash
git pull origin main

View File

@ -6,10 +6,10 @@ exports.save = asyncHandler(async (req, res, next) => {
try{
let result = await save(req.body);
console.log(result);
res.status(204).send({message: "Favorite created"});
res.status(204).json({message: "Favorite created"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -19,9 +19,9 @@ exports.getAll = asyncHandler(async (req, res, next) => {
try{
let result = await getAll();
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});
}
});

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});
}
});

View File

@ -18,7 +18,7 @@ exports.getSaleInfos = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
return res.status(500).send({error: error});
return res.status(500).json({error: error});
});
});
@ -33,11 +33,11 @@ exports.prepareSale = asyncHandler(async (req, res, next) => {
})
.catch(error => {
console.error(error);
return res.status(500).send({error: error});
return res.status(500).json({error: error});
});
}catch(err){
console.error(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -48,15 +48,15 @@ exports.followSale = asyncHandler(async (req, res, next) => {
agent.followSale(id)
.then(data => {
res.status(200).send(data);
res.status(200).json(data);
})
.catch(error => {
console.error(error);
return res.status(500).send({error: error});
return res.status(500).json({error: error});
});
}catch(err){
console.error(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -67,10 +67,10 @@ exports.get = asyncHandler(async (req, res, next) => {
try{
const id = req.params.id;
let result = await saleDb.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});
}
});
@ -81,7 +81,7 @@ exports.post = asyncHandler(async (req, res, next) => {
// check if double
let Sale = await saleDb.getByIDPlatform(req.body.idPlatform, req.body.platform);
if(Sale){
return res.status(500).send({error: "Sale already exists"});
return res.status(500).json({error: "Sale already exists"});
}
let createData = await saleDb.post(req.body);
@ -105,10 +105,10 @@ exports.post = asyncHandler(async (req, res, next) => {
await jobFollow.save();
}else{ console.log("Sale is in the past, no Follow Job");}
res.status(204).send({"message": "Sale created"});
res.status(204).json({"message": "Sale created"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -122,10 +122,10 @@ exports.put = asyncHandler(async (req, res, next) => {
console.log(updatedDocument);
let result = await saleDb.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});
}
});
@ -147,10 +147,10 @@ exports.delete = asyncHandler(async (req, res, next) => {
await job.remove();
}
res.status(200).send({"message": "Sale and Lots deleted"});
res.status(200).json({"message": "Sale and Lots deleted"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -160,10 +160,10 @@ exports.delete = asyncHandler(async (req, res, next) => {
exports.getAll = asyncHandler(async (req, res, next) => {
try{
let result = await saleDb.getAll();
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});
}
});
@ -174,10 +174,10 @@ exports.getByUrl = asyncHandler(async (req, res, next) => {
let result = await saleDb.getByUrl(url);
//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});
}
});
@ -185,10 +185,10 @@ exports.postProcessing = asyncHandler(async (req, res, next) => {
try{
const id = req.params.id;
await saleDb.processStats(id);
res.status(200).send({"message": "Post Processing done"});
res.status(200).json({"message": "Post Processing done"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -200,7 +200,7 @@ exports.SaleStatXsl = asyncHandler(async (req, res, next) => {
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);

View File

@ -28,13 +28,13 @@ exports.get = asyncHandler(async (req, res, next) => {
const id = req.params.id;
let result = await userDb.get(id);
if (req.user.isAdmin){
res.status(200).send(ClearUserDataForAdmin(result));
res.status(200).json(ClearUserDataForAdmin(result));
}else{
res.status(200).send(ClearUserData(result));
res.status(200).json(ClearUserData(result));
}
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -46,24 +46,24 @@ exports.post = asyncHandler(async (req, res, next) => {
// check if double
let User = await userDb.getByEmail(req.body.email);
if(User){
return res.status(500).send({error: "User already exists"});
return res.status(500).json({error: "User already exists"});
}
// check password
if(!req.body.password){
return res.status(500).send({error: "Password not set"});
return res.status(500).json({error: "Password not set"});
}
if(req.body.password != req.body.confirmPassword){
return res.status(500).send({error: "Passwords do not match"});
return res.status(500).json({error: "Passwords do not match"});
}
if(req.body.password.length < 8){
return res.status(500).send({error: "Password too short"});
return res.status(500).json({error: "Password too short"});
}
if(req.body.isAdmin){
if(req.user){
if(!req.user.isAdmin){
return res.status(500).send({error: "You are not allowed to create an admin user"});
return res.status(500).json({error: "You are not allowed to create an admin user"});
}
}else{
req.body.isAdmin = false
@ -73,7 +73,7 @@ exports.post = asyncHandler(async (req, res, next) => {
if(req.body.isAgent){
if(req.user){
if(!req.user.isAgent){
return res.status(500).send({error: "You are not allowed to create an agent user"});
return res.status(500).json({error: "You are not allowed to create an agent user"});
}
}else{
req.body.isAgent = false
@ -92,10 +92,10 @@ exports.post = asyncHandler(async (req, res, next) => {
let createData = await userDb.post(user);
res.status(204).send({message: "User created"});
res.status(204).json({message: "User created"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -108,7 +108,7 @@ exports.put = asyncHandler(async (req, res, next) => {
const User = await userDb.get(id);
if(!User){
return res.status(500).send({error:"User not found"});
return res.status(500).json({error:"User not found"});
}
// check password
@ -116,10 +116,10 @@ exports.put = asyncHandler(async (req, res, next) => {
let salt = "";
if(req.body.password){
if(req.body.password != req.body.confirmPassword){
return res.status(500).send({error:"Passwords do not match"});
return res.status(500).json({error:"Passwords do not match"});
}
if(req.body.password.length < 8){
return res.status(500).send({error:"Password too short"});
return res.status(500).json({error:"Password too short"});
}
salt = crypto.randomBytes(16).toString('hex');
hashed_password = crypto.pbkdf2Sync(req.body.password, salt, 310000, 32, 'sha256').toString('hex');
@ -130,12 +130,12 @@ exports.put = asyncHandler(async (req, res, next) => {
if(req.body.isAdmin){
if(!req.user.isAdmin){
return res.status(500).send({error:"You are not allowed to create an admin user"});
return res.status(500).json({error:"You are not allowed to create an admin user"});
}
}
if(req.body.isAgent){
if(!req.user.isAdmin){
return res.status(500).send({error:"You are not allowed to create an agent user"});
return res.status(500).json({error:"You are not allowed to create an agent user"});
}
}
@ -150,10 +150,10 @@ exports.put = asyncHandler(async (req, res, next) => {
let result = await userDb.put(id, user);
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});
}
});
@ -166,10 +166,10 @@ exports.delete = asyncHandler(async (req, res, next) => {
// Remove the sale
await userDb.remove(id);
res.status(200).send({"message": "User deleted"});
res.status(200).json({"message": "User deleted"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -178,10 +178,10 @@ exports.delete = asyncHandler(async (req, res, next) => {
exports.current = asyncHandler(async (req, res, next) => {
try{
const user = ClearUserData(req.user);
res.status(200).send(user);
res.status(200).json(user);
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -189,10 +189,10 @@ exports.current = asyncHandler(async (req, res, next) => {
exports.agentConnected = asyncHandler(async (req, res, next) => {
try{
res.status(200).send({message: "Agent connected"});
res.status(200).json({message: "Agent connected"});
}catch(err){
console.log(err);
return res.status(500).send({error: err});
return res.status(500).json({error: err});
}
});
@ -201,10 +201,10 @@ exports.getAllUsers = asyncHandler(async (req, res, next) => {
const userDb = await UserDb.init();
let result = await userDb.getAll();
result = result.map(user => ClearUserDataForAdmin(user));
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});
}
});

View File

@ -15,6 +15,7 @@ const Agent = class
}
async request(url, method){
return new Promise((resolve, reject) => {
fetch(url,{
method: method,

View File

@ -1,4 +1,19 @@
.example-card {
margin-bottom: 8px;
}
.description-item {
height: auto !important;
min-height: 48px !important;
}
.description-container {
max-height: 150px;
overflow-y: auto;
/* padding: 8px 0; */
}
.description-text {
white-space: pre-wrap !important;
word-wrap: break-word;
line-height: 1.5;
}

View File

@ -1,27 +1,29 @@
<mat-card>
<mat-card-header>
<mat-card-title>Lot</mat-card-title>
<mat-card-subtitle>Lot informations</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<div fxLayout="row" fxLayoutGap="5px">
<div fxLayout="column" fxLayoutGap="2px">
<p><b>#</b> {{Lot.lotNumber}}</p>
</div>
<div fxLayout="column" fxLayoutGap="2px">
<p><b>Title</b> {{Lot.title}}</p>
</div>
</div>
<div fxLayout="row" fxLayoutGap="5px">
<div fxLayout="column" fxLayoutGap="2px">
<p><b>Estimate</b> [{{Lot.EstimateLow}} - {{Lot.EstimateHigh}}]</p>
</div>
</div>
<div fxLayout="row" fxLayoutGap="5px">
<mat-list>
<mat-list-item>
<span matListItemTitle>#</span>
<span matListItemLine>{{Lot.lotNumber}}</span>
</mat-list-item>
<mat-list-item>
<span matListItemTitle>Title</span>
<span matListItemLine>{{Lot.title}}</span>
</mat-list-item>
<mat-list-item>
<mat-list-item class="description-item">
<span matListItemTitle>Description</span>
<span matListItemLine [innerHTML]="getSafeDescription()"></span>
</mat-list-item>
<mat-list-item>
<span matListItemTitle>Estimate</span>
<span matListItemLine>Low: {{Lot.EstimateLow}} | High: {{Lot.EstimateHigh}} </span>
<div class="description-container">
<span matListItemLine class="description-text" [innerHTML]="getSafeDescription()"></span>
</div>
</mat-list-item>
</mat-list>
</div>

View File

@ -78,14 +78,17 @@ export class SaleDetailPageComponent implements OnInit, AfterViewInit {
this.route.paramMap.subscribe(params => {
this.id = params.get('id');
this.getSale();
this.getLotList();
this.refresh();
});
}
ngAfterViewInit(): void {
}
refresh(): void {
this.getSale();
this.getLotList();
}
getSale(){
this.apiSaleService.getSale(this.id).subscribe((sale: Sale) => {
@ -93,10 +96,6 @@ export class SaleDetailPageComponent implements OnInit, AfterViewInit {
});
}
refresh(): void {
this.getLotList();
}
getLotList(){
this.apiLotService.getLotsBySale(this.id).subscribe((lotList: Lot[]) => {

View File

@ -21,7 +21,7 @@ const config = {
audience: "yoursite",
},
agent :{
ApiAgentURL: 'jucundus-agent1.saucisse.ninja/api',
ApiAgentURL: 'https://jucundus-agent1.saucisse.ninja/api',
token: '861v48gr4YTHJTUre0reg40g8e6r8r64eggv1r4e6g4r81PKREVJ8g6reg46r8eg416reST6ger84g14er86e',
}
};