Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
feat: add delete manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgraham4401 committed Jul 1, 2021
1 parent 7d05b00 commit d0a70bc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
49 changes: 41 additions & 8 deletions src/eManAPI.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Use the Preprod API to get RCRAInfo/e-Manifest data
// Axios interceptors
// Needs to be completely refactored

import {} from 'dotenv/config'
import axios from 'axios'
Expand All @@ -18,26 +19,58 @@ const axiosAuth = axios.create({
method: 'get'
})

const axiosDelete = axios.create({
baseURL: `${process.env.BASE_URL}`,
method: 'delete'
})

const axiosPut= axios.create({
baseURL: `${process.env.BASE_URL}`,
method: 'put'
})

axiosGet.interceptors.request.use(async function (config) {
const response = await axiosAuth({
const res = await axiosAuth({
url: `${process.env.RCRAINFO_API_ID}/${process.env.RCRAINFO_API_KEY}`
})
config.headers.Authorization = 'Bearer ' + response.data.token
config.headers.Authorization = 'Bearer ' + res.data.token
return config
}, function (error) {
console.error(error.message)
console.error(error.response.data)
console.error(error.res.data)
})

axiosPost.interceptors.request.use(async function (config) {
const response = await axiosAuth({
const res = await axiosAuth({
url: `${process.env.RCRAINFO_API_ID}/${process.env.RCRAINFO_API_KEY}`
})
config.headers.Authorization = 'Bearer ' + res.data.token
return config
}, function (error) {
console.error(error.message)
console.error(error.res.data)
})

axiosDelete.interceptors.request.use(async function (config) {
const res = await axiosAuth({
url: `${process.env.RCRAINFO_API_ID}/${process.env.RCRAINFO_API_KEY}`
})
config.headers.Authorization = 'Bearer ' + res.data.token
return config
}, function (error) {
console.error(error.message)
console.error(error.res.data)
})

axiosPut.interceptors.request.use(async function (config) {
const res = await axiosAuth({
url: `${process.env.RCRAINFO_API_ID}/${process.env.RCRAINFO_API_KEY}`
})
config.headers.Authorization = 'Bearer ' + response.data.token
config.headers.Authorization = 'Bearer ' + res.data.token
return config
}, function (error) {
console.error(error.message)
console.error(error.response.data)
console.error(error.res.data)
})

export { axiosGet as get, axiosPost as post }
export { axiosGet as get, axiosPost as post, axiosDelete as delete, axiosPut as put }
24 changes: 23 additions & 1 deletion src/eManServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ async function eManGet (mtn, attachments = false) {
}
}

/**
* Delete manifests when allowed
*
* @param {string} mtn manifest tracking number
* */
async function eManDel (mtn) {
try {
mtn = mtn.toUpperCase()
const res = await eManAPI.delete({
url: `/emanifest/manifest/delete/${mtn}`,
headers: {
Accept: 'application/json'
}
})
return res.data
} catch (error) {
console.error('Problem getting manifest')
console.error(error.message)
console.error(error.response.data)
}
}

/**
* Save manifest with JSON and optional zip attachment
*
Expand Down Expand Up @@ -61,4 +83,4 @@ async function eManSave (mtnJson, path) {
}
}

export { eManGet as get, eManSave as save }
export { eManGet as get, eManSave as save, eManDel as delete }

0 comments on commit d0a70bc

Please sign in to comment.