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;
|
||||
@@ -3160,3 +3160,12 @@ exports.DELETE_PHONE_NUMBER_OPT_OUT = `
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
exports.INSERT_MEDIA_ANALYTICS = `
|
||||
mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
||||
insert_media_analytics_one(object: $mediaObject) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -146,7 +146,7 @@ router.post("/bodyshop-cache", eventAuthorizationMiddleware, updateBodyshopCache
|
||||
|
||||
// Estimate Scrubber Vehicle Type
|
||||
router.post("/es/vehicletype", data.vehicletype);
|
||||
|
||||
router.post("/analytics/documents", data.documentAnalytics);
|
||||
// Health Check for docker-compose-cluster load balancer, only available in development
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
router.get("/health", (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user