Merge remote-tracking branch 'origin/master-AIO' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration
This commit is contained in:
37
server/data/analytics/documents.js
Normal file
37
server/data/analytics/documents.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const logger = require("../../utils/logger");
|
||||
const { client } = require('../../graphql-client/graphql-client');
|
||||
const { INSERT_MEDIA_ANALYTICS, GET_BODYSHOP_BY_ID } = require("../../graphql-client/queries");
|
||||
|
||||
const documentAnalytics = async (req, res) => {
|
||||
try {
|
||||
const { data } = req.body;
|
||||
|
||||
//Check if the bodyshopid is real as a "security" measure
|
||||
if (!data.bodyshopid) {
|
||||
throw new Error("No bodyshopid provided in data");
|
||||
}
|
||||
|
||||
const { bodyshops_by_pk } = await client.request(GET_BODYSHOP_BY_ID, {
|
||||
id: data.bodyshopid
|
||||
});
|
||||
|
||||
if (!bodyshops_by_pk) {
|
||||
throw new Error("Invalid bodyshopid provided in data");
|
||||
}
|
||||
|
||||
await client.request(INSERT_MEDIA_ANALYTICS, {
|
||||
mediaObject: data
|
||||
});
|
||||
|
||||
res.json({ status: "success" })
|
||||
} catch (error) {
|
||||
logger.log("document-analytics-error", "ERROR", req?.user?.email, null, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
res.status(500).json({ error: error.message, stack: error.stack });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.default = documentAnalytics;
|
||||
@@ -8,4 +8,5 @@ exports.podium = require("./podium").default;
|
||||
exports.emsUpload = require("./emsUpload").default;
|
||||
exports.carfax = require("./carfax").default;
|
||||
exports.carfaxRps = require("./carfax-rps").default;
|
||||
exports.vehicletype = require("./vehicletype/vehicletype").default;
|
||||
exports.vehicletype = require("./vehicletype/vehicletype").default;
|
||||
exports.documentAnalytics = require("./analytics/documents").default;
|
||||
Reference in New Issue
Block a user