diff --git a/server/src/database/line.ts b/server/src/database/line.ts index 18e97cd7..6a1aa36e 100644 --- a/server/src/database/line.ts +++ b/server/src/database/line.ts @@ -90,9 +90,30 @@ export default class DatabaseLines { width : { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, defaultValue: 4, validate: { min: 1 } }, name : { type: DataTypes.TEXT, allowNull: true, get: function(this: LineModel) { return this.getDataValue("name") || "Untitled line"; } }, distance : { type: DataTypes.FLOAT(24, 2).UNSIGNED, allowNull: true }, - time : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true }, - ascent : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true }, - descent : { type: DataTypes.INTEGER.UNSIGNED, allowNull: true }, + time : { + type: DataTypes.INTEGER.UNSIGNED, + allowNull: true, + set: function(this: LineModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("time", v != null ? Math.round(v) : v); + } + }, + ascent : { + type: DataTypes.INTEGER.UNSIGNED, + allowNull: true, + set: function(this: LineModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("ascent", v != null ? Math.round(v) : v); + } + }, + descent : { + type: DataTypes.INTEGER.UNSIGNED, + allowNull: true, + set: function(this: LineModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("descent", v != null ? Math.round(v) : v); + } + }, top: getLatType(), bottom: getLatType(), left: getLonType(), @@ -120,7 +141,14 @@ export default class DatabaseLines { pos: getPosType(), zoom: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, validate: { min: 1, max: 20 } }, idx: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false }, - ele: { type: DataTypes.INTEGER, allowNull: true } + ele: { + type: DataTypes.INTEGER, + allowNull: true, + set: function(this: LinePointModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("ele", v != null ? Math.round(v) : v); + } + } }, { sequelize: this._db._conn, indexes: [ diff --git a/server/src/database/marker.ts b/server/src/database/marker.ts index 5f7a9a24..0fc3716f 100644 --- a/server/src/database/marker.ts +++ b/server/src/database/marker.ts @@ -43,7 +43,14 @@ export default class DatabaseMarkers { size : { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, defaultValue: 25, validate: { min: 15 } }, symbol : { type: DataTypes.TEXT, allowNull: true }, shape : { type: DataTypes.TEXT, allowNull: true }, - ele: { type: DataTypes.INTEGER, allowNull: true } + ele: { + type: DataTypes.INTEGER, + allowNull: true, + set: function(this: MarkerModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("ele", v != null ? Math.round(v) : v); + } + } }, { sequelize: this._db._conn, // pos index is created in migration diff --git a/server/src/database/route.ts b/server/src/database/route.ts index b1714e62..300c5f63 100644 --- a/server/src/database/route.ts +++ b/server/src/database/route.ts @@ -40,7 +40,14 @@ export default class DatabaseRoutes { pos: getPosType(), zoom: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false, validate: { min: 1, max: 20 } }, idx: { type: DataTypes.INTEGER.UNSIGNED, allowNull: false }, - ele: { type: DataTypes.INTEGER, allowNull: true } + ele: { + type: DataTypes.INTEGER, + allowNull: true, + set: function(this: RoutePointModel, v: number | null) { + // Round number to avoid integer column error in Postgres + this.setDataValue("ele", v != null ? Math.round(v) : v); + } + } }, { sequelize: this._db._conn, indexes: [