Skip to content

Commit c2b8708

Browse files
authored
feat: presence.getPresenceByUserCode (#49)
1 parent 8d60176 commit c2b8708

File tree

5 files changed

+59
-13
lines changed

5 files changed

+59
-13
lines changed

docs/presence.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Presence
22

33
- [getPresenceByUserID](#getpresencebyuserid)
4+
- [getPresenceByUserCode](#getpresencebyusercode)
45

56
## Overview
67

@@ -38,3 +39,21 @@ See the example response in the `Reference`.
3839
#### Reference
3940

4041
- https://developer.cybozu.io/hc/ja/articles/360026939891#step1
42+
43+
### getPresenceByUserCode
44+
45+
Get the presence information specified by the code of the user.
46+
47+
#### Parameters
48+
49+
| Name | Type | Required | Description |
50+
| ---- | :----: | :------: | --------------------- |
51+
| code | String | Yes | The code of the user. |
52+
53+
#### Returns
54+
55+
See the example response in the `Reference`.
56+
57+
#### Reference
58+
59+
- https://developer.cybozu.io/hc/ja/articles/360026939891#step2

src/client/PresenceClient.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HttpClient } from "../http";
2+
import { Presence } from "./types";
23
import { buildPath } from "../url";
34

45
export class PresenceClient {
@@ -10,21 +11,15 @@ export class PresenceClient {
1011

1112
public getPresenceByUserID(params: {
1213
id: string | number;
13-
}): Promise<{
14-
user: {
15-
id: string;
16-
name: string;
17-
code: string;
18-
};
19-
updatedAt: string;
20-
notes: string;
21-
status: {
22-
name: string;
23-
code: string;
24-
};
25-
}> {
14+
}): Promise<Presence> {
2615
const { id } = params;
2716
const path = buildPath({ endpointName: `presence/users/${id}` });
2817
return this.client.get(path, {});
2918
}
19+
20+
public getPresenceByUserCode(params: { code: string }): Promise<Presence> {
21+
const { code } = params;
22+
const path = buildPath({ endpointName: `presence/users/code/${code}` });
23+
return this.client.get(path, {});
24+
}
3025
}

src/client/__tests__/PresenceClient.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,22 @@ describe("PresenceClient", () => {
3535
expect(mockClient.getLogs()[0].params).toEqual({});
3636
});
3737
});
38+
39+
describe("getPresenceByUserCode", () => {
40+
const params = { code: "cybozu" };
41+
beforeEach(async () => {
42+
await presenceClient.getPresenceByUserCode(params);
43+
});
44+
it("should pass the path to the http client", () => {
45+
expect(mockClient.getLogs()[0].path).toBe(
46+
"/api/v1/presence/users/code/cybozu"
47+
);
48+
});
49+
it("should send a get request", () => {
50+
expect(mockClient.getLogs()[0].method).toBe("get");
51+
});
52+
it("should pass an empty object as a param to the http client", () => {
53+
expect(mockClient.getLogs()[0].params).toEqual({});
54+
});
55+
});
3856
});

src/client/types/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./schedule";
22
export * from "./workflow";
3+
export * from "./presence";

src/client/types/presence/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export type Presence = {
2+
user: {
3+
id: string;
4+
name: string;
5+
code: string;
6+
};
7+
updatedAt: string;
8+
notes: string;
9+
status: {
10+
name: string;
11+
code: string;
12+
};
13+
};

0 commit comments

Comments
 (0)