I am encountering an issue where I am trying to retrieve a Coupon object from the Back-End, but instead of getting the desired Coupon type in the Front-End, I am receiving an 'Object' type.
It seems that the problem lies in the conversion process between the Back-End and the Front-End.
JSON representation of the Coupon from the Back-End:
https://i.sstatic.net/aeU6O.png
Coupon Entity in the Front-End:
export class Coupon {
amount: number
category: number
endDate: string
id: number
imageURL: string
price: number
startDate: string
title: string
constructor(
id: number,
// companyId: number,
title: string,
startDate: string,
endDate: string,
category: number,
amount: number,
price: number,
imageURL: string
) {
this.id = id
// this.companyId = companyId
this.title = title
this.startDate = startDate
this.endDate = endDate
this.category = category
this.amount = amount
this.price = price
this.imageURL = imageURL
}
}
GET request:
getCompanyCoupons() {
const params = new HttpParams()
.set("token", this.token);
return this.http.get < Coupon[] > ('http://localhost:8080/api/company/get_company_coupons', {
params
})
}
Usage of the request:
fetchAllCoupons() {
this.storagService.getCompanyCoupons()
.subscribe(coupons => {
this.coupons = coupons
console.log(this.coupons)
})
}