From 47751367b861d05d8408abffe17678b65d8cc08d Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 14 Sep 2026 23:32:52 +0100 Subject: [PATCH] Refactor object retrieval and template data handling in DocumentPrinterClient - Updated the object retrieval logic to support multiple document objects, enhancing flexibility in handling document jobs. - Introduced a new `templateData` structure to consolidate retrieved objects, improving the deployment process in the `deploy` method. - Enhanced error handling and data management during the document printing workflow, ensuring more robust operations. --- src/documentprinter/documentprinterclient.js | 24 ++++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/documentprinter/documentprinterclient.js b/src/documentprinter/documentprinterclient.js index 20e38af..57e437c 100644 --- a/src/documentprinter/documentprinterclient.js +++ b/src/documentprinter/documentprinterclient.js @@ -605,10 +605,24 @@ export class DocumentPrinterClient { type: "deploying", progress: fetchTemplateProgress, }); - const object = await this.socketClient.getObject({ - objectType: documentJob.objectType, - _id: documentJob.object._id, - }); + const objectRefs = + Array.isArray(documentJob.objects) && documentJob.objects.length + ? documentJob.objects + : documentJob.object != null + ? [documentJob.object] + : []; + const objects = []; + for (const ref of objectRefs) { + const object = await this.socketClient.getObject({ + objectType: documentJob.objectType, + _id: ref?._id ?? ref, + }); + objects.push(object); + } + const templateData = + objects.length && objects[0] && typeof objects[0] === "object" + ? { ...objects[0], objects } + : { objects }; await this.updateJobState(documentJob._id, { type: "deploying", progress: fetchObjectProgress, @@ -626,7 +640,7 @@ export class DocumentPrinterClient { const result = await this.printerInterface.deploy( documentJob, documentTemplate, - object, + templateData, async ({ progress, message } = {}) => { const mapped = renderProgressStart +