feature/IO-2282-VSSTA-Integration: - Finish Integration
This commit is contained in:
@@ -2860,6 +2860,9 @@ exports.GET_JOB_BY_RO_NUMBER_AND_SHOP_ID = `
|
|||||||
jobs(where: {ro_number: {_eq: $roNumber}, shopid: {_eq: $shopId}}, limit: 1) {
|
jobs(where: {ro_number: {_eq: $roNumber}, shopid: {_eq: $shopId}}, limit: 1) {
|
||||||
id
|
id
|
||||||
shopid
|
shopid
|
||||||
|
bodyshop {
|
||||||
|
timezone
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
|
|||||||
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
|
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
|
||||||
const { GET_JOB_BY_RO_NUMBER_AND_SHOP_ID, INSERT_NEW_DOCUMENT } = require("../../graphql-client/queries");
|
const { GET_JOB_BY_RO_NUMBER_AND_SHOP_ID, INSERT_NEW_DOCUMENT } = require("../../graphql-client/queries");
|
||||||
const { InstanceRegion } = require("../../utils/instanceMgr");
|
const { InstanceRegion } = require("../../utils/instanceMgr");
|
||||||
|
const moment = require("moment/moment");
|
||||||
const client = require("../../graphql-client/graphql-client").client;
|
const client = require("../../graphql-client/graphql-client").client;
|
||||||
|
|
||||||
const S3_BUCKET = process.env?.IMGPROXY_DESTINATION_BUCKET;
|
const S3_BUCKET = process.env?.IMGPROXY_DESTINATION_BUCKET;
|
||||||
@@ -76,9 +77,9 @@ const vsstaIntegrationRoute = async (req, res) => {
|
|||||||
const pdfBuffer = Buffer.from(base64String, "base64");
|
const pdfBuffer = Buffer.from(base64String, "base64");
|
||||||
|
|
||||||
// 4. Generate key for S3
|
// 4. Generate key for S3
|
||||||
const timestamp = Date.now();
|
const timestamp = moment(scan_time).tz(job.bodyshop.timezone).format("YYYYMMDD-HHmmss");
|
||||||
const fileName = `VSSTA_${scan_type}_Scan_${timestamp}.pdf`;
|
const fileName = `${timestamp}_VSSTA_${scan_type}_Scan_${technician}_${year}_${make}_${model}`;
|
||||||
const s3Key = `${job.shopid}/${job.id}/${fileName.replace(/[^A-Z0-9]+/gi, "_")}-${timestamp}.pdf`;
|
const s3Key = `${job.shopid}/${job.id}/${fileName.replace(/[^A-Z0-9]+/gi, "_")}.pdf`;
|
||||||
|
|
||||||
// 5. Generate presigned URL for S3 upload
|
// 5. Generate presigned URL for S3 upload
|
||||||
const s3Client = new S3Client({ region: InstanceRegion() });
|
const s3Client = new S3Client({ region: InstanceRegion() });
|
||||||
@@ -114,7 +115,6 @@ const vsstaIntegrationRoute = async (req, res) => {
|
|||||||
docInput: [documentMeta]
|
docInput: [documentMeta]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reversed flow: check for error case
|
|
||||||
if (!documentInsert.insert_documents?.returning?.length) {
|
if (!documentInsert.insert_documents?.returning?.length) {
|
||||||
logger.log(`vssta-integration-failed-to-create-document-record`, "error", "api", "vssta", {
|
logger.log(`vssta-integration-failed-to-create-document-record`, "error", "api", "vssta", {
|
||||||
params: missingParams
|
params: missingParams
|
||||||
@@ -122,8 +122,6 @@ const vsstaIntegrationRoute = async (req, res) => {
|
|||||||
return res.status(500).json({ error: "Failed to create document record" });
|
return res.status(500).json({ error: "Failed to create document record" });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success case
|
|
||||||
logger.logger.info(`Document created with ID ${documentInsert.insert_documents.returning[0].id}`);
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
message: "VSSTA integration successful",
|
message: "VSSTA integration successful",
|
||||||
documentId: documentInsert.insert_documents.returning[0].id
|
documentId: documentInsert.insert_documents.returning[0].id
|
||||||
|
|||||||
Reference in New Issue
Block a user