I encountered an issue with converting the output of my object post saving it in the database. I attempted to adhere to the guidelines laid out by and convert my responses to the Json standard.
The approach I took is not optimal. Here it is:
async findAll() {
const data = new DataResponse<Product>();
return await this.repository.find().then(value => {
data.data = value;
data.isError = false;
data.message = "";
data.statusCode = 1;
return data;
}).catch(e => {
const error: HttpException = e;
data.data = [];
data.isError = true;
data.message = error.message;
data.statusCode = error.getStatus();
return data;
});
}
In my json response, it appears as follows:
{
"data": {
"id": 1,
"description": "Oreo",
"price": "6.5",
"category": "Oreo",
"stock": 50,
"createDate": "2021-10-28T14:11:47.454Z",
"lastUpdateDate": "2021-10-28T14:11:47.454Z"
},
"message": "",
"statusCode": 1,
"isError": false
}