66 lines
1.5 KiB
TypeScript
66 lines
1.5 KiB
TypeScript
import { ref } from 'vue';
|
|
import { defineStore } from 'pinia';
|
|
import { api } from 'src/boot/axios';
|
|
import { getToken } from 'src/services/keycloak';
|
|
import { Manual } from './types';
|
|
import { baseUrl } from '../utils';
|
|
|
|
const MANUAL_ENDPOINT = 'manual';
|
|
const TROUBLESHOOTING_ENDPOINT = 'troubleshooting';
|
|
|
|
export async function getManual() {
|
|
const res = await api.get<Manual[]>(`/${MANUAL_ENDPOINT}`);
|
|
if (res.status < 400) {
|
|
return res.data;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function getManualByPage(opt: {
|
|
category: string;
|
|
pageName: string;
|
|
}) {
|
|
const res = await fetch(
|
|
`${baseUrl}/${MANUAL_ENDPOINT}/${opt.category}/page/${opt.pageName}`,
|
|
);
|
|
if (res.status < 400) {
|
|
return res;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function getTroubleshooting() {
|
|
const res = await api.get<Manual[]>(`/${TROUBLESHOOTING_ENDPOINT}`);
|
|
if (res.status < 400) {
|
|
return res.data;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export async function getTroubleshootingByPage(opt: {
|
|
category: string;
|
|
pageName: string;
|
|
}) {
|
|
const res = await fetch(
|
|
`${baseUrl}/${TROUBLESHOOTING_ENDPOINT}/${opt.category}/page/${opt.pageName}`,
|
|
);
|
|
if (res.status < 400) {
|
|
return res;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export const useManualStore = defineStore('manual-store', () => {
|
|
const dataManual = ref<Manual[]>([]);
|
|
const dataTroubleshooting = ref<Manual[]>([]);
|
|
|
|
return {
|
|
getManual,
|
|
getManualByPage,
|
|
getTroubleshooting,
|
|
getTroubleshootingByPage,
|
|
|
|
dataManual,
|
|
dataTroubleshooting,
|
|
};
|
|
});
|