Postgres/Sequelize — returns a string for decimal/numeric type
I am not very familiar with postgres
and sequelize
and just realized that it would return the decimal/numeric type as string in the code.
Here I found a work around to make it returns as string in the code base, and it worked well for me.
Make this change in the model.
Do this
@Column
get price(): number {
return parseFloat(`${this.getDataValue('price')}`);
}
set price(value: number) {
this.setDataValue('price', value);
}
instead of
@Column
price: number
Please leaves comments if anyone know other better ways to handle this.