Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

111 clean services #113

Merged
merged 5 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Server/src/routes/poi.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class PoiRoute {
properties: null
}

const type: POIType | null = await POIService.getPOITypeById(userData.typeId)
const type: POIType | null = await database.pois.getTypeById(userData.typeId)
if (!type) {
logger.error(`Could not find poi type with id ${userData.typeId}`)
res.sendStatus(400)
Expand Down Expand Up @@ -179,7 +179,7 @@ export class PoiRoute {
return
}

const poiToUpdate: POI | null = await POIService.getPOIById(poiId)
const poiToUpdate: POI | null = await database.pois.getById(poiId)
if (!poiToUpdate) {
logger.error(`Could not find poi with id ${userData.id}`)
res.sendStatus(404)
Expand Down Expand Up @@ -233,13 +233,13 @@ export class PoiRoute {
}

// Look out for the POI
const poi: POI | null = await POIService.getPOIById(poiId)
const poi: POI | null = await database.pois.getById(poiId)
if (!poi) {
logger.error(`Could not find poi with id ${poiId}`)
res.sendStatus(500)
return
}
const success: boolean = await POIService.removePOI(poi)
const success: boolean = await database.pois.remove(poi.uid)
if (!success) {
logger.error(`Could not delete poi with id ${poiId}`)
res.sendStatus(500)
Expand Down
11 changes: 5 additions & 6 deletions Server/src/routes/track.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import TrackService from "../services/track.service"
import { POI, Track, Vehicle } from "@prisma/client"
import please_dont_crash from "../utils/please_dont_crash"
import { logger } from "../utils/logger"
import { UpdateTrack, BareTrack, FullTrack, PointOfInterest, Position, Vehicle as APIVehicle } from "../models/api"
import { BareTrack, FullTrack, PointOfInterest, Position, UpdateTrack, Vehicle as APIVehicle } from "../models/api"
import VehicleService from "../services/vehicle.service"
import { Feature, GeoJsonProperties, LineString, Point } from "geojson"
import POIService from "../services/poi.service"
import GeoJSONUtils from "../utils/geojsonUtils"
import database from "../services/database.service"
import TrackerService from "../services/tracker.service"

/**
* The router class for the routing of the track uploads from the website.
Expand Down Expand Up @@ -221,9 +220,9 @@ export class TrackRoute {
// If we know that, convert it in the API format.
const pos: Position | undefined = geo_pos
? {
lat: GeoJSONUtils.getLatitude(geo_pos),
lng: GeoJSONUtils.getLongitude(geo_pos)
}
lat: GeoJSONUtils.getLatitude(geo_pos),
lng: GeoJSONUtils.getLongitude(geo_pos)
}
: undefined
// Also acquire the percentage position. It might happen that a percentage position is known, while the position is not.
// This might not make much sense.
Expand All @@ -234,7 +233,7 @@ export class TrackRoute {
track: vehicle.trackId,
name: vehicle.name ? vehicle.name : "Empty Name",
type: vehicle.typeId,
trackerIds: (await TrackerService.getTrackerByVehicle(vehicle.uid)).map(y => y.uid),
trackerIds: (await database.trackers.getByVehicleId(vehicle.uid)).map(y => y.uid),
pos,
percentagePosition,
heading
Expand Down
5 changes: 2 additions & 3 deletions Server/src/routes/tracker.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 VehicleService from "../services/vehicle.service"
import database from "../services/database.service"
import { Tracker as APITracker } from "../models/api"

Expand Down Expand Up @@ -152,7 +151,7 @@ export class TrackerRoute {
}
const trackerId = trackerData.end_device_ids.device_id
// load the tracker from the database
const tracker: Tracker | null = await TrackerService.getTrackerById(trackerId)
const tracker: Tracker | null = await database.trackers.getById(trackerId)
if (!tracker) {
logger.silly(`Tried to append log on unknown tracker with id ${trackerId}`)
res.sendStatus(401)
Expand All @@ -165,7 +164,7 @@ export class TrackerRoute {
}
// and get the vehicle the tracker is attached to. If it has no associated vehicle, do nothing.
const associatedVehicle: Vehicle | null = tracker.vehicleId
? await VehicleService.getVehicleById(tracker.vehicleId)
? await database.vehicles.getById(tracker.vehicleId)
: null
if (!associatedVehicle) {
logger.silly(`Got position from tracker ${trackerId} with no associated vehicle.`)
Expand Down
6 changes: 3 additions & 3 deletions Server/src/routes/vehicle.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export class VehicleRoute {

/**
* Get a list of vehicles with all the required properties for CRUD operations
* @param req A request containing a track id in the parameters
* @param _req A request containing a track id in the parameters
* @param res A list of `VehicleListItemWebsite`.
* @returns Nothing
*/
private async getAllVehicles(req: Request, res: Response): Promise<void> {
private async getAllVehicles(_req: Request, res: Response): Promise<void> {
const vehicles = await database.vehicles.getAll()
const apiVehicles: APIVehicle[] = await Promise.all(
vehicles.map(async vehicle => {
Expand Down Expand Up @@ -320,7 +320,7 @@ export class VehicleRoute {
return
}

const userVehicle: Vehicle | null = await VehicleService.getVehicleById(userData.vehicleId)
const userVehicle: Vehicle | null = await database.vehicles.getById(userData.vehicleId)
if (!userVehicle) {
logger.error(`Could not find vehicle with id ${userData.vehicleId}`)
res.sendStatus(404)
Expand Down
10 changes: 9 additions & 1 deletion Server/src/services/crypto.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as argon from "argon2"

export default class CryptoService {

/**
* Wrapper method for verifying a plain password against hashed password using argon2.
*
* @param hashedPassword The argon2-hashed password from the database to verify against.
* @param plainPassword The plain password the user entered.
*/
public static async verify(hashedPassword: string, plainPassword: string): Promise<boolean> {
let isCorrectPassword: boolean
try {
Expand All @@ -10,10 +17,11 @@ export default class CryptoService {
}
return isCorrectPassword
}

/**
* Produces a hash using the argon hashing.
* @param input The password, that needs to be hashed
* @returns Undefined, if the hashing is unsuccessful, a hash of the password otherwise.
* @returns undefined, if the hashing is unsuccessful, a hash of the password otherwise.
*/
public static async produceHash(input: string): Promise<string | undefined> {
try {
Expand Down
Loading
Loading