Skip to content

Commit

Permalink
Properly store absent line extra info as null
Browse files Browse the repository at this point in the history
  • Loading branch information
cdauth committed Mar 15, 2024
1 parent 5071e5b commit a4eea57
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/src/database/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface MetaProperties {
hasBboxes: "1";
untitledMigrationCompleted: "1";
fieldsNullMigrationCompleted: "1";
extraInfoNullMigrationCompleted: "1";
}

export default class DatabaseMeta {
Expand Down
20 changes: 20 additions & 0 deletions server/src/database/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class DatabaseMigrations {
await this._spatialMigration();
await this._untitledMigration();
await this._fieldsNullMigration();
await this._extraInfoNullMigration();
}


Expand Down Expand Up @@ -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");
}

}
4 changes: 2 additions & 2 deletions server/src/routing/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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++) {
Expand Down

0 comments on commit a4eea57

Please sign in to comment.