Fix error when saving route as line

pull/174/head
Candid Dauth 2021-06-05 01:01:41 +02:00
rodzic d822adf014
commit abf90b9192
3 zmienionych plików z 10 dodań i 6 usunięć

Wyświetl plik

@ -43,6 +43,9 @@ export function getPosType(): ModelAttributeColumnOptions {
allowNull: false, allowNull: false,
get() { get() {
return undefined; return undefined;
},
set() {
throw new Error('Cannot set pos directly.');
} }
}; };
} }

Wyświetl plik

@ -260,7 +260,7 @@ export default class DatabaseLines {
const points = await this._db.helpers._bulkCreateInBatches<TrackPoint>(this.LinePointModel, create); const points = await this._db.helpers._bulkCreateInBatches<TrackPoint>(this.LinePointModel, create);
if(!_noEvent) if(!_noEvent)
this._db.emit("linePoints", padId, lineId, points); this._db.emit("linePoints", padId, lineId, points.map((point) => omit(point, ["lineId", "pos"]) as TrackPoint));
} }
async deleteLine(padId: PadId, lineId: ID): Promise<Line> { async deleteLine(padId: PadId, lineId: ID): Promise<Line> {
@ -290,7 +290,7 @@ export default class DatabaseLines {
return Object.entries(groupBy(linePoints, "lineId")).map(([key, val]) => ({ return Object.entries(groupBy(linePoints, "lineId")).map(([key, val]) => ({
id: Number(key), id: Number(key),
trackPoints: val.map((p) => omit(p.toJSON(), ["lineId"])) trackPoints: val.map((p) => omit(p.toJSON(), ["lineId", "pos"]))
})); }));
})).flatten(); })).flatten();
} }
@ -300,7 +300,7 @@ export default class DatabaseLines {
attributes: [ "pos", "lat", "lon", "ele", "zoom", "idx" ], attributes: [ "pos", "lat", "lon", "ele", "zoom", "idx" ],
order: [["idx", "ASC"]] order: [["idx", "ASC"]]
}); });
return points.map((point) => point.toJSON() as TrackPoint); return points.map((point) => omit(point.toJSON(), ["pos"]) as TrackPoint);
} }
} }

Wyświetl plik

@ -5,6 +5,7 @@ import { BboxWithZoom, ID, Latitude, Longitude, PadId, Point, Route, RouteMode,
import { BboxWithExcept, getPosType, getVirtualLatType, getVirtualLonType, makeBboxCondition } from "./helpers"; import { BboxWithExcept, getPosType, getVirtualLatType, getVirtualLonType, makeBboxCondition } from "./helpers";
import { WhereOptions } from "sequelize/types/lib/model"; import { WhereOptions } from "sequelize/types/lib/model";
import { calculateRouteForLine } from "../routing/routing"; import { calculateRouteForLine } from "../routing/routing";
import { omit } from "lodash";
const updateTimes: Record<string, number> = {}; const updateTimes: Record<string, number> = {};
@ -68,7 +69,7 @@ export default class DatabaseRoutes {
where: cond, where: cond,
attributes: [ "pos", "lat", "lon", "idx", "ele"], attributes: [ "pos", "lat", "lon", "idx", "ele"],
order: [[ "idx", "ASC" ]] order: [[ "idx", "ASC" ]]
})).map((point) => point.toJSON()); })).map((point) => omit(point.toJSON(), ["pos"]) as TrackPoint);
} }
async generateRouteId(): Promise<string> { async generateRouteId(): Promise<string> {
@ -199,7 +200,7 @@ export default class DatabaseRoutes {
attributes: [ "pos", "lat", "lon", "idx", "ele" ], attributes: [ "pos", "lat", "lon", "idx", "ele" ],
order: [[ "idx", "ASC" ]] order: [[ "idx", "ASC" ]]
}); });
return data.map((d) => d.toJSON()); return data.map((d) => omit(d.toJSON(), ["pos"]) as TrackPoint);
} }
async getAllRoutePoints(routeId: string): Promise<TrackPoint[]> { async getAllRoutePoints(routeId: string): Promise<TrackPoint[]> {
@ -207,7 +208,7 @@ export default class DatabaseRoutes {
where: {routeId}, where: {routeId},
attributes: [ "pos", "lat", "lon", "idx", "ele", "zoom"] attributes: [ "pos", "lat", "lon", "idx", "ele", "zoom"]
}); });
return data.map((d) => d.toJSON()); return data.map((d) => omit(d.toJSON(), ["pos"]) as TrackPoint);
} }
} }