Files
cloudron-box/dashboard/src/models/ApplinksModel.js
T

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2025-01-03 15:06:41 +01:00
import { fetcher } from 'pankow';
2025-03-03 11:22:56 +01:00
import { API_ORIGIN } from '../constants.js';
2025-01-03 15:06:41 +01:00
2025-01-31 21:02:48 +01:00
function create() {
const accessToken = localStorage.token;
2025-01-03 15:06:41 +01:00
return {
name: 'ApplinksModel',
async list() {
let result;
2025-01-03 15:06:41 +01:00
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.get(`${API_ORIGIN}/api/v1/applinks`, { access_token: accessToken });
2025-01-03 15:06:41 +01:00
} catch (e) {
return [e];
2025-01-03 15:06:41 +01:00
}
if (result.status !== 200) return [result];
return [null, result.body.applinks];
2025-01-03 15:06:41 +01:00
},
async add(applink) {
const data = applink;
let result;
2025-01-03 15:06:41 +01:00
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/applinks`, data, { access_token: accessToken });
2025-01-03 15:06:41 +01:00
} catch (e) {
return [e];
2025-01-03 15:06:41 +01:00
}
if (result.status !== 201) return [result];
return [null];
2025-01-03 15:06:41 +01:00
},
async update(id, applink) {
const data = applink;
let result;
2025-01-03 15:06:41 +01:00
try {
2025-03-03 11:22:56 +01:00
result = await fetcher.post(`${API_ORIGIN}/api/v1/applinks/${id}`, data, { access_token: accessToken });
2025-01-03 15:06:41 +01:00
} catch (e) {
return [e];
2025-01-03 15:06:41 +01:00
}
if (result.status !== 200) return [result];
return [null];
2025-01-03 15:06:41 +01:00
},
async remove(id) {
let result;
2025-01-03 15:06:41 +01:00
try {
2025-03-14 18:48:13 +01:00
result = await fetcher.del(`${API_ORIGIN}/api/v1/applinks/${id}`, null, { access_token: accessToken });
2025-01-03 15:06:41 +01:00
} catch (e) {
return [e];
2025-01-03 15:06:41 +01:00
}
if (result.status !== 204) return [result];
return [null];
2025-01-03 15:06:41 +01:00
},
};
}
export default {
create,
};