Bug 32939: Have a generic APIClient object

You always import the same, only once, and you can access other
resources from the same object.

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2023-02-15 09:35:19 +01:00 committed by Tomas Cohen Arazi
parent 866cc641d9
commit 10322566d4
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
6 changed files with 16 additions and 11 deletions

View file

@ -187,7 +187,7 @@ import AgreementLicenses from "./AgreementLicenses.vue"
import AgreementRelationships from "./AgreementRelationships.vue"
import Documents from "./Documents.vue"
import { setMessage, setError, setWarning } from "../../messages"
import { ERMAPIClient } from "../../fetch/erm-api-client.js"
import { APIClient } from "../../fetch/api-client.js"
import { storeToRefs } from "pinia"
export default {
@ -250,7 +250,7 @@ export default {
},
methods: {
async getAgreement(agreement_id) {
const client = new ERMAPIClient()
const client = APIClient.erm
try {
await client.agreements.get(agreement_id).then(data => {
this.agreement = data
@ -372,7 +372,7 @@ export default {
delete agreement.agreement_packages
const client = new ERMAPIClient()
const client = APIClient.erm
;(async () => {
try {
if (agreement_id) {

View file

@ -36,7 +36,7 @@
</template>
<script>
import { ERMAPIClient } from "../../fetch/erm-api-client.js"
import { APIClient } from "../../fetch/api-client.js"
import { setMessage, setError } from "../../messages"
export default {
@ -53,7 +53,7 @@ export default {
},
methods: {
async getAgreement(agreement_id) {
const client = new ERMAPIClient()
const client = APIClient.erm
try {
await client.agreements.get(agreement_id).then(data => {
this.agreement = data
@ -66,7 +66,7 @@ export default {
onSubmit(e) {
e.preventDefault()
const client = new ERMAPIClient()
const client = APIClient.erm
;(async () => {
try {
await client.agreements

View file

@ -37,7 +37,7 @@
import flatPickr from "vue-flatpickr-component"
import Toolbar from "./AgreementsToolbar.vue"
import { inject, createVNode, render } from "vue"
import { ERMAPIClient } from "../../fetch/erm-api-client.js"
import { APIClient } from "../../fetch/api-client.js"
import { storeToRefs } from "pinia"
import { useDataTable, build_url } from "../../composables/datatables"
@ -93,7 +93,7 @@ export default {
},
methods: {
async getAgreements() {
const client = new ERMAPIClient()
const client = APIClient.erm
const agreements = await client.agreements.getAll()
this.agreements = agreements
this.initialized = true

View file

@ -300,7 +300,7 @@
<script>
import { inject } from "vue"
import { ERMAPIClient } from "../../fetch/erm-api-client.js"
import { APIClient } from "../../fetch/api-client.js"
import { setError } from "../../messages"
export default {
@ -347,7 +347,7 @@ export default {
},
methods: {
async getAgreement(agreement_id) {
const client = new ERMAPIClient()
const client = APIClient.erm
try {
await client.agreements.get(agreement_id).then(data => {
this.agreement = data

View file

@ -0,0 +1,5 @@
import ERMAPIClient from "./erm-api-client";
export const APIClient = {
erm: new ERMAPIClient(),
};

View file

@ -43,4 +43,4 @@ export class ERMAPIClient extends HttpClient {
}
}
export default ERMAPIClient;
export default ERMAPIClient;