Added fortellis event logging.
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const fs = require("fs").promises;
|
||||||
require("dotenv").config({
|
require("dotenv").config({
|
||||||
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
|
||||||
});
|
});
|
||||||
|
const client = require("../graphql-client/graphql-client").client;
|
||||||
// const CalcualteAllocations = require("../cdk/cdk-calculate-allocations").default;
|
// const CalcualteAllocations = require("../cdk/cdk-calculate-allocations").default;
|
||||||
const CreateFortellisLogEvent = require("./fortellis-logger");
|
const CreateFortellisLogEvent = require("./fortellis-logger");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
|
const { INSERT_IOEVENT } = require("../graphql-client/queries");
|
||||||
const uuid = require("uuid").v4;
|
const uuid = require("uuid").v4;
|
||||||
const AxiosLib = require("axios").default;
|
const AxiosLib = require("axios").default;
|
||||||
const axios = AxiosLib.create();
|
const axios = AxiosLib.create();
|
||||||
@@ -157,6 +159,19 @@ async function MakeFortellisCall({
|
|||||||
console.log(`Body Contents: ${JSON.stringify(body, null, 4)}`);
|
console.log(`Body Contents: ${JSON.stringify(body, null, 4)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Write to the IOEvent Log
|
||||||
|
|
||||||
|
await WriteToIOEventLog({
|
||||||
|
apiName,
|
||||||
|
fullUrl,
|
||||||
|
logger,
|
||||||
|
socket,
|
||||||
|
useremail: socket.user?.email,
|
||||||
|
type,
|
||||||
|
bodyshopid: ""
|
||||||
|
//bodyshopid: job.bodyshop.id,
|
||||||
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let result;
|
let result;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -297,6 +312,45 @@ function sleep(ms) {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function WriteToIOEventLog({ apiName, type, fullUrl, bodyshopid, useremail, logger, socket }) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
await client.request(INSERT_IOEVENT, {
|
||||||
|
event: {
|
||||||
|
operationname: `fortellis-${apiName}-${type}`,
|
||||||
|
//time,
|
||||||
|
//dbevent,
|
||||||
|
env: isProduction ? "production" : "test",
|
||||||
|
variables: { fullUrl, type, apiName },
|
||||||
|
bodyshopid: socket.bodyshopId,
|
||||||
|
useremail
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.log(
|
||||||
|
"fortellis-tracking-error",
|
||||||
|
"ERROR",
|
||||||
|
socket?.user?.email,
|
||||||
|
socket?.recordid,
|
||||||
|
{
|
||||||
|
operationname: `fortellis-${apiName}-`,
|
||||||
|
//time,
|
||||||
|
//dbevent,
|
||||||
|
env: isProduction ? "production" : "test",
|
||||||
|
variables: {},
|
||||||
|
bodyshopid,
|
||||||
|
useremail,
|
||||||
|
error: error.message,
|
||||||
|
stack: error.stack
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
const isProduction = process.env.NODE_ENV === "production";
|
const isProduction = process.env.NODE_ENV === "production";
|
||||||
|
|
||||||
//Get requests should have the trailing slash as they are used that way in the calls.
|
//Get requests should have the trailing slash as they are used that way in the calls.
|
||||||
|
|||||||
Reference in New Issue
Block a user