Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 0 additions & 152 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"license": "MIT",
"dependencies": {
"@cfaester/enzyme-adapter-react-18": "^0.8.0",
"axios": "^0.21.0",
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"cors": "^2.8.5",
Expand Down
74 changes: 42 additions & 32 deletions src/APIFunctions/2DPrinting.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from 'axios';
import {
PrintApiResponse,
ApiResponse
Expand All @@ -22,14 +21,17 @@ export const range = (start, end) => {
export async function healthCheck() {
let status = new ApiResponse();
const url = new URL('/api/Printer/healthCheck', BASE_API_URL);
await axios.get(url.href)
.then(res => {
status.responseData = res.data;
})
.catch(err => {
status.responseData = err;
try {
const res = await fetch(url.href);
if (res.ok) {
status.responseData = await res.json();
} else {
status.error = true;
});
}
} catch(err) {
status.responseData = err;
status.error = true;
}
return status;
}

Expand Down Expand Up @@ -78,18 +80,22 @@ export function parseRange(pages, maxPages) {
export async function printPage(data, token) {
let status = new ApiResponse();
const url = new URL('/api/Printer/sendPrintRequest', BASE_API_URL);
await axios.post(url.href, data, {
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${token}`
}
})
.then(response => {
status.responseData = response.data.message;
})
.catch(() => {
status.error = true;
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
},
body: data
});
if (res.ok) {
const response = await res.json();
status.responseData = response.message;
}
} catch(err) {
status.responseData = err;
status.error = true;
}
return status;
}

Expand All @@ -105,20 +111,24 @@ export async function printPage(data, token) {
export async function getPagesPrinted(email, token) {
let status = new PrintApiResponse();
const url = new URL('/api/user/getPagesPrintedCount', BASE_API_URL);
await axios
.post(url.href, {
email
}, {
try {
const res = await fetch(url.href, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
}
}
)
.then(res => {
status.pagesUsed = res.data;
})
.catch(() => {
status.error = true;
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ email })
});
if (res.ok) {
const response = await res.json();
status.pagesUsed = response.pagesUsed;
} else {
status.error = true;
}
} catch(err) {
status.responseData = err;
status.error = true;
}
return status;
}
Loading