Skip to content

Commit 71943eb

Browse files
committed
feat(files_reminders): add reminder service
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent dec0111 commit 71943eb

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @copyright 2023 Christopher Ng <chrng8@gmail.com>
3+
*
4+
* @author Christopher Ng <chrng8@gmail.com>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import axios from '@nextcloud/axios'
24+
import { generateOcsUrl } from '@nextcloud/router'
25+
26+
interface Reminder {
27+
dueDate: Date
28+
}
29+
30+
export const getReminder = async (fileId: number): Promise<Reminder> => {
31+
const url = generateOcsUrl('/apps/files_reminders/api/v1/get/{fileId}', { fileId })
32+
const response = await axios.get(url)
33+
34+
return {
35+
dueDate: new Date(response.data.ocs.data.dueDate),
36+
}
37+
}
38+
39+
export const setReminder = async (fileId: number, dueDate: Date): Promise<[]> => {
40+
const url = generateOcsUrl('/apps/files_reminders/api/v1/set/{fileId}', { fileId })
41+
42+
const response = await axios.put(url, {
43+
dueDate: dueDate.toISOString(),
44+
})
45+
46+
return response.data.ocs.data
47+
}
48+
49+
export const clearReminder = async (fileId: number): Promise<[]> => {
50+
const url = generateOcsUrl('/apps/files_reminders/api/v1/remove/{fileId}', { fileId })
51+
const response = await axios.delete(url)
52+
53+
return response.data.ocs.data
54+
}

0 commit comments

Comments
 (0)