-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.ts
71 lines (65 loc) · 2.03 KB
/
service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { GeolocationCircle } from './searchArea'
import { Trip } from '../domain/trip'
import { IRepository } from './repository'
/**
* A service interface for trips
*/
export interface IService<T> {
getTrips(
searchCircle: GeolocationCircle,
startDateTime?: Date,
endDateTime?: Date
): Promise<Array<T>>
getMinMaxTravelledDistances(
searchCircle: GeolocationCircle
): Promise<{ min: number; max: number }>
getVehicleModelGroupedTripCounts(
searchCircle: GeolocationCircle
): Promise<Record<number, number>>
}
/**
* A service implementation for the trips
*/
export class TripService {
#repo: IRepository<Trip>
constructor(repo: IRepository<Trip>) {
this.#repo = repo
}
/**
* Returns a list of trip promises.
* @param searchCircle - The geolocation circle (i.e. starting point + radius)
* @param startDateTime - Minimum trip start time
* @param endDateTime - Maximum trip end time
* @returns The array of trips as a promise
*/
public async getTrips(
searchCircle: GeolocationCircle,
startDateTime?: Date,
endDateTime?: Date
): Promise<Array<Trip>> {
return await this.#repo.findTrips(searchCircle, startDateTime, endDateTime)
}
/**
* Returns minimum and maximum travelled distances started from a user-defined region.
* @param searchCircle - The geolocation circle (i.e. starting point + radius)
* @returns The object containing distances as a promise
*/
public async getMinMaxTravelledDistances(
searchCircle: GeolocationCircle
): Promise<{
min: number
max: number
}> {
return await this.#repo.findMinMaxTravelledDistances(searchCircle)
}
/**
* Returns trip counts per vehicle model year.
* @param searchCircle - The geolocation circle (i.e. starting point + radius)
* @returns The model year - trip count pairs as a promise
*/
public async getVehicleModelGroupedTripCounts(
searchCircle: GeolocationCircle
): Promise<Record<number, number>> {
return await this.#repo.findVehicleModelGroupedTripCounts(searchCircle)
}
}