-
Notifications
You must be signed in to change notification settings - Fork 6
/
staff.fn.ts
50 lines (46 loc) · 1.23 KB
/
staff.fn.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
import { get } from '@placeos/ts-client';
import { toQueryString } from 'libs/common/src/lib/api';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { StaffUser } from './user.class';
const STAFF_ENDPOINT = '/api/staff/v1/people';
/**
* Search staff members
* @param q Search string for filtering staff
*/
export function searchStaff(q: string): Observable<StaffUser[]> {
const query = toQueryString({
q,
fields: [
'id',
'name',
'email',
'username',
'organisation',
'department',
].join(','),
});
return get(`${STAFF_ENDPOINT}${q ? '?' + query : ''}`).pipe(
map((list) =>
list.map((item: Record<string, any>) => new StaffUser(item))
)
);
}
/**
* Get user details
* @param id User ID or email
*/
export function showStaff(id: string) {
return get(`${STAFF_ENDPOINT}/${encodeURIComponent(id)}`).pipe(
map((item) => new StaffUser(item))
);
}
/**
* Get user with their location details
* @param email User email
*/
export function locateStaff(email: string) {
return get(`${STAFF_ENDPOINT}/${email}`).pipe(
map((item) => new StaffUser(item))
);
}