Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
fix: change default version and add bearer headers to request API call
Browse files Browse the repository at this point in the history
  • Loading branch information
RadovanTomik committed Aug 30, 2024
1 parent de4cc91 commit e3c3ddc
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 110 deletions.
2 changes: 2 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
AccessCriteriaSection: typeof import('./src/components/negotiation-tabs/AccessCriteriaSection.vue')['default']
AddResourcesButton: typeof import('./src/components/AddResourcesButton.vue')['default']
AddResourcesModal: typeof import('./src/components/modals/AddResourcesModal.vue')['default']
Alert: typeof import('./src/components/Alert.vue')['default']
BAvatar: typeof import('bootstrap-vue-next')['BAvatar']
ConfirmationModal: typeof import('./src/components/modals/ConfirmationModal.vue')['default']
Expand Down
24 changes: 9 additions & 15 deletions src/components/modals/AddResourcesModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,10 @@
</div>
</template>
<script setup>
import { onBeforeMount, onMounted, ref, watch } from "vue"
import { onMounted, ref, watch } from "vue"
import { Tooltip } from "bootstrap"
import { useStore } from "vuex"
import { useRouter } from "vue-router"
import debounce from "@popperjs/core/lib/utils/debounce"
const store = useStore()
import { useNegotiationPageStore } from "@/store/negotiationPage"
const resources = ref([])
const selectedResources = ref([])
const selectAll = ref(false)
Expand All @@ -193,6 +191,7 @@ const props = defineProps({
required: true
}
})
const store = useNegotiationPageStore()
watch(() => props.shown, (first, second) => {
if (props.shown !== false) {
loadResources()
Expand All @@ -208,7 +207,7 @@ onMounted(() => {
})
})
async function loadResources (name = "") {
const response = await store.dispatch("retrieveAllResources", name)
const response = await store.retrieveAllResources(name)
resources.value = response?._embedded?.resources ?? []
pageLinks.value = response._links
pageNumber.value = response.page.number
Expand All @@ -217,7 +216,8 @@ async function loadResources (name = "") {
loading.value = false
}
async function loadStates () {
states.value = await store.dispatch("retrieveResourceAllStates")
const response = await store.retrieveResourceAllStates()
states.value = response._embedded.states
}
const emit = defineEmits(["confirm"])
Expand All @@ -230,11 +230,7 @@ async function addResources () {
}
}
const negotiationId = props.negotiationId
await store.dispatch("addResources", { data, negotiationId }).then((response) => {
if (response) {
console.log(response)
}
})
await store.addResources(data, negotiationId)
selectedResources.value = []
emit("confirm")
}
Expand Down Expand Up @@ -263,13 +259,11 @@ async function fetchPage (url) {
const onSearch = debounce(async () => {
if (searchQuery.value.length >= 3) {
loading.value = true
console.log(searchQuery.value)
await loadResources({ name: searchQuery.value })
await loadResources(searchQuery.value)
}
if (searchQuery.value.length === 0) {
loading.value = true
console.log(searchQuery.value)
await loadResources({ name: searchQuery.value })
await loadResources(searchQuery.value)
}
}, 1000) // Debounce delay in milliseconds
function getNumberOfSelectedResources () {
Expand Down
74 changes: 37 additions & 37 deletions src/store/apiCalls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ import { apiPaths, getBearerHeaders } from "../config/apiPaths"
import { useNotificationsStore } from "./notifications"

export const useApiCallsStore = defineStore("apiCalls", () => {
const notifications = useNotificationsStore()
const notifications = useNotificationsStore()

function createRequests(data) {
return axios.post(`${apiPaths.REQUESTS_PATH}`, data)
.then((response) => {
return response.data
})
.catch(() => {
notifications.setNotification("There was an error saving the attachment")
return null
})
}
function createRequests (data) {
return axios.post(`${apiPaths.REQUESTS_PATH}`, data)
.then((response) => {
return response.data
})
.catch(() => {
notifications.setNotification("There was an error saving the attachment")
return null
})
}

function markMessageAsRead(data) {
return axios.put(`${apiPaths.NEGOTIATION_PATH}/${data.negotiationId}/posts/${data.postId}`, data, { headers: getBearerHeaders() })
.then((response) => {
return response.data.id
})
.catch(() => {
return "Failed"
})
}
function markMessageAsRead (data) {
return axios.put(`${apiPaths.NEGOTIATION_PATH}/${data.negotiationId}/posts/${data.postId}`, data, { headers: getBearerHeaders() })
.then((response) => {
return response.data.id
})
.catch(() => {
return "Failed"
})
}

function getUnreadMessagesByRole(data) {
// the role shoud be complementary in relation of the one from the user
const complementaryRole = data.Rolename === ROLES.RESEARCHER ? ROLES.REPRESENTATIVE : ROLES.RESEARCHER
return axios.get(`${apiPaths.NEGOTIATION_PATH}/${data.negotiationId}/${complementaryRole}/posts`, { headers: getBearerHeaders() })
.then((response) => {
return response.data
})
.catch(() => {
return "Failed"
})
}
function getUnreadMessagesByRole (data) {
// the role shoud be complementary in relation of the one from the user
const complementaryRole = data.Rolename === ROLES.RESEARCHER ? ROLES.REPRESENTATIVE : ROLES.RESEARCHER
return axios.get(`${apiPaths.NEGOTIATION_PATH}/${data.negotiationId}/${complementaryRole}/posts`, { headers: getBearerHeaders() })
.then((response) => {
return response.data
})
.catch(() => {
return "Failed"
})
}

return {
createRequests,
markMessageAsRead,
getUnreadMessagesByRole
}
})
return {
createRequests,
markMessageAsRead,
getUnreadMessagesByRole
}
})
65 changes: 59 additions & 6 deletions src/store/negotiationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useNegotiationPageStore = defineStore("negotiationPage", () => {
notifications.setNotification("Error getting Possible Events For Resource data from server")
})
}

function updateResourceStatus (link) {
return axios.put(`${link}`, {}, { headers: getBearerHeaders() })
.then((response) => {
Expand Down Expand Up @@ -142,7 +142,7 @@ export const useNegotiationPageStore = defineStore("negotiationPage", () => {
function retrieveResourcesByNegotiationId (negotiationId) {
return axios.get(`${apiPaths.NEGOTIATION_PATH}/${negotiationId}/resources`, { headers: getBearerHeaders() })
.then((response) => {
return response.data._embedded.resources
return response.data
})
.catch(() => {
notifications.setNotification("Error getting request data from server")
Expand Down Expand Up @@ -185,20 +185,73 @@ export const useNegotiationPageStore = defineStore("negotiationPage", () => {
notifications.setNotification("Error getting Information Submission data from server")
})
}
async function retrieveAllResources (name) {
let url = `${apiPaths.BASE_API_PATH}/resources`
if (name) {
url = `${apiPaths.BASE_API_PATH}/resources?name=${name}`
}
return axios.get(`${url}`, { headers: getBearerHeaders() })
.then((response) => {
return response.data
})
.catch(() => {
notifications.setNotification("There was an error saving the attachment")
return null
})
}
async function fetchURL (url) {
return axios.get(`${url}`, { headers: getBearerHeaders() })
.then((response) => {
return response.data
})
.catch(() => {
notifications.setNotification("There was an error saving the attachment")
return null
})
}
async function addResources (data, negotiationId) {
try {
const response = await axios.patch(
`${apiPaths.BASE_API_PATH}/negotiations/${negotiationId}/resources`,
data,
{ headers: getBearerHeaders() }
)
notifications.setNotification("Resources were successfully updated")
return response.data
} catch (error) {
notifications.setNotification("There was an error saving the attachment")
return undefined
}
}
async function retrieveResourceAllStates () {
return axios.get(`${apiPaths.BASE_API_PATH}/resource-lifecycle/states`, { headers: getBearerHeaders() })
.then((response) => {
return response.data
})
.catch(() => {
notifications.setNotification("There was an error saving the attachment")
return null
})
}

return {
return {
updateNegotiationStatus,
retrievePossibleEvents,
retrievePossibleEventsForResource,
updateResourceStatus,
retrieveNegotiationById,
retrievePostsByNegotiationId,
retrieveAttachmentsByNegotiationId,
addMessageToNegotiation, addAttachmentToNegotiation,
addMessageToNegotiation,
addAttachmentToNegotiation,
retrieveUserRepresentedResources,
downloadAttachment,
retrieveResourcesByNegotiationId,
downloadAttachmentFromLink,
retrieveInformationSubmission
}
retrieveInformationSubmission,
fetchURL,
addResources,
retrieveAllResources,
retrieveResourceAllStates
}
})
Loading

0 comments on commit e3c3ddc

Please sign in to comment.