diff --git a/src/api/activityApi.ts b/src/api/activityApi.ts index 4e886c5..26ca66b 100644 --- a/src/api/activityApi.ts +++ b/src/api/activityApi.ts @@ -1,57 +1,73 @@ import { useAuthStore } from "@/stores/auth"; import { BASE_URL } from "./api"; - export const getActivities = async () => { - const auth = useAuthStore(); + const auth = useAuthStore(); - const response = await fetch(`${BASE_URL}/v1/activities`, { - headers: { - "Authorization": `Bearer ${auth.token}` - } - }); - const result = await response.json(); + const response = await fetch(`${BASE_URL}/v1/activities`, { + headers: { + Authorization: `Bearer ${auth.token}`, + }, + }); + const result = await response.json(); + + if (!response.ok) { + throw new Error(result.message); + } + + return result.data; +}; + +export const deleteActivities = async (payload: any) => { + const auth = useAuthStore(); - if (!response.ok) { - throw new Error(result.message) - } + const response = await fetch(`${BASE_URL}/v1/activities`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${auth.token}`, + }, + body: JSON.stringify(payload), + }); - return result.data; + if (!response.ok) { + const result = await response.json(); + throw new Error(result.message); + } }; export const deleteActivity = async (id: string) => { - const auth = useAuthStore(); - - const response = await fetch(`${BASE_URL}/v1/activities/${id}`, { - method: "DELETE", - headers: { - "Authorization": `Bearer ${auth.token}` - } - }); - - if (!response.ok) { - const result = await response.json(); - throw new Error(result.message) - } + const auth = useAuthStore(); + + const response = await fetch(`${BASE_URL}/v1/activities/${id}`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${auth.token}`, + }, + }); + + if (!response.ok) { + const result = await response.json(); + throw new Error(result.message); + } }; export const createActivity = async (payload: any) => { - const auth = useAuthStore(); + const auth = useAuthStore(); - const response = await fetch(`${BASE_URL}/v1/activities`, { - method: "POST", - headers: { - "Authorization": `Bearer ${auth.token}`, - "Content-Type": "application/json" - }, - body: JSON.stringify(payload) - }); + const response = await fetch(`${BASE_URL}/v1/activities`, { + method: "POST", + headers: { + Authorization: `Bearer ${auth.token}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }); - const result = await response.json(); + const result = await response.json(); - if (!response.ok) { - throw new Error(result.message) - } + if (!response.ok) { + throw new Error(result.message); + } - return result; -}; \ No newline at end of file + return result; +}; diff --git a/src/api/outputApi.ts b/src/api/outputApi.ts index b67c88f..3bf4685 100644 --- a/src/api/outputApi.ts +++ b/src/api/outputApi.ts @@ -18,6 +18,23 @@ export const getOutputs = async () => { return result.data; }; +export const deleteOutputs = async (payload: any) => { + const auth = useAuthStore(); + + const response = await fetch(`${BASE_URL}/v1/outputs`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${auth.token}`, + }, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + const result = await response.json(); + throw new Error(result.message); + } + }; + export const deleteOutput = async (id: string) => { const auth = useAuthStore(); diff --git a/src/api/partnerApi.ts b/src/api/partnerApi.ts index 0e8eb7b..435a0ce 100644 --- a/src/api/partnerApi.ts +++ b/src/api/partnerApi.ts @@ -2,56 +2,73 @@ import { BASE_URL } from "./api"; import { useAuthStore } from "@/stores/auth"; export const getPartners = async () => { - const auth = useAuthStore(); - - const response = await fetch(`${BASE_URL}/v1/partners`, { - headers: { - "Authorization": `Bearer ${auth.token}`, - "Content-Type": "application/json" - }, - }); - const result = await response.json(); + const auth = useAuthStore(); + + const response = await fetch(`${BASE_URL}/v1/partners`, { + headers: { + Authorization: `Bearer ${auth.token}`, + "Content-Type": "application/json", + }, + }); + const result = await response.json(); + + if (!response.ok) { + throw new Error(result.message); + } + + return result.data; +}; + +export const deletePartners = async (payload: any) => { + const auth = useAuthStore(); - if (!response.ok) { - throw new Error(result.message) - } + const response = await fetch(`${BASE_URL}/v1/partners`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${auth.token}`, + }, + body: JSON.stringify(payload), + }); - return result.data; + if (!response.ok) { + const result = await response.json(); + throw new Error(result.message); + } }; export const deletePartner = async (id: string) => { - const auth = useAuthStore(); - - const response = await fetch(`${BASE_URL}/v1/partners/${id}`, { - method: "DELETE", - headers: { - "Authorization": `Bearer ${auth.token}`, - } - }); - - if (!response.ok) { - const result = await response.json(); - throw new Error(result.message) - } + const auth = useAuthStore(); + + const response = await fetch(`${BASE_URL}/v1/partners/${id}`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${auth.token}`, + }, + }); + + if (!response.ok) { + const result = await response.json(); + throw new Error(result.message); + } }; export const createPartner = async (payload: any) => { - const auth = useAuthStore(); + const auth = useAuthStore(); - const response = await fetch(`${BASE_URL}/v1/partners`, { - method: "POST", - headers: { - "Authorization": `Bearer ${auth.token}`, - "Content-Type": "application/json" - }, - body: JSON.stringify(payload) - }); + const response = await fetch(`${BASE_URL}/v1/partners`, { + method: "POST", + headers: { + Authorization: `Bearer ${auth.token}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(payload), + }); - const result = await response.json(); + const result = await response.json(); - if (!response.ok) { - throw new Error(result.message) - } + if (!response.ok) { + throw new Error(result.message); + } - return result; -}; \ No newline at end of file + return result; +}; diff --git a/src/views/activity/ListActivityView.vue b/src/views/activity/ListActivityView.vue index a111311..b86dc69 100644 --- a/src/views/activity/ListActivityView.vue +++ b/src/views/activity/ListActivityView.vue @@ -49,7 +49,7 @@ import { computed, ref, watch, onMounted } from "vue"; import { useRoute, useRouter } from "vue-router"; import { Printer, Plus, Upload } from "@element-plus/icons-vue"; -import { getActivities, deleteActivity } from "@/api/activityApi"; +import { getActivities, deleteActivity, deleteActivities } from "@/api/activityApi"; import { useUserStore } from "@/stores/user"; import { BASE_URL } from "@/api/api"; import { useAuthStore } from "@/stores/auth"; @@ -110,7 +110,7 @@ const handleSelection = (value: any[]) => { }; const deleteSelection = () => { - console.log(activitiesSelected.value); + executeOperation(() => deleteActivities(activitiesSelected.value)); }; const clearSelection = () => { diff --git a/src/views/output/ListOutputView.vue b/src/views/output/ListOutputView.vue index 44778a0..8609a78 100644 --- a/src/views/output/ListOutputView.vue +++ b/src/views/output/ListOutputView.vue @@ -48,7 +48,7 @@ import { computed, ref, watch, onMounted } from "vue"; import { useRoute, useRouter } from "vue-router"; import { Plus, Upload } from "@element-plus/icons-vue"; -import { getOutputs, deleteOutput } from "@/api/outputApi"; +import { getOutputs, deleteOutput, deleteOutputs } from "@/api/outputApi"; import { BASE_URL } from "@/api/api"; import { ElNotification, ElTable } from "element-plus"; import { useAuthStore } from "@/stores/auth"; @@ -108,7 +108,7 @@ const handleSelection = (value: any[]) => { }; const deleteSelection = () => { - console.log(outputsSelected.value); + executeOperation(() => deleteOutputs(outputsSelected.value)); }; const clearSelection = () => { diff --git a/src/views/partner/ListPartnerView.vue b/src/views/partner/ListPartnerView.vue index f75c022..ed6e14f 100644 --- a/src/views/partner/ListPartnerView.vue +++ b/src/views/partner/ListPartnerView.vue @@ -50,7 +50,7 @@ import { computed, ref, watch, onMounted } from "vue"; import { useRoute, useRouter } from "vue-router"; import { Printer, Plus, Upload } from "@element-plus/icons-vue"; -import { getPartners, deletePartner } from "@/api/partnerApi"; +import { getPartners, deletePartner, deletePartners } from "@/api/partnerApi"; import { useUserStore } from "@/stores/user"; import { BASE_URL } from "@/api/api"; import { ElNotification, ElTable } from "element-plus"; @@ -111,7 +111,7 @@ const handleSelection = (value: any[]) => { }; const deleteSelection = () => { - console.log(partnersSelected.value); + executeOperation(() => deletePartners(partnersSelected.value)); }; const clearSelection = () => {