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) {
|
||||
id
|
||||
shopid
|
||||
bodyshop {
|
||||
timezone
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -3,6 +3,7 @@ const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
|
||||
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 { InstanceRegion } = require("../../utils/instanceMgr");
|
||||
const moment = require("moment/moment");
|
||||
const client = require("../../graphql-client/graphql-client").client;
|
||||
|
||||
const S3_BUCKET = process.env?.IMGPROXY_DESTINATION_BUCKET;
|
||||
@@ -76,9 +77,9 @@ const vsstaIntegrationRoute = async (req, res) => {
|
||||
const pdfBuffer = Buffer.from(base64String, "base64");
|
||||
|
||||
// 4. Generate key for S3
|
||||
const timestamp = Date.now();
|
||||
const fileName = `VSSTA_${scan_type}_Scan_${timestamp}.pdf`;
|
||||
const s3Key = `${job.shopid}/${job.id}/${fileName.replace(/[^A-Z0-9]+/gi, "_")}-${timestamp}.pdf`;
|
||||
const timestamp = moment(scan_time).tz(job.bodyshop.timezone).format("YYYYMMDD-HHmmss");
|
||||
const fileName = `${timestamp}_VSSTA_${scan_type}_Scan_${technician}_${year}_${make}_${model}`;
|
||||
const s3Key = `${job.shopid}/${job.id}/${fileName.replace(/[^A-Z0-9]+/gi, "_")}.pdf`;
|
||||
|
||||
// 5. Generate presigned URL for S3 upload
|
||||
const s3Client = new S3Client({ region: InstanceRegion() });
|
||||
@@ -114,7 +115,6 @@ const vsstaIntegrationRoute = async (req, res) => {
|
||||
docInput: [documentMeta]
|
||||
});
|
||||
|
||||
// Reversed flow: check for error case
|
||||
if (!documentInsert.insert_documents?.returning?.length) {
|
||||
logger.log(`vssta-integration-failed-to-create-document-record`, "error", "api", "vssta", {
|
||||
params: missingParams
|
||||
@@ -122,8 +122,6 @@ const vsstaIntegrationRoute = async (req, res) => {
|
||||
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({
|
||||
message: "VSSTA integration successful",
|
||||
documentId: documentInsert.insert_documents.returning[0].id
|
||||
|
||||
Reference in New Issue
Block a user