-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_100_drivers.ts
36 lines (34 loc) · 1.03 KB
/
log_100_drivers.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
import { command } from "cmd-ts";
import { Geotab } from "geotab-rx";
import { authenticate } from "geotab-rx/authenticate";
import { find } from "geotab-rx/repository/find";
import { switchMap, tap } from "rxjs/operators";
import { credentialArgs } from "../utils";
export const log100Drivers = command({
name: "log-100-drivers",
args: {
...credentialArgs,
},
description: "Show at most 100 drivers in database",
handler: (args) => {
const geotab = new Geotab();
// Begin authenticate
authenticate(geotab, {
username: args.username,
password: args.password,
})
.pipe(
// Notify user of failed login if error is thrown
tap({ error: (err) => console.error("Failed to login", err) }),
// Find 100 users that are drivers
switchMap((_) =>
find(geotab.users, {
limit: 100,
isDriver: true,
})
)
)
// Notify user of results
.subscribe((driver) => console.log(`Found driver '${driver.firstName}'!`));
},
});