Skip to content

Commit

Permalink
feat: add usage summary (#77)
Browse files Browse the repository at this point in the history
* delete main

Co-authored-by: Tigua002 <Tigua002@users.noreply.github.com>

* revert commit: delete main

Co-authored-by: Tigua002 <Tigua002@users.noreply.github.com>

* implement list usage summary

Co-authored-by: Tigua002 <Tigua002@users.noreply.github.com>

* add method  listUsageSummary

* format

* put in proper spot

* convert to type import

* rename to match method

* update path name

* lint

---------

Co-authored-by: Tigua002 <Tigua002@users.noreply.github.com>
  • Loading branch information
Xillians and Tigua002 authored Feb 6, 2024
1 parent 926b197 commit 01ab149
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/abax-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ import {
type ListTripsResponse,
listTripsResponseSchema,
} from './calls/list-trips.js';
import {
type ListUsageSummaryInput,
type ListUsageSummaryResponse,
listUsageSummaryResponseSchema,
} from './calls/list-usage-summary.js';
import {
type ListVehiclesInput,
type ListVehiclesResponse,
Expand Down Expand Up @@ -112,6 +117,29 @@ export class AbaxClient {
return this.performRequest(apiKey => call({ input, apiKey }));
}

listUsageSummary(
input: ListUsageSummaryInput,
): Promise<ListUsageSummaryResponse> {
// URL: /v1/vehicles/{vehicle-id}/usage-summary?from=<datetime>&to=<datetime>
const call = this.authenticatedCall()
.args<{ input: ListUsageSummaryInput }>()
.method('get')
.path(
({ input: { vehicle_id } }) =>
`/v1/vehicles/${vehicle_id}/usage-summary`,
)
.query(({ input }) => {
const queryParams = new URLSearchParams();
queryParams.append('from', format(input.date_from, 'yyyy-MM-dd'));
queryParams.append('to', format(input.date_to, 'yyyy-MM-dd'));
return queryParams;
})
.parseJson(withZod(listUsageSummaryResponseSchema))
.build();

return this.performRequest(apiKey => call({ input, apiKey }));
}

async listTripExpenses(
input: ListTripExpensesInput,
): Promise<listTripExpensesResponse> {
Expand Down
27 changes: 27 additions & 0 deletions src/calls/list-usage-summary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { z } from 'zod';

export interface ListUsageSummaryInput {
// the id of the vehicle
vehicle_id?: string;

/** The period cannot be longer than 3 months */
date_from: Date;

/** The period cannot be longer than 3 months */
date_to: Date;
}

export const listUsageSummaryResponseSchema = z.object({
PrivateUsage: z.object({
DistanceDrivenInMeter: z.number(),
TotalTollStationsPassed: z.number(),
}),
CorporateUsageSummary: z.object({
DistanceDrivenInMeter: z.number(),
TotalTollStationsPassed: z.number(),
}),
});

export type ListUsageSummaryResponse = z.infer<
typeof listUsageSummaryResponseSchema
>;

0 comments on commit 01ab149

Please sign in to comment.