moved get details method
This commit is contained in:
parent
92742b3942
commit
6276bc6992
2 changed files with 25 additions and 18 deletions
|
|
@ -1,13 +1,23 @@
|
||||||
import { apiClient } from '@/services/apiClient.js'
|
import { apiClient } from '@/services/apiClient.js'
|
||||||
import router from '@/router/index.js'
|
|
||||||
|
|
||||||
export const useMerchApi = () => {
|
export const useMerchApi = () => {
|
||||||
const addMerch = async (payload) => {
|
const addMerch = async (payload) => {
|
||||||
const response = await apiClient.post('/merch/', payload.value)
|
const response = await apiClient.post('/merch/', payload.value)
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
router.push({ name: 'collection' })
|
return response
|
||||||
} else {
|
} else {
|
||||||
console.log("Add merch error: ", response)
|
console.log('Add merch error: ', response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getMerchDetails = async (uuid) => {
|
||||||
|
try {
|
||||||
|
const response = await apiClient.get(`/merch/${uuid}`)
|
||||||
|
if (response.status === 200) {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -22,6 +32,7 @@ export const useMerchApi = () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addMerch,
|
addMerch,
|
||||||
|
getMerchDetails,
|
||||||
deleteMerch,
|
deleteMerch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { apiClient } from '@/services/apiClient.js'
|
|
||||||
import { useMerchApi } from '@/api/merch.js'
|
import { useMerchApi } from '@/api/merch.js'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import router from '@/router/index.js'
|
import router from '@/router/index.js'
|
||||||
|
|
||||||
const { deleteMerch } = useMerchApi()
|
const { getMerchDetails, deleteMerch } = useMerchApi()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
merch_uuid: {
|
merch_uuid: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true,
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const merchDetails = ref(null)
|
const merchDetails = ref(null)
|
||||||
|
|
@ -19,11 +18,12 @@ const error = ref(null)
|
||||||
|
|
||||||
const fetchMerch = async () => {
|
const fetchMerch = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await apiClient.get(`/merch/${props.merch_uuid}`)
|
const response = await getMerchDetails(props.merch_uuid)
|
||||||
if (!response.status === 200) throw new Error('Network response was not ok')
|
|
||||||
merchDetails.value = response.data
|
merchDetails.value = response.data
|
||||||
|
|
||||||
if (!response.status === 400) router.push({ name: "collection" })
|
if (!response.status === 400) {
|
||||||
|
router.push({ name: 'collection' })
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error.value = err.message
|
error.value = err.message
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -44,14 +44,13 @@ const confirmDelete = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await deleteMerch(props.merch_uuid)
|
const response = await deleteMerch(props.merch_uuid)
|
||||||
if (!response.status === 200) throw new Error('Network response was not ok')
|
if (!response.status === 200) throw new Error('Network response was not ok')
|
||||||
if (!response.status === 400) router.push({ name: "collection" })
|
if (!response.status === 400) router.push({ name: 'collection' })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
showModal.value = false
|
showModal.value = false
|
||||||
router.push({ name: "collection" })
|
router.push({ name: 'collection' })
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -84,9 +83,6 @@ const confirmDelete = async () => {
|
||||||
<n-button @click="showModal = false">Cancel</n-button>
|
<n-button @click="showModal = false">Cancel</n-button>
|
||||||
</template>
|
</template>
|
||||||
</n-modal>
|
</n-modal>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue