Skip to content

Commit 4c3f905

Browse files
authored
feat: presence.updatePresenceByUserCode (#52)
1 parent cbb882a commit 4c3f905

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

docs/presence.md

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [getPresenceByUserID](#getpresencebyuserid)
44
- [getPresenceByUserCode](#getpresencebyusercode)
55
- [updatePresenceByUserID](#updatepresencebyuserid)
6+
- [updatePresenceByUserCode](#updatepresencebyusercode)
67

78
## Overview
89

@@ -79,3 +80,24 @@ See the example response in the `Reference`.
7980
#### Reference
8081

8182
- https://developer.cybozu.io/hc/ja/articles/360026939911#step1
83+
84+
### updatePresenceByUserCode
85+
86+
Update the presence information specified by the user code.
87+
88+
#### Parameters
89+
90+
| Name | Type | Required | Description |
91+
| ----------- | :----: | :------: | -------------------------------------------- |
92+
| code | String | Yes | The user code. |
93+
| status | Object | | An object containing data of the status. |
94+
| status.code | String | | The status code of the presence information. |
95+
| notes | String | | The memo. |
96+
97+
#### Returns
98+
99+
See the example response in the `Reference`.
100+
101+
#### Reference
102+
103+
- https://developer.cybozu.io/hc/ja/articles/360026939911#step2

src/client/PresenceClient.ts

+13
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ export class PresenceClient {
3535
const data = (rest as unknown) as Record<string, unknown>;
3636
return this.client.patch(path, data);
3737
}
38+
39+
public updatePresenceByUserCode(params: {
40+
code: string;
41+
status?: {
42+
code?: string;
43+
};
44+
notes?: string;
45+
}): Promise<Presence> {
46+
const { code, ...rest } = params;
47+
const path = buildPath({ endpointName: `presence/users/code/${code}` });
48+
const data = (rest as unknown) as Record<string, unknown>;
49+
return this.client.patch(path, data);
50+
}
3851
}

src/client/__tests__/PresenceClient.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,33 @@ describe("PresenceClient", () => {
8080
});
8181
});
8282
});
83+
84+
describe("updatePresenceByUserCode", () => {
85+
const params = {
86+
code: "cybozu",
87+
status: {
88+
code: "attend",
89+
},
90+
notes: "This is presence note.",
91+
};
92+
beforeEach(async () => {
93+
await presenceClient.updatePresenceByUserCode(params);
94+
});
95+
it("should pass the path to the http client", () => {
96+
expect(mockClient.getLogs()[0].path).toBe(
97+
"/api/v1/presence/users/code/cybozu"
98+
);
99+
});
100+
it("should send a patch request", () => {
101+
expect(mockClient.getLogs()[0].method).toBe("patch");
102+
});
103+
it("should pass status and notes as a param to the http client", () => {
104+
expect(mockClient.getLogs()[0].params).toEqual({
105+
status: {
106+
code: "attend",
107+
},
108+
notes: "This is presence note.",
109+
});
110+
});
111+
});
83112
});

0 commit comments

Comments
 (0)