kopia lustrzana https://github.com/FacilMap/facilmap
Properly store absent line extra info as null
rodzic
5071e5b417
commit
26753061a7
|
@ -127,7 +127,7 @@ export default class DatabaseLines {
|
|||
return extraInfo != null ? JSON.parse(extraInfo) : extraInfo;
|
||||
},
|
||||
set: function(this: LineModel, v: ExtraInfo) {
|
||||
this.setDataValue("extraInfo", JSON.stringify(v) as any);
|
||||
this.setDataValue("extraInfo", v != null ? JSON.stringify(v) as any : v);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
|
|
@ -14,6 +14,7 @@ export interface MetaProperties {
|
|||
hasBboxes: "1";
|
||||
untitledMigrationCompleted: "1";
|
||||
fieldsNullMigrationCompleted: "1";
|
||||
extraInfoNullMigrationCompleted: "1";
|
||||
}
|
||||
|
||||
export default class DatabaseMeta {
|
||||
|
|
|
@ -25,6 +25,7 @@ export default class DatabaseMigrations {
|
|||
await this._spatialMigration();
|
||||
await this._untitledMigration();
|
||||
await this._fieldsNullMigration();
|
||||
await this._extraInfoNullMigration();
|
||||
}
|
||||
|
||||
|
||||
|
@ -489,4 +490,23 @@ export default class DatabaseMigrations {
|
|||
await this._db.meta.setMeta("fieldsNullMigrationCompleted", "1");
|
||||
}
|
||||
|
||||
|
||||
/** Convert "null" to null for extraInfo */
|
||||
async _extraInfoNullMigration(): Promise<void> {
|
||||
if(await this._db.meta.getMeta("extraInfoNullMigrationCompleted") == "1")
|
||||
return;
|
||||
|
||||
await this._db.lines.LineModel.update({
|
||||
extraInfo: null
|
||||
}, {
|
||||
where: {
|
||||
extraInfo: {
|
||||
[Op.in]: ["null", "{}"]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await this._db.meta.setMeta("extraInfoNullMigrationCompleted", "1");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ export async function calculateRouteForLine(line: Pick<Line<CRU.CREATE_VALIDATED
|
|||
} else if(line.mode == "track" && line.trackPoints && line.trackPoints.length >= 2) {
|
||||
result.distance = calculateDistance(line.trackPoints);
|
||||
result.time = undefined;
|
||||
result.extraInfo = {};
|
||||
result.extraInfo = undefined;
|
||||
|
||||
// TODO: ascent/descent?
|
||||
|
||||
|
@ -80,7 +80,7 @@ export async function calculateRouteForLine(line: Pick<Line<CRU.CREATE_VALIDATED
|
|||
} else {
|
||||
result.distance = calculateDistance(line.routePoints);
|
||||
result.time = undefined;
|
||||
result.extraInfo = {};
|
||||
result.extraInfo = undefined;
|
||||
|
||||
result.trackPoints = [ ];
|
||||
for(let i=0; i<line.routePoints.length; i++) {
|
||||
|
|
Ładowanie…
Reference in New Issue