Files
cloudron-box/dashboard/src/models/NotificationsModel.js

37 lines
885 B
JavaScript

import { fetcher } from '@cloudron/pankow';
import { API_ORIGIN } from '../constants.js';
function create() {
const accessToken = localStorage.token;
return {
async list(acknowledged = false) {
let result;
try {
result = await fetcher.get(`${API_ORIGIN}/api/v1/notifications`, { acknowledged, access_token: accessToken, per_page: 100 });
} catch (e) {
return [e];
}
if (result.status !== 200) return [result];
return [null, result.body.notifications];
},
async update(id, acknowledged) {
let result;
try {
result = await fetcher.post(`${API_ORIGIN}/api/v1/notifications/${id}`, { acknowledged }, { access_token: accessToken });
} catch (e) {
return [e];
}
if (result.status !== 204) return [result];
return [null];
},
};
}
export default {
create,
};