66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
const path = require("path");
|
|
const _ = require("lodash");
|
|
const logger = require("../utils/logger");
|
|
const xml2js = require("xml2js");
|
|
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
|
|
exports.mixdataUpload = async (req, res) => {
|
|
const { bodyshopid } = req.body;
|
|
logger.log("media-bulk-download", "DEBUG", req.user.email, ids, null);
|
|
const BearerToken = req.headers.authorization;
|
|
logger.log("job-mixdata-upload", "DEBUG", req.user.email, null, null);
|
|
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
|
headers: {
|
|
Authorization: BearerToken,
|
|
},
|
|
});
|
|
|
|
try {
|
|
req.files.forEach(async (element) => {
|
|
const b = Buffer.from(element.buffer);
|
|
console.log(b.toString());
|
|
|
|
const inboundRequest = await xml2js.parseStringPromise(b.toString(), {
|
|
explicitArray: false,
|
|
});
|
|
|
|
const ScaleType = DetermineScaleType(inboundRequest);
|
|
const ROList = GetListOfRos(inboundRequest, ScaleType);
|
|
|
|
//Query the list of ROs based on the RO number.
|
|
|
|
console.log(ROList);
|
|
});
|
|
res.sendStatus(200);
|
|
} catch (error) {
|
|
res.status(500).JSON(error);
|
|
}
|
|
};
|
|
|
|
function DetermineScaleType(inboundRequest) {
|
|
const ret = { type: "", verson: 0 };
|
|
|
|
//PPG Mix Data
|
|
if (inboundRequest.PPG && inboundRequest.PPG.Header.Protocol.Name === "PPG") {
|
|
return {
|
|
type: inboundRequest.PPG.Header.Protocol.Name,
|
|
company: "PPG",
|
|
version: inboundRequest.PPG.Header.Protocol.Version,
|
|
};
|
|
}
|
|
}
|
|
|
|
function GetListOfRos(inboundRequest, ScaleType) {
|
|
if (ScaleType.company === "PPG" && ScaleType.version === "1.3.0") {
|
|
return inboundRequest.PPG.DataExportInterface.ROData.RepairOrders.RO.map(
|
|
(r) => r.RONumber
|
|
);
|
|
}
|
|
}
|