Skip to content

Commit

Permalink
feat: delete selected activities/outputs/partners
Browse files Browse the repository at this point in the history
  • Loading branch information
newarifrh committed Jun 27, 2024
1 parent bcb5502 commit 4b26e3c
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 87 deletions.
96 changes: 56 additions & 40 deletions src/api/activityApi.ts
Original file line number Diff line number Diff line change
@@ -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;
};
return result;
};
17 changes: 17 additions & 0 deletions src/api/outputApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
99 changes: 58 additions & 41 deletions src/api/partnerApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
return result;
};
4 changes: 2 additions & 2 deletions src/views/activity/ListActivityView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -110,7 +110,7 @@ const handleSelection = (value: any[]) => {
};
const deleteSelection = () => {
console.log(activitiesSelected.value);
executeOperation(() => deleteActivities(activitiesSelected.value));
};
const clearSelection = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/views/output/ListOutputView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -108,7 +108,7 @@ const handleSelection = (value: any[]) => {
};
const deleteSelection = () => {
console.log(outputsSelected.value);
executeOperation(() => deleteOutputs(outputsSelected.value));
};
const clearSelection = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/views/partner/ListPartnerView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -111,7 +111,7 @@ const handleSelection = (value: any[]) => {
};
const deleteSelection = () => {
console.log(partnersSelected.value);
executeOperation(() => deletePartners(partnersSelected.value));
};
const clearSelection = () => {
Expand Down

0 comments on commit 4b26e3c

Please sign in to comment.