dbl-coins-invest
Version:
Sharade DBL package over other coins invest services
52 lines (46 loc) • 1.35 kB
JavaScript
import { sequelize } from "../sequelize-init";
import { Sequelize } from "sequelize";
export const Investment = sequelize.define(`investment`, {
coinId: Sequelize.STRING,
amount: Sequelize.FLOAT,
openPrice: Sequelize.FLOAT,
lastChecked: {
type: Sequelize.DATE,
allowNull: true,
set(val) {
let _d;
if (val instanceof Date) {
_d = val;
} else if (typeof val === 'number') {
_d = new Date(val < 15026591430 ? val * 1000 : val)
}
this.setDataValue('lastChecked', _d);
},
get() {
return this.getDataValue('lastChecked');
}
},
comment: Sequelize.STRING,
metaData: {
type: Sequelize.TEXT,
allowNull: false,
set(val) {
this.setDataValue('metaData', JSON.stringify(val));
},
get() {
try {
const metaData = this.getDataValue('metaData');
return !!metaData ? JSON.parse(metaData) : null;
} catch (err) {
console.log('Error in Investment Model, empty string will be returned');
return ''
}
}
}
}, {
getterMethods: {
openValue() {
return this.amount * this.openPrice
}
},
});