diff --git a/src/api/PrintMyBarcode.js b/src/api/PrintMyBarcode.js index e3a88439..3a10ab95 100644 --- a/src/api/PrintMyBarcode.js +++ b/src/api/PrintMyBarcode.js @@ -9,25 +9,11 @@ const createLabels = (barcodes) => { .replace(/ /g, '-') .toUpperCase() - // { - // "print_job": { - // "printer_name": "stub", - // "label_template_name": "traction_tube_label_template", - // "labels": [{ - // "barcode": "TRAC-2-4-N1", - // "first_line": "15-Sep-22", - // "second_line": "TRAC-2-4-N1", - // "third_line": "", - // "label_name": "main_label" - // }], - // "copies": "1" - // } - // } return barcodes.map((barcode) => ({ + label_name: 'main_label', top_left: dateString, bottom_left: barcode, barcode: barcode, - label_name: 'main_label', })) } @@ -60,11 +46,10 @@ const createPrintJob = async ({ printer, barcodes }) => { const labels = createLabels(barcodes) const data = { - print_job: { - printer_name: printer, - label_template_name: import.meta.env.VITE_LABEL_TEMPLATE_NAME, - labels, - }, + printer_name: printer, + label_template_name: import.meta.env.VITE_LABEL_TEMPLATE_NAME, + labels, + copies: '1', } return fetch( `${import.meta.env.VITE_PRINT_MY_BARCODE_BASE_URL}/v2/print_jobs`, diff --git a/src/components/PrintJob.vue b/src/components/PrintJob.vue index e66f5fbb..8acfbc0d 100644 --- a/src/components/PrintJob.vue +++ b/src/components/PrintJob.vue @@ -117,19 +117,23 @@ export default { createPrintJob({ printer: this.printer, barcodes: this.formattedBarcodes(), - }).then((response) => { - if (!response.ok) { - response.json().then((data) => { - const message = data.errors - .map((error) => `${error.source.pointer} ${error.detail}`) - .join(', ') - this.showAlert('Barcode printing failed: ' + message, 'danger') - }) - } else { - this.showAlert('Barcode printing succeeded', 'success') - } - return response }) + .then((response) => { + if (!response.ok) { + response.json().then((data) => { + const message = data.errors + .map((error) => `${error.source.pointer} ${error.detail}`) + .join(', ') + this.showAlert('Barcode printing failed: ' + message, 'danger') + }) + } else { + this.showAlert('Barcode printing succeeded', 'success') + } + return response + }) + .catch((error) => { + this.showAlert('Barcode printing failed: ' + error.message, 'danger') + }) }, valid() { this.barcodeError = !this.barcodes diff --git a/tests/unit/api/PrintMyBarcode.spec.js b/tests/unit/api/PrintMyBarcode.spec.js index 80c37e7e..170fa465 100644 --- a/tests/unit/api/PrintMyBarcode.spec.js +++ b/tests/unit/api/PrintMyBarcode.spec.js @@ -90,11 +90,10 @@ describe('PrintMyBarcode.js', () => { Accept: 'application/vnd.api+json', }, body: JSON.stringify({ - print_job: { - printer_name: printer, - label_template_name: 'sqsc_96plate_label_template_code128', - labels: createLabels(barcodes), - }, + printer_name: printer, + label_template_name: 'sqsc_96plate_label_template_code128', + labels: createLabels(barcodes), + copies: '1', }), }, )