jws-frontend/src/stores/manual/index.ts
Methapon2001 21699b14c5
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 7s
feat: troubleshooting page
2025-04-25 15:15:37 +07:00

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,
};
});