Merged in feature/media-analytics-logging (pull request #2651)
Add API route for media analytics, and updates to database schema.
This commit is contained in:
@@ -4711,9 +4711,31 @@
|
|||||||
- table:
|
- table:
|
||||||
name: media_analytics
|
name: media_analytics
|
||||||
schema: public
|
schema: public
|
||||||
|
object_relationships:
|
||||||
|
- name: bodyshop
|
||||||
|
using:
|
||||||
|
foreign_key_constraint_on: bodyshopid
|
||||||
|
array_relationships:
|
||||||
|
- name: media_analytics_details
|
||||||
|
using:
|
||||||
|
foreign_key_constraint_on:
|
||||||
|
column: media_analytics_id
|
||||||
|
table:
|
||||||
|
name: media_analytics_detail
|
||||||
|
schema: public
|
||||||
- table:
|
- table:
|
||||||
name: media_analytics_detail
|
name: media_analytics_detail
|
||||||
schema: public
|
schema: public
|
||||||
|
object_relationships:
|
||||||
|
- name: bodyshop
|
||||||
|
using:
|
||||||
|
foreign_key_constraint_on: bodyshopid
|
||||||
|
- name: job
|
||||||
|
using:
|
||||||
|
foreign_key_constraint_on: jobid
|
||||||
|
- name: media_analytic
|
||||||
|
using:
|
||||||
|
foreign_key_constraint_on: media_analytics_id
|
||||||
- table:
|
- table:
|
||||||
name: messages
|
name: messages
|
||||||
schema: public
|
schema: public
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics" add column "total_size_bytes" integer
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics" add column "total_size_bytes" integer
|
||||||
|
null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics" add column "total_size_mb" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics" add column "total_size_mb" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
-- Could not auto-generate a down migration.
|
||||||
|
-- Please write an appropriate down migration for the SQL below:
|
||||||
|
-- alter table "public"."media_analytics_detail" add column "total_size_mb" numeric
|
||||||
|
-- null;
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
alter table "public"."media_analytics_detail" add column "total_size_mb" numeric
|
||||||
|
null;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" alter column "jobid" set not null;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alter table "public"."media_analytics_detail" alter column "jobid" drop not null;
|
||||||
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;
|
||||||
@@ -9,3 +9,4 @@ exports.emsUpload = require("./emsUpload").default;
|
|||||||
exports.carfax = require("./carfax").default;
|
exports.carfax = require("./carfax").default;
|
||||||
exports.carfaxRps = require("./carfax-rps").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;
|
||||||
@@ -3151,3 +3151,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
|
// Estimate Scrubber Vehicle Type
|
||||||
router.post("/es/vehicletype", data.vehicletype);
|
router.post("/es/vehicletype", data.vehicletype);
|
||||||
|
router.post("/analytics/documents", data.documentAnalytics);
|
||||||
// Health Check for docker-compose-cluster load balancer, only available in development
|
// Health Check for docker-compose-cluster load balancer, only available in development
|
||||||
if (process.env.NODE_ENV === "development") {
|
if (process.env.NODE_ENV === "development") {
|
||||||
router.get("/health", (req, res) => {
|
router.get("/health", (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user