Skip to content

Commit

Permalink
provide last known battery charge for each tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
n1kPLV committed Sep 4, 2023
1 parent 720fb88 commit 0a9294f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions Server/src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export type VehicleType = UpdateVehicleType & {
export type Tracker = {
id: string
vehicleId: number | null
battery?: number
data?: unknown
}

Expand Down
6 changes: 5 additions & 1 deletion Server/src/routes/tracker.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { authenticateJWT, jsonParser } from "."
import TrackerService from "../services/tracker.service"
import { UplinkTracker } from "../models/api.tracker"
import please_dont_crash from "../utils/please_dont_crash"
import { Tracker, Vehicle } from "@prisma/client"
import { Tracker, Vehicle, Log } from "@prisma/client"
import database from "../services/database.service"
import { Tracker as APITracker } from "../models/api"

Expand Down Expand Up @@ -69,9 +69,13 @@ export class TrackerRoute {
return
}

const [lastLog]: [lastLog?: Log, ...rest: never[]] = await database.logs.getAll(undefined, tracker.uid, 1)


const apiTracker: APITracker = {
id: tracker.uid,
vehicleId: tracker.vehicleId,
battery: lastLog?.battery ?? undefined,
data: tracker.data ?? undefined
}

Expand Down

0 comments on commit 0a9294f

Please sign in to comment.