Refactor object retrieval and template data handling in DocumentPrinterClient
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
- 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.
This commit is contained in:
parent
c6a4ba900e
commit
47751367b8
@ -605,10 +605,24 @@ export class DocumentPrinterClient {
|
|||||||
type: "deploying",
|
type: "deploying",
|
||||||
progress: fetchTemplateProgress,
|
progress: fetchTemplateProgress,
|
||||||
});
|
});
|
||||||
const object = await this.socketClient.getObject({
|
const objectRefs =
|
||||||
objectType: documentJob.objectType,
|
Array.isArray(documentJob.objects) && documentJob.objects.length
|
||||||
_id: documentJob.object._id,
|
? 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, {
|
await this.updateJobState(documentJob._id, {
|
||||||
type: "deploying",
|
type: "deploying",
|
||||||
progress: fetchObjectProgress,
|
progress: fetchObjectProgress,
|
||||||
@ -626,7 +640,7 @@ export class DocumentPrinterClient {
|
|||||||
const result = await this.printerInterface.deploy(
|
const result = await this.printerInterface.deploy(
|
||||||
documentJob,
|
documentJob,
|
||||||
documentTemplate,
|
documentTemplate,
|
||||||
object,
|
templateData,
|
||||||
async ({ progress, message } = {}) => {
|
async ({ progress, message } = {}) => {
|
||||||
const mapped =
|
const mapped =
|
||||||
renderProgressStart +
|
renderProgressStart +
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user