Skip to content

Commit

Permalink
Fixed format mishaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Niatsuna committed Aug 31, 2023
1 parent 1fe76b7 commit decda6d
Show file tree
Hide file tree
Showing 9 changed files with 672 additions and 686 deletions.
21 changes: 9 additions & 12 deletions Server/src/routes/poi.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,24 +194,21 @@ export class PoiRoute {
},
properties: null
}

const track = (await database.tracks.getById(userData.trackId)) ?? undefined

const enrichedPoint = (await POIService.enrichPOIPosition(geopos, track)) ?? undefined

// Note: geopos is from type GeoJSON.Feature and can't be parsed directly into Prisma.InputJsonValue
// Therefore we cast it into unknown first.
const updatedPOI: POI | null = await database.pois.update(
userData.id!,
{
name: userData.name,
description: userData.description,
position: (enrichedPoint as unknown as Prisma.InputJsonValue),
isTurningPoint: userData.isTurningPoint,
typeId: userData.typeId,
trackId: track!.uid
}
)
const updatedPOI: POI | null = await database.pois.update(userData.id!, {
name: userData.name,
description: userData.description,
position: enrichedPoint as unknown as Prisma.InputJsonValue,
isTurningPoint: userData.isTurningPoint,
typeId: userData.typeId,
trackId: track!.uid
})

if (!updatedPOI) {
logger.error(`Could not update poi with id ${userData.id}`)
Expand Down
8 changes: 6 additions & 2 deletions Server/src/routes/poitype.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class PoiTypeRoute {
private async createType(req: Request, res: Response): Promise<void> {
const { name, icon, description }: CreatePOIType = req.body

const poiType: POIType | null = await database.pois.saveType({name, icon, description})
const poiType: POIType | null = await database.pois.saveType({ name, icon, description })
if (!poiType) {
logger.error("Could not create poi type")
res.sendStatus(500)
Expand Down Expand Up @@ -116,7 +116,11 @@ export class PoiTypeRoute {
return
}

type = await database.pois.updateType(typeId, {name: userData.name, icon: userData.icon, description: userData.description})
type = await database.pois.updateType(typeId, {
name: userData.name,
icon: userData.icon,
description: userData.description
})
if (!type) {
logger.error(`Could not update poi type with id ${userData.id}`)
res.sendStatus(500)
Expand Down
18 changes: 13 additions & 5 deletions Server/src/routes/vehicle.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,19 @@ export class VehicleRoute {
trackers.push(maybeTracker)
}

const vehicle: Vehicle | null = await database.vehicles.save({ name: userData.name, typeId: type.uid, trackId: userData.track })
const vehicle: Vehicle | null = await database.vehicles.save({
name: userData.name,
typeId: type.uid,
trackId: userData.track
})
if (!vehicle) {
logger.error(`Could not create vehicle`)
res.sendStatus(500)
return
}

for (const tracker of trackers) {
const updatedTracker = await database.trackers.update(tracker.uid, {vehicleId: vehicle.uid})
const updatedTracker = await database.trackers.update(tracker.uid, { vehicleId: vehicle.uid })
if (!updatedTracker) {
logger.error(`Could not attach tracker to created vehicle.`)
res.sendStatus(500)
Expand Down Expand Up @@ -216,19 +220,23 @@ export class VehicleRoute {
trackers.push(tracker)
}

const vehicle = await database.vehicles.update(vehicleId, {typeId: type.uid, trackId: userData.track, name: userData.name})
const vehicle = await database.vehicles.update(vehicleId, {
typeId: type.uid,
trackId: userData.track,
name: userData.name
})
if (!vehicle) {
logger.error(`Could not update vehicle with id ${vehicleId}`)
res.sendStatus(500)
return
}

for (const tracker of prevTrackers) {
database.trackers.update(tracker.uid, {vehicleId: null})
database.trackers.update(tracker.uid, { vehicleId: null })
}

for (const tracker of trackers) {
const trackerToUpdate: Tracker | null = await database.trackers.update(tracker.uid, {vehicleId: vehicleId})
const trackerToUpdate: Tracker | null = await database.trackers.update(tracker.uid, { vehicleId: vehicleId })
if (!trackerToUpdate) {
logger.error(`Could not set tracker with tracker-id ${tracker}`)
res.sendStatus(500)
Expand Down
Loading

0 comments on commit decda6d

Please sign in to comment.