Skip to content

Commit f9e0cb9

Browse files
add task added
1 parent ba457c2 commit f9e0cb9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/modules/task.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
import cbws from './websocket';
22

33
/**
4-
* Fetches the list of tasks asynchronously.
5-
* @returns {Promise<any>} A promise that resolves with the list of tasks.
4+
* Manages task operations via WebSocket communication.
65
*/
76
const taskplaner = {
7+
/**
8+
* Adds a task using a WebSocket message.
9+
* @param {string} task - The task to be added.
10+
* @returns {Promise<any>} A promise that resolves with the response from the add task event.
11+
*/
12+
addTask: async (task: string): Promise<any> => {
13+
return new Promise((resolve, reject) => {
14+
cbws.getWebsocket.send(JSON.stringify({
15+
"type": "addTask",
16+
"task": task
17+
}));
18+
cbws.getWebsocket.on('message', (data: string) => {
19+
const response = JSON.parse(data);
20+
if (response.type === "addTaskResponse") {
21+
resolve(response); // Resolve the promise with the response data from adding the task
22+
}
23+
});
24+
});
25+
},
26+
/**
27+
* Retrieves all tasks using a WebSocket message.
28+
* @returns {Promise<any>} A promise that resolves with the response from the get tasks event.
29+
*/
830
getTasks: async (): Promise<any> => {
931
return new Promise((resolve, reject) => {
1032
cbws.getWebsocket.send(JSON.stringify({
11-
"type": "getTasks",
12-
33+
"type": "getTasks"
1334
}));
1435
cbws.getWebsocket.on('message', (data: string) => {
1536
const response = JSON.parse(data);
1637
if (response.type === "getTasksResponse") {
17-
resolve(response); // Resolve the Promise with the task data
38+
resolve(response); // Resolve the promise with the response data from retrieving tasks
1839
}
1940
});
2041
});

0 commit comments

Comments
 (0)