Basic posting up to fortellis-select-customer.
This commit is contained in:
@@ -17,7 +17,7 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
});
|
});
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsCdkVehicles);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsCdkVehicles);
|
||||||
|
|
||||||
export function DmsCdkVehicles({ bodyshop, form, socket, job }) {
|
export function DmsCdkVehicles({ bodyshop, form, job }) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [selectedModel, setSelectedModel] = useState(null);
|
const [selectedModel, setSelectedModel] = useState(null);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
import { Button, Checkbox, Col, Table } from "antd";
|
import { Button, Checkbox, Col, Table } from "antd";
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
|
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||||
import { socket } from "../../pages/dms/dms.container";
|
import { socket } from "../../pages/dms/dms.container";
|
||||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||||
import { alphaSort } from "../../utils/sorters";
|
import { alphaSort } from "../../utils/sorters";
|
||||||
@@ -22,17 +24,47 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
const [selectedCustomer, setSelectedCustomer] = useState(null);
|
||||||
const [dmsType, setDmsType] = useState("cdk");
|
const [dmsType, setDmsType] = useState("cdk");
|
||||||
|
|
||||||
socket.on("cdk-select-customer", (customerList, callback) => {
|
const {
|
||||||
setOpen(true);
|
treatments: { Fortellis }
|
||||||
setDmsType("cdk");
|
} = useSplitTreatments({
|
||||||
setcustomerList(customerList);
|
attributes: {},
|
||||||
});
|
names: ["Fortellis"],
|
||||||
socket.on("pbs-select-customer", (customerList, callback) => {
|
splitKey: bodyshop.imexshopid
|
||||||
setOpen(true);
|
|
||||||
setDmsType("pbs");
|
|
||||||
setcustomerList(customerList);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { socket: wsssocket } = useSocket();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (Fortellis.treatment === "on") {
|
||||||
|
const handleFortellisSelectCustomer = (customerList, callback) => {
|
||||||
|
setOpen(true);
|
||||||
|
setDmsType("fortellis");
|
||||||
|
setcustomerList(customerList);
|
||||||
|
};
|
||||||
|
wsssocket.on("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||||
|
return () => {
|
||||||
|
wsssocket.off("fortellis-select-customer", handleFortellisSelectCustomer);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const handleCdkSelectCustomer = (customerList, callback) => {
|
||||||
|
setOpen(true);
|
||||||
|
setDmsType("cdk");
|
||||||
|
setcustomerList(customerList);
|
||||||
|
};
|
||||||
|
const handlePbsSelectCustomer = (customerList, callback) => {
|
||||||
|
setOpen(true);
|
||||||
|
setDmsType("pbs");
|
||||||
|
setcustomerList(customerList);
|
||||||
|
};
|
||||||
|
socket.on("cdk-select-customer", handleCdkSelectCustomer);
|
||||||
|
socket.on("pbs-select-customer", handlePbsSelectCustomer);
|
||||||
|
return () => {
|
||||||
|
socket.off("cdk-select-customer", handleCdkSelectCustomer);
|
||||||
|
socket.off("pbs-select-customer", handlePbsSelectCustomer);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onUseSelected = () => {
|
const onUseSelected = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
socket.emit(`${dmsType}-selected-customer`, selectedCustomer);
|
||||||
@@ -51,6 +83,42 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
setSelectedCustomer(null);
|
setSelectedCustomer(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fortellisColumns = [
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.id"),
|
||||||
|
dataIndex: "customerId",
|
||||||
|
key: "id"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.vinowner"),
|
||||||
|
dataIndex: "vinOwner",
|
||||||
|
key: "vinOwner",
|
||||||
|
render: (text, record) => <Checkbox disabled checked={record.vinOwner} />
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.name1"),
|
||||||
|
dataIndex: ["customerName", "firstName"],
|
||||||
|
key: "firstName",
|
||||||
|
sorter: (a, b) => alphaSort(a.customerName?.firstName, b.customerName?.firstName)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.name1"),
|
||||||
|
dataIndex: ["customerName", "lastName"],
|
||||||
|
key: "lastName",
|
||||||
|
sorter: (a, b) => alphaSort(a.customerName?.lastName, b.customerName?.lastName)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: t("jobs.fields.dms.address"),
|
||||||
|
|
||||||
|
key: "address",
|
||||||
|
render: (record, value) =>
|
||||||
|
`${record.postalAddress?.addressLine1} ${record.postalAddress?.addressLine2 ? `, ${record.postalAddress?.addressLine2}` : ""},
|
||||||
|
${record.postalAddress?.city} ${record.postalAddress?.state} ${record.postalAddress?.postalCode} ${
|
||||||
|
record.postalAddress?.country
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
const cdkColumns = [
|
const cdkColumns = [
|
||||||
{
|
{
|
||||||
title: t("jobs.fields.dms.id"),
|
title: t("jobs.fields.dms.id"),
|
||||||
@@ -122,13 +190,13 @@ export function DmsCustomerSelector({ bodyshop }) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
pagination={{ position: "top" }}
|
pagination={{ position: "top" }}
|
||||||
columns={dmsType === "cdk" ? cdkColumns : pbsColumns}
|
columns={dmsType === "cdk" ? (Fortellis.treatment === "on" ? fortellisColumns : cdkColumns) : pbsColumns}
|
||||||
rowKey={(record) => (dmsType === "cdk" ? record.id.value : record.ContactId)}
|
rowKey={(record) => (dmsType === "cdk" ? record.id?.value || record.customerId : record.ContactId)}
|
||||||
dataSource={customerList}
|
dataSource={customerList}
|
||||||
//onChange={handleTableChange}
|
//onChange={handleTableChange}
|
||||||
rowSelection={{
|
rowSelection={{
|
||||||
onSelect: (record) => {
|
onSelect: (record) => {
|
||||||
setSelectedCustomer(dmsType === "cdk" ? record.id.value : record.ContactId);
|
setSelectedCustomer(dmsType === "cdk" ? record.id?.value || record.customerId : record.ContactId);
|
||||||
},
|
},
|
||||||
type: "radio",
|
type: "radio",
|
||||||
selectedRowKeys: [selectedCustomer]
|
selectedRowKeys: [selectedCustomer]
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import CurrencyInput from "../form-items-formatted/currency-form-item.component"
|
|||||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||||
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
import DateTimePicker from "../form-date-time-picker/form-date-time-picker.component.jsx";
|
||||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||||
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -38,6 +39,14 @@ const mapDispatchToProps = (dispatch) => ({
|
|||||||
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
export default connect(mapStateToProps, mapDispatchToProps)(DmsPostForm);
|
||||||
|
|
||||||
export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||||
|
const {
|
||||||
|
treatments: { Fortellis }
|
||||||
|
} = useSplitTreatments({
|
||||||
|
attributes: {},
|
||||||
|
names: ["Fortellis"],
|
||||||
|
splitKey: bodyshop.imexshopid
|
||||||
|
});
|
||||||
|
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { socket: wsssocket } = useSocket();
|
const { socket: wsssocket } = useSocket();
|
||||||
@@ -62,21 +71,21 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
|||||||
|
|
||||||
const handleFinish = (values) => {
|
const handleFinish = (values) => {
|
||||||
//TODO: Add this as a split instead.
|
//TODO: Add this as a split instead.
|
||||||
if (true) {
|
if (Fortellis.treatment === "on") {
|
||||||
wsssocket.emit("fortellis-export-job", { jobid: job.id, txEnvelope: values });
|
wsssocket.emit("fortellis-export-job", { jobid: job.id, txEnvelope: values });
|
||||||
} else {
|
} else {
|
||||||
socket.emit(`${determineDmsType(bodyshop)}-export-job`, {
|
socket.emit(`${determineDmsType(bodyshop)}-export-job`, {
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
txEnvelope: values
|
txEnvelope: values
|
||||||
});
|
});
|
||||||
console.log(logsRef);
|
}
|
||||||
if (logsRef) {
|
console.log(logsRef);
|
||||||
console.log("executing", logsRef);
|
if (logsRef) {
|
||||||
logsRef.curent &&
|
console.log("executing", logsRef);
|
||||||
logsRef.current.scrollIntoView({
|
logsRef.curent &&
|
||||||
behavior: "smooth"
|
logsRef.current.scrollIntoView({
|
||||||
});
|
behavior: "smooth"
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,7 +194,7 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</LayoutFormRow>
|
</LayoutFormRow>
|
||||||
<Space>
|
<Space>
|
||||||
<DmsCdkMakes form={form} socket={socket} job={job} />
|
<DmsCdkMakes form={form} job={job} />
|
||||||
<DmsCdkMakesRefetch />
|
<DmsCdkMakesRefetch />
|
||||||
<Form.Item name="dms_unsold" label={t("jobs.fields.dms.dms_unsold")} initialValue={false}>
|
<Form.Item name="dms_unsold" label={t("jobs.fields.dms.dms_unsold")} initialValue={false}>
|
||||||
<Switch />
|
<Switch />
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import { selectBodyshop } from "../../redux/user/user.selectors";
|
|||||||
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
import InstanceRenderManager from "../../utils/instanceRenderMgr";
|
||||||
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
import AuditTrailMapping from "../../utils/AuditTrailMappings";
|
||||||
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
import { useNotification } from "../../contexts/Notifications/notificationContext.jsx";
|
||||||
|
import { useSplitTreatments } from "@splitsoftware/splitio-react";
|
||||||
|
import { useSocket } from "../../contexts/SocketIO/useSocket.js";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop
|
||||||
@@ -54,6 +56,14 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
const search = queryString.parse(useLocation().search);
|
const search = queryString.parse(useLocation().search);
|
||||||
const { jobId } = search;
|
const { jobId } = search;
|
||||||
const notification = useNotification();
|
const notification = useNotification();
|
||||||
|
const {
|
||||||
|
treatments: { Fortellis }
|
||||||
|
} = useSplitTreatments({
|
||||||
|
attributes: {},
|
||||||
|
names: ["Fortellis"],
|
||||||
|
splitKey: bodyshop.imexshopid
|
||||||
|
});
|
||||||
|
const { socket: wsssocket } = useSocket();
|
||||||
|
|
||||||
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
const { loading, error, data } = useQuery(QUERY_JOB_EXPORT_DMS, {
|
||||||
variables: { id: jobId },
|
variables: { id: jobId },
|
||||||
@@ -84,45 +94,75 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
}, [t, setBreadcrumbs, setSelectedHeader]);
|
}, [t, setBreadcrumbs, setSelectedHeader]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
if (Fortellis.treatment === "on") {
|
||||||
socket.on("reconnect", () => {
|
wsssocket.emit("set-log-level", logLevel);
|
||||||
setLogs((logs) => {
|
|
||||||
return [
|
|
||||||
...logs,
|
|
||||||
{
|
|
||||||
timestamp: new Date(),
|
|
||||||
level: "warn",
|
|
||||||
message: "Reconnected to CDK Export Service"
|
|
||||||
}
|
|
||||||
];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
socket.on("connect_error", (err) => {
|
|
||||||
console.log(`connect_error due to ${err}`, err);
|
|
||||||
notification.error({ message: err.message });
|
|
||||||
});
|
|
||||||
socket.on("log-event", (payload) => {
|
|
||||||
setLogs((logs) => {
|
|
||||||
return [...logs, payload];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
socket.on("export-success", (payload) => {
|
|
||||||
notification.success({
|
|
||||||
message: t("jobs.successes.exported")
|
|
||||||
});
|
|
||||||
insertAuditTrail({
|
|
||||||
jobid: payload,
|
|
||||||
operation: AuditTrailMapping.jobexported(),
|
|
||||||
type: "jobexported"
|
|
||||||
});
|
|
||||||
history("/manage/accounting/receivables");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (socket.disconnected) socket.connect();
|
const handleLogEvent = (payload) => {
|
||||||
return () => {
|
setLogs((logs) => {
|
||||||
socket.removeAllListeners();
|
return [...logs, payload];
|
||||||
socket.disconnect();
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleExportSuccess = (payload) => {
|
||||||
|
notification.success({
|
||||||
|
message: t("jobs.successes.exported")
|
||||||
|
});
|
||||||
|
insertAuditTrail({
|
||||||
|
jobid: payload,
|
||||||
|
operation: AuditTrailMapping.jobexported(),
|
||||||
|
type: "jobexported"
|
||||||
|
});
|
||||||
|
history("/manage/accounting/receivables");
|
||||||
|
};
|
||||||
|
|
||||||
|
wsssocket.on("fortellis-log-event", handleLogEvent);
|
||||||
|
wsssocket.on("export-success", handleExportSuccess);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
wsssocket.off("fortellis-log-event", handleLogEvent);
|
||||||
|
wsssocket.off("export-success", handleExportSuccess);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
socket.on("connect", () => socket.emit("set-log-level", logLevel));
|
||||||
|
socket.on("reconnect", () => {
|
||||||
|
setLogs((logs) => {
|
||||||
|
return [
|
||||||
|
...logs,
|
||||||
|
{
|
||||||
|
timestamp: new Date(),
|
||||||
|
level: "warn",
|
||||||
|
message: "Reconnected to CDK Export Service"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
socket.on("connect_error", (err) => {
|
||||||
|
console.log(`connect_error due to ${err}`, err);
|
||||||
|
notification.error({ message: err.message });
|
||||||
|
});
|
||||||
|
socket.on("log-event", (payload) => {
|
||||||
|
setLogs((logs) => {
|
||||||
|
return [...logs, payload];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
socket.on("export-success", (payload) => {
|
||||||
|
notification.success({
|
||||||
|
message: t("jobs.successes.exported")
|
||||||
|
});
|
||||||
|
insertAuditTrail({
|
||||||
|
jobid: payload,
|
||||||
|
operation: AuditTrailMapping.jobexported(),
|
||||||
|
type: "jobexported"
|
||||||
|
});
|
||||||
|
history("/manage/accounting/receivables");
|
||||||
|
});
|
||||||
|
|
||||||
|
if (socket.disconnected) socket.connect();
|
||||||
|
return () => {
|
||||||
|
socket.removeAllListeners();
|
||||||
|
socket.disconnect();
|
||||||
|
};
|
||||||
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -137,6 +177,9 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader, inse
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
{Fortellis.treatment === "on" && (
|
||||||
|
<AlertComponent message="Posting to Fortellis" type="warning" showIcon closable />
|
||||||
|
)}
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]}>
|
||||||
<Col md={24} lg={10}>
|
<Col md={24} lg={10}>
|
||||||
<DmsAllocationsSummary
|
<DmsAllocationsSummary
|
||||||
|
|||||||
7
package-lock.json
generated
7
package-lock.json
generated
@@ -23,6 +23,7 @@
|
|||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
"aws4": "^1.13.2",
|
"aws4": "^1.13.2",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
"axios-curlirize": "^2.0.0",
|
||||||
"bee-queue": "^1.7.1",
|
"bee-queue": "^1.7.1",
|
||||||
"better-queue": "^3.8.12",
|
"better-queue": "^3.8.12",
|
||||||
"bluebird": "^3.7.2",
|
"bluebird": "^3.7.2",
|
||||||
@@ -4848,6 +4849,12 @@
|
|||||||
"proxy-from-env": "^1.1.0"
|
"proxy-from-env": "^1.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/axios-curlirize": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios-curlirize/-/axios-curlirize-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-TrQBa8MfIwaYsrCoYhfCr7NDRXLuGm+Rqh/PtAuO64b8PCCOJWn37BWQvpN4/mzzig3uHb4qXzvpxJmALHaiwA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/axios-ntlm": {
|
"node_modules/axios-ntlm": {
|
||||||
"version": "1.4.4",
|
"version": "1.4.4",
|
||||||
"resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/axios-ntlm/-/axios-ntlm-1.4.4.tgz",
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
"aws4": "^1.13.2",
|
"aws4": "^1.13.2",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
"axios-curlirize": "^2.0.0",
|
||||||
"bee-queue": "^1.7.1",
|
"bee-queue": "^1.7.1",
|
||||||
"better-queue": "^3.8.12",
|
"better-queue": "^3.8.12",
|
||||||
"bluebird": "^3.7.2",
|
"bluebird": "^3.7.2",
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ const logger = require("../utils/logger");
|
|||||||
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();
|
||||||
|
const axiosCurlirize = require('axios-curlirize').default;
|
||||||
|
|
||||||
|
axiosCurlirize(axios, (result, err) => {
|
||||||
|
const { command } = result;
|
||||||
|
console.log("*** ~ axiosCurlirize ~ command:", command);
|
||||||
|
|
||||||
|
// if (err) {
|
||||||
|
// use your logger here
|
||||||
|
// } else {
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
|
||||||
const getTransactionType = (jobid) => `fortellis:${jobid}`;
|
const getTransactionType = (jobid) => `fortellis:${jobid}`;
|
||||||
const defaultFortellisTTL = 60 * 60;
|
const defaultFortellisTTL = 60 * 60;
|
||||||
@@ -100,10 +111,11 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) {
|
|||||||
);
|
);
|
||||||
console.log("===========");
|
console.log("===========");
|
||||||
}
|
}
|
||||||
|
//TODO: Verify how to select the correct department.
|
||||||
const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object.
|
const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object.
|
||||||
.find((info) => info.name === apiName)?.departments; //Departments are categorized by API name and have an array of departments.
|
.find((info) => info.name === apiName)?.departments; //Departments are categorized by API name and have an array of departments.
|
||||||
|
|
||||||
return departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department.
|
return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department.
|
||||||
}
|
}
|
||||||
|
|
||||||
//Highest level function call to make a call to fortellis. This should be the only call required, and it will handle all the logic for making the call.
|
//Highest level function call to make a call to fortellis. This should be the only call required, and it will handle all the logic for making the call.
|
||||||
@@ -114,13 +126,17 @@ async function MakeFortellisCall({
|
|||||||
body = {},
|
body = {},
|
||||||
type = "post",
|
type = "post",
|
||||||
debug = true,
|
debug = true,
|
||||||
|
requestPathParams,
|
||||||
|
requestSearchParams = [], //Array of key/value strings like [["key", "value"]]
|
||||||
jobid,
|
jobid,
|
||||||
redisHelpers,
|
redisHelpers,
|
||||||
socket
|
socket,
|
||||||
}) {
|
}) {
|
||||||
const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
||||||
|
|
||||||
if (debug) logger.log(`Executing ${type} to ${url}`);
|
const fullUrl = constructFullUrl({ url, pathParams: requestPathParams, requestSearchParams });
|
||||||
|
|
||||||
|
if (debug) logger.log(`Executing ${type} to ${fullUrl}`);
|
||||||
const ReqId = uuid();
|
const ReqId = uuid();
|
||||||
const access_token = await GetAuthToken();
|
const access_token = await GetAuthToken();
|
||||||
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid });
|
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid });
|
||||||
@@ -138,18 +154,18 @@ async function MakeFortellisCall({
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "post":
|
case "post":
|
||||||
default:
|
default:
|
||||||
result = await axios.post(url, body, {
|
result = await axios.post(fullUrl, body, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${access_token}`,
|
Authorization: `Bearer ${access_token}`,
|
||||||
"Subscription-Id": SubscriptionMeta.subscriptionId,
|
"Subscription-Id": SubscriptionMeta.subscriptionId,
|
||||||
"Request-Id": ReqId,
|
"Request-Id": ReqId,
|
||||||
"Department-Id": DepartmentId,
|
...DepartmentId && { "Department-Id": DepartmentId },
|
||||||
...headers
|
...headers
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case "get":
|
case "get":
|
||||||
result = await axios.get(url, {
|
result = await axios.get(fullUrl, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${access_token}`,
|
Authorization: `Bearer ${access_token}`,
|
||||||
"Subscription-Id": SubscriptionMeta.subscriptionId,
|
"Subscription-Id": SubscriptionMeta.subscriptionId,
|
||||||
@@ -229,10 +245,31 @@ const FortellisActions = {
|
|||||||
type: "get",
|
type: "get",
|
||||||
apiName: "Service Vehicle - Query Vehicles"
|
apiName: "Service Vehicle - Query Vehicles"
|
||||||
},
|
},
|
||||||
|
GetVehicleId: {
|
||||||
|
url: isProduction
|
||||||
|
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/vehicle-ids/" //Request path params of vins
|
||||||
|
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/vehicle-ids/",
|
||||||
|
type: "get",
|
||||||
|
apiName: "CDK Drive Post Service Vehicle",
|
||||||
|
},
|
||||||
|
GetVehicleById: {
|
||||||
|
url: isProduction
|
||||||
|
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/" //Request path params of vehicleId
|
||||||
|
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/",
|
||||||
|
type: "get",
|
||||||
|
apiName: "CDK Drive Post Service Vehicle",
|
||||||
|
},
|
||||||
|
QueryCustomerByName: {
|
||||||
|
url: isProduction
|
||||||
|
? "https://api.fortellis.io/cdk/drive/customerpost/v1/search"
|
||||||
|
: "https://api.fortellis.io/cdk-test/drive/customerpost/v1/search",
|
||||||
|
type: "get",
|
||||||
|
apiName: "CDK Drive Post Customer",
|
||||||
|
},
|
||||||
GetCOA: {
|
GetCOA: {
|
||||||
type: "get",
|
type: "get",
|
||||||
apiName: "CDK Drive Post Accounts GL WIP",
|
apiName: "CDK Drive Post Accounts GL WIP",
|
||||||
url: `https://api.fortellis.io/cdk-test/drive/chartofaccounts/v2/bulk`,
|
url: `https://api.fortellis.io/cdk-test/drive/chartofaccounts/v2/bulk/`,
|
||||||
waitForResult: true
|
waitForResult: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -243,6 +280,17 @@ const FortellisCacheEnums = {
|
|||||||
DepartmentId: "DepartmentId"
|
DepartmentId: "DepartmentId"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function constructFullUrl({ url, pathParams = "", requestSearchParams = [] }) {
|
||||||
|
// Ensure the base URL ends with a single "/"
|
||||||
|
url = url.replace(/\/+$/, "/");
|
||||||
|
const fullPath = pathParams ? `${url}${pathParams}` : url;
|
||||||
|
const searchParams = new URLSearchParams(requestSearchParams).toString();
|
||||||
|
const fullUrl = searchParams ? `${fullPath}?${searchParams}` : fullPath;
|
||||||
|
return fullUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
GetAuthToken,
|
GetAuthToken,
|
||||||
FortellisCacheEnums,
|
FortellisCacheEnums,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
|
|
||||||
const CreateFortellisLogEvent = (socket, level, message, txnDetails) => {
|
const CreateFortellisLogEvent = (socket, level, message, txnDetails) => {
|
||||||
//TODO: Add detaisl to track the whole transaction between Fortellis and the server.
|
//TODO: Add detaisl to track the whole transaction between Fortellis and the server.
|
||||||
logger.log("fortellis-log-event", level, socket?.user?.email, null, { wsmessage: message, txnDetails });
|
logger.log("fortellis-log-event", level, socket?.user?.email, null, { wsmessage: message, txnDetails });
|
||||||
socket.emit("fortellis-log-event", { level, message, txnDetails });
|
socket.emit("fortellis-log-event", { level, message, txnDetails });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ const {
|
|||||||
defaultFortellisTTL,
|
defaultFortellisTTL,
|
||||||
FortellisCacheEnums
|
FortellisCacheEnums
|
||||||
} = require("./fortellis-helpers");
|
} = require("./fortellis-helpers");
|
||||||
|
const { last } = require("lodash");
|
||||||
|
|
||||||
// const moment = require("moment-timezone");
|
// const moment = require("moment-timezone");
|
||||||
|
|
||||||
// const replaceSpecialRegex = /[^a-zA-Z0-9 .,\n #]+/g;
|
const replaceSpecialRegex = /[^a-zA-Z0-9 .,\n #]+/g;
|
||||||
|
|
||||||
async function FortellisJobExport({
|
async function FortellisJobExport({
|
||||||
socket,
|
socket,
|
||||||
@@ -37,10 +38,6 @@ async function FortellisJobExport({
|
|||||||
getSessionTransactionData,
|
getSessionTransactionData,
|
||||||
clearSessionTransactionData
|
clearSessionTransactionData
|
||||||
} = redisHelpers;
|
} = redisHelpers;
|
||||||
// ////Store the following information into the redis store for this transaction.
|
|
||||||
// socket.logEvents = [];
|
|
||||||
// socket.recordid = jobid;
|
|
||||||
// socket.txEnvelope = txEnvelope;
|
|
||||||
try {
|
try {
|
||||||
CreateFortellisLogEvent(socket, "debug", `Received Job export request for id ${jobid}`);
|
CreateFortellisLogEvent(socket, "debug", `Received Job export request for id ${jobid}`);
|
||||||
await setSessionTransactionData(
|
await setSessionTransactionData(
|
||||||
@@ -54,127 +51,133 @@ async function FortellisJobExport({
|
|||||||
const JobData = await QueryJobData({ socket, jobid }); //TODO: Need to remove unnecessary stuff here to reduce the payload.
|
const JobData = await QueryJobData({ socket, jobid }); //TODO: Need to remove unnecessary stuff here to reduce the payload.
|
||||||
await setSessionTransactionData(socket.id, getTransactionType(jobid), `JobData`, JobData, defaultFortellisTTL);
|
await setSessionTransactionData(socket.id, getTransactionType(jobid), `JobData`, JobData, defaultFortellisTTL);
|
||||||
|
|
||||||
// const DealerId = JobData.bodyshop.cdk_dealerid;
|
|
||||||
|
|
||||||
CreateFortellisLogEvent(socket, "DEBUG", `{1} Begin Calculate DMS Vehicle ID using VIN: ${JobData.v_vin}`);
|
CreateFortellisLogEvent(socket, "DEBUG", `{1} Begin Calculate DMS Vehicle ID using VIN: ${JobData.v_vin}`);
|
||||||
const DMSVid = await CalculateDmsVid({ socket, JobData, redisHelpers });
|
const DMSVid = await CalculateDmsVid({ socket, JobData, redisHelpers });
|
||||||
await setSessionTransactionData(socket.id, getTransactionType(jobid), `DMSVid`, DMSVid, defaultFortellisTTL);
|
await setSessionTransactionData(socket.id, getTransactionType(jobid), `DMSVid`, DMSVid, defaultFortellisTTL);
|
||||||
|
|
||||||
if (socket.DMSVid.newId === "N") {
|
let DMSVehCustomer;
|
||||||
|
if (DMSVid.newId === "N") {
|
||||||
CreateFortellisLogEvent(
|
CreateFortellisLogEvent(
|
||||||
socket,
|
socket,
|
||||||
"DEBUG",
|
"DEBUG",
|
||||||
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid.vehiclesVehId}`
|
`{2.1} Querying the Vehicle using the DMSVid: ${socket.DMSVid.vehiclesVehId}`
|
||||||
);
|
);
|
||||||
// socket.DMSVeh = await QueryDmsVehicleById(socket, JobData, socket.DMSVid);
|
const DMSVeh = await QueryDmsVehicleById({ socket, redisHelpers, JobData, DMSVid });
|
||||||
|
await setSessionTransactionData(socket.id, getTransactionType(jobid), `DMSVeh`, DMSVeh, defaultFortellisTTL);
|
||||||
|
|
||||||
// const DMSVehCustomer =
|
const DMSVehCustomerFromVehicle =
|
||||||
// socket.DMSVeh && socket.DMSVeh.owners && socket.DMSVeh.owners.find((o) => o.id.assigningPartyId === "CURRENT");
|
DMSVeh && DMSVeh.owners && DMSVeh.owners.find((o) => o.id.assigningPartyId === "CURRENT");
|
||||||
|
|
||||||
// if (DMSVehCustomer && DMSVehCustomer.id && DMSVehCustomer.id.value) {
|
if (DMSVehCustomerFromVehicle && DMSVehCustomerFromVehicle.id && DMSVehCustomerFromVehicle.id.value) {
|
||||||
// CdkBase.createLogEvent(
|
CreateFortellisLogEvent(
|
||||||
// socket,
|
socket,
|
||||||
// "DEBUG",
|
"DEBUG",
|
||||||
// `{2.2} Querying the Customer using the ID from DMSVeh: ${DMSVehCustomer.id.value}`
|
`{2.2} Querying the Customer using the ID from DMSVeh: ${DMSVehCustomerFromVehicle.id.value}`
|
||||||
// );
|
);
|
||||||
// socket.DMSVehCustomer = await QueryDmsCustomerById(socket, JobData, DMSVehCustomer.id.value);
|
DMSVehCustomer = await QueryDmsCustomerById({ socket, redisHelpers, JobData, CustomerId: DMSVehCustomerFromVehicle.id.value });
|
||||||
|
await setSessionTransactionData(socket.id, getTransactionType(jobid), `DMSVehCustomer`, DMSVehCustomer, defaultFortellisTTL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
CreateFortellisLogEvent(socket, "DEBUG", `{2.3} Querying the Customer using the name.`);
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{2.3} Querying the Customer using the name.`);
|
const DMSCustList = await QueryDmsCustomerByName({ socket, redisHelpers, JobData });
|
||||||
|
await setSessionTransactionData(socket.id, getTransactionType(jobid), `DMSCustList`, DMSCustList, defaultFortellisTTL);
|
||||||
|
|
||||||
// socket.DMSCustList = await QueryDmsCustomerByName(socket, JobData);
|
|
||||||
|
|
||||||
// socket.emit("cdk-select-customer", [
|
socket.emit("fortellis-select-customer", [
|
||||||
// ...(socket.DMSVehCustomer ? [{ ...socket.DMSVehCustomer, vinOwner: true }] : []),
|
...(DMSVehCustomer ? [{ ...DMSVehCustomer, vinOwner: true }] : []),
|
||||||
// ...socket.DMSCustList
|
...DMSCustList
|
||||||
// ]);
|
]);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CreateFortellisLogEvent(socket, "ERROR", `Error in FortellisJobExport - ${error}`, {
|
CreateFortellisLogEvent(socket, "ERROR", `Error in FortellisJobExport - ${error}`, {
|
||||||
error: error.message,
|
error: error.message,
|
||||||
stack: error.stack
|
stack: error.stack
|
||||||
});
|
});
|
||||||
//CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkJobExport. ${error}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
|
||||||
// try {
|
|
||||||
// socket.selectedCustomerId = selectedCustomerId;
|
|
||||||
// if (selectedCustomerId) {
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{3.1} Querying the Customer using Customer ID: ${selectedCustomerId}`);
|
|
||||||
// socket.DMSCust = await QueryDmsCustomerById(socket, socket.JobData, selectedCustomerId);
|
|
||||||
// } else {
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{3.2} Generating a new customer ID.`);
|
|
||||||
// const newCustomerId = await GenerateDmsCustomerNumber(socket);
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{3.3} Inserting new customer with ID: ${newCustomerId}`);
|
|
||||||
// socket.DMSCust = await InsertDmsCustomer(socket, newCustomerId);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (socket.DMSVid.newId === "Y") {
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{4.1} Inserting new vehicle with ID: ID ${socket.DMSVid.vehiclesVehId}`);
|
|
||||||
// socket.DMSVeh = await InsertDmsVehicle(socket);
|
|
||||||
// } else {
|
|
||||||
// CdkBase.createLogEvent(
|
|
||||||
// socket,
|
|
||||||
// "DEBUG",
|
|
||||||
// `{4.2} Querying Existing Vehicle using ID ${socket.DMSVid.vehiclesVehId}`
|
|
||||||
// );
|
|
||||||
// socket.DMSVeh = await QueryDmsVehicleById(socket, socket.JobData, socket.DMSVid);
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{4.3} Updating Existing Vehicle to associate to owner.`);
|
|
||||||
// socket.DMSVeh = await UpdateDmsVehicle(socket);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{5} Creating Transaction header with Dms Start WIP`);
|
|
||||||
// socket.DMSTransHeader = await InsertDmsStartWip(socket);
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{5.1} Creating Transaction with ID ${socket.DMSTransHeader.transID}`);
|
|
||||||
|
|
||||||
// socket.DMSBatchTxn = await InsertDmsBatchWip(socket);
|
|
||||||
// CdkBase.createLogEvent(
|
|
||||||
// socket,
|
|
||||||
// "DEBUG",
|
|
||||||
// `{6} Attempting to post Transaction with ID ${socket.DMSTransHeader.transID}`
|
|
||||||
// );
|
|
||||||
// socket.DmsBatchTxnPost = await PostDmsBatchWip(socket);
|
|
||||||
// if (socket.DmsBatchTxnPost.code === "success") {
|
|
||||||
// //something
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{6} Successfully posted sransaction to DMS.`);
|
|
||||||
|
|
||||||
// await MarkJobExported(socket, socket.JobData.id);
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{5} Updating Service Vehicle History.`);
|
|
||||||
// socket.DMSVehHistory = await InsertServiceVehicleHistory(socket);
|
|
||||||
// socket.emit("export-success", socket.JobData.id);
|
|
||||||
// } else {
|
|
||||||
// //Get the error code
|
|
||||||
// CdkBase.createLogEvent(
|
|
||||||
// socket,
|
|
||||||
// "DEBUG",
|
|
||||||
// `{6.1} Getting errors for Transaction ID ${socket.DMSTransHeader.transID}`
|
|
||||||
// );
|
|
||||||
// socket.DmsError = await QueryDmsErrWip(socket);
|
|
||||||
// //Delete the transaction
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `{6.2} Deleting Transaction ID ${socket.DMSTransHeader.transID}`);
|
|
||||||
// socket.DmsBatchTxnPost = await DeleteDmsWip(socket);
|
|
||||||
|
|
||||||
// socket.DmsError.errMsg
|
|
||||||
// .split("|")
|
|
||||||
// .map(
|
|
||||||
// (e) =>
|
|
||||||
// e !== null &&
|
|
||||||
// e !== "" &&
|
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `Error(s) encountered in posting transaction. ${e}`)
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// } catch (error) {
|
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkSelectedCustomer. ${error}`);
|
|
||||||
// await InsertFailedExportLog(socket, error);
|
|
||||||
// } finally {
|
|
||||||
// //Ensure we always insert logEvents
|
|
||||||
// //GQL to insert logevents.
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `Capturing log events to database.`);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// async function CdkSelectedCustomer(socket, selectedCustomerId) {
|
||||||
|
// try {
|
||||||
|
// socket.selectedCustomerId = selectedCustomerId;
|
||||||
|
// if (selectedCustomerId) {
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{3.1} Querying the Customer using Customer ID: ${selectedCustomerId}`);
|
||||||
|
// socket.DMSCust = await QueryDmsCustomerById(socket, socket.JobData, selectedCustomerId);
|
||||||
|
// } else {
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{3.2} Generating a new customer ID.`);
|
||||||
|
// const newCustomerId = await GenerateDmsCustomerNumber(socket);
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{3.3} Inserting new customer with ID: ${newCustomerId}`);
|
||||||
|
// socket.DMSCust = await InsertDmsCustomer(socket, newCustomerId);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (socket.DMSVid.newId === "Y") {
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{4.1} Inserting new vehicle with ID: ID ${socket.DMSVid.vehiclesVehId}`);
|
||||||
|
// socket.DMSVeh = await InsertDmsVehicle(socket);
|
||||||
|
// } else {
|
||||||
|
// CdkBase.createLogEvent(
|
||||||
|
// socket,
|
||||||
|
// "DEBUG",
|
||||||
|
// `{4.2} Querying Existing Vehicle using ID ${socket.DMSVid.vehiclesVehId}`
|
||||||
|
// );
|
||||||
|
// socket.DMSVeh = await QueryDmsVehicleById(socket, socket.JobData, socket.DMSVid);
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{4.3} Updating Existing Vehicle to associate to owner.`);
|
||||||
|
// socket.DMSVeh = await UpdateDmsVehicle(socket);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{5} Creating Transaction header with Dms Start WIP`);
|
||||||
|
// socket.DMSTransHeader = await InsertDmsStartWip(socket);
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{5.1} Creating Transaction with ID ${socket.DMSTransHeader.transID}`);
|
||||||
|
|
||||||
|
// socket.DMSBatchTxn = await InsertDmsBatchWip(socket);
|
||||||
|
// CdkBase.createLogEvent(
|
||||||
|
// socket,
|
||||||
|
// "DEBUG",
|
||||||
|
// `{6} Attempting to post Transaction with ID ${socket.DMSTransHeader.transID}`
|
||||||
|
// );
|
||||||
|
// socket.DmsBatchTxnPost = await PostDmsBatchWip(socket);
|
||||||
|
// if (socket.DmsBatchTxnPost.code === "success") {
|
||||||
|
// //something
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{6} Successfully posted sransaction to DMS.`);
|
||||||
|
|
||||||
|
// await MarkJobExported(socket, socket.JobData.id);
|
||||||
|
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{5} Updating Service Vehicle History.`);
|
||||||
|
// socket.DMSVehHistory = await InsertServiceVehicleHistory(socket);
|
||||||
|
// socket.emit("export-success", socket.JobData.id);
|
||||||
|
// } else {
|
||||||
|
// //Get the error code
|
||||||
|
// CdkBase.createLogEvent(
|
||||||
|
// socket,
|
||||||
|
// "DEBUG",
|
||||||
|
// `{6.1} Getting errors for Transaction ID ${socket.DMSTransHeader.transID}`
|
||||||
|
// );
|
||||||
|
// socket.DmsError = await QueryDmsErrWip(socket);
|
||||||
|
// //Delete the transaction
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `{6.2} Deleting Transaction ID ${socket.DMSTransHeader.transID}`);
|
||||||
|
// socket.DmsBatchTxnPost = await DeleteDmsWip(socket);
|
||||||
|
|
||||||
|
// socket.DmsError.errMsg
|
||||||
|
// .split("|")
|
||||||
|
// .map(
|
||||||
|
// (e) =>
|
||||||
|
// e !== null &&
|
||||||
|
// e !== "" &&
|
||||||
|
// CdkBase.createLogEvent(socket, "ERROR", `Error(s) encountered in posting transaction. ${e}`)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkSelectedCustomer. ${error}`);
|
||||||
|
// await InsertFailedExportLog(socket, error);
|
||||||
|
// } finally {
|
||||||
|
// //Ensure we always insert logEvents
|
||||||
|
// //GQL to insert logevents.
|
||||||
|
|
||||||
|
// CdkBase.createLogEvent(socket, "DEBUG", `Capturing log events to database.`);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
// exports.CdkSelectedCustomer = CdkSelectedCustomer;
|
// exports.CdkSelectedCustomer = CdkSelectedCustomer;
|
||||||
|
|
||||||
async function QueryJobData({ socket, jobid }) {
|
async function QueryJobData({ socket, jobid }) {
|
||||||
@@ -188,170 +191,107 @@ async function QueryJobData({ socket, jobid }) {
|
|||||||
async function CalculateDmsVid({ socket, JobData, redisHelpers }) {
|
async function CalculateDmsVid({ socket, JobData, redisHelpers }) {
|
||||||
try {
|
try {
|
||||||
const result = await MakeFortellisCall({
|
const result = await MakeFortellisCall({
|
||||||
...FortellisActions.QueryVehicles,
|
...FortellisActions.GetVehicleId,
|
||||||
|
requestPathParams: JobData.v_vin,
|
||||||
headers: {},
|
headers: {},
|
||||||
redisHelpers,
|
redisHelpers,
|
||||||
socket,
|
socket,
|
||||||
jobid: JobData.id,
|
jobid: JobData.id,
|
||||||
body: {
|
body: {},
|
||||||
vin: JobData.v_vin
|
|
||||||
//Include the contents of the call here.
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
// const soapClientVehicleInsertUpdate = await soap.createClientAsync(CdkWsdl.VehicleInsertUpdate);
|
return result;
|
||||||
// const soapResponseVehicleInsertUpdate = await soapClientVehicleInsertUpdate.getVehIdsAsync({
|
|
||||||
// arg0: CDK_CREDENTIALS,
|
|
||||||
// arg1: { id: JobData.bodyshop.cdk_dealerid },
|
|
||||||
// arg2: { VIN: JobData.v_vin }
|
|
||||||
// });
|
|
||||||
// const [result, rawResponse, , rawRequest] = soapResponseVehicleInsertUpdate;
|
|
||||||
// CdkBase.createXmlEvent(socket, rawRequest, `soapClientVehicleInsertUpdate.getVehIdsAsync request.`);
|
|
||||||
// CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.getVehIdsAsync response.`);
|
|
||||||
// CdkBase.createLogEvent(
|
|
||||||
// socket,
|
|
||||||
// "SILLY",
|
|
||||||
// `soapClientVehicleInsertUpdate.getVehIdsAsync Result ${JSON.stringify(result, null, 2)}`
|
|
||||||
// );
|
|
||||||
// CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
|
||||||
// //if (result && result.return && result.return.length > 1) {
|
|
||||||
// return result.return.find((r) => r.vehiclesVehId);
|
|
||||||
// //}
|
|
||||||
//return result && result.return && result.return[0];
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
CreateFortellisLogEvent(socket, "ERROR", `Error in CalculateDmsVid - ${error}`, { request: error.request });
|
CreateFortellisLogEvent(socket, "ERROR", `Error in CalculateDmsVid - ${error}`, { request: error.request });
|
||||||
// CdkBase.createXmlEvent(socket, error.request, `soapClientVehicleInsertUpdate.getVehIdsAsync request.`, true);
|
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(
|
|
||||||
// socket,
|
|
||||||
// error.response && error.response.data,
|
|
||||||
// `soapClientVehicleInsertUpdate.getVehIdsAsync response.`,
|
|
||||||
// true
|
|
||||||
// );
|
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `{1} Error in CalculateDmsVid - ${error}`);
|
|
||||||
// throw new Error(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function QueryDmsVehicleById(socket, JobData, DMSVid) {
|
async function QueryDmsVehicleById({ socket, redisHelpers, JobData, DMSVid }) {
|
||||||
// try {
|
try {
|
||||||
// const soapClientVehicleInsertUpdate = await soap.createClientAsync(CdkWsdl.VehicleInsertUpdate);
|
const result = await MakeFortellisCall({
|
||||||
|
...FortellisActions.GetVehicleById,
|
||||||
|
requestPathParams: DMSVid.vehiclesVehId,
|
||||||
|
headers: {},
|
||||||
|
redisHelpers,
|
||||||
|
socket,
|
||||||
|
jobid: JobData.id,
|
||||||
|
body: {},
|
||||||
|
});
|
||||||
|
const VehicleFromDMS = result && result.return && result.return.vehicle;
|
||||||
|
return VehicleFromDMS;
|
||||||
|
} catch (error) {
|
||||||
|
CreateFortellisLogEvent(socket, "ERROR", `Error in QueryDmsVehicleById - ${error}`, { request: error.request });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// const soapResponseVehicleInsertUpdate = await soapClientVehicleInsertUpdate.readAsync({
|
async function QueryDmsCustomerById({ socket, redisHelpers, JobData, CustomerId }) {
|
||||||
// arg0: CDK_CREDENTIALS,
|
try {
|
||||||
// arg1: { id: JobData.bodyshop.cdk_dealerid },
|
const soapClientCustomerInsertUpdate = await soap.createClientAsync(CdkWsdl.CustomerInsertUpdate);
|
||||||
// arg2: {
|
const soapResponseCustomerInsertUpdate = await soapClientCustomerInsertUpdate.readAsync({
|
||||||
// fileType: "VEHICLES",
|
arg0: CDK_CREDENTIALS,
|
||||||
// vehiclesVehicleId: DMSVid.vehiclesVehId
|
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
||||||
// }
|
arg2: {
|
||||||
// });
|
// userId: CustomerId,
|
||||||
|
},
|
||||||
|
arg3: CustomerId
|
||||||
|
});
|
||||||
|
|
||||||
// const [result, rawResponse, , rawRequest] = soapResponseVehicleInsertUpdate;
|
const [result, rawResponse, , rawRequest] = soapResponseCustomerInsertUpdate;
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(socket, rawRequest, `soapClientVehicleInsertUpdate.readAsync request.`);
|
CdkBase.createXmlEvent(socket, rawRequest, `soapClientCustomerInsertUpdate.readAsync request.`);
|
||||||
|
|
||||||
// CdkBase.createLogEvent(
|
CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.readAsync response.`);
|
||||||
// socket,
|
CdkBase.createLogEvent(
|
||||||
// "SILLY",
|
socket,
|
||||||
// `soapClientVehicleInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
"SILLY",
|
||||||
// );
|
`soapClientCustomerInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
||||||
// CdkBase.createXmlEvent(socket, rawResponse, `soapClientVehicleInsertUpdate.readAsync response.`);
|
);
|
||||||
// CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||||
// const VehicleFromDMS = result && result.return && result.return.vehicle;
|
const CustomersFromDms = result && result.return && result.return.customerParty;
|
||||||
// return VehicleFromDMS;
|
return CustomersFromDms;
|
||||||
// } catch (error) {
|
} catch (error) {
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `Error in QueryDmsVehicleById - ${error}`);
|
CdkBase.createXmlEvent(socket, error.request, `soapClientCustomerInsertUpdate.readAsync request.`, true);
|
||||||
// throw new Error(error);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async function QueryDmsCustomerById(socket, JobData, CustomerId) {
|
CdkBase.createXmlEvent(
|
||||||
// try {
|
socket,
|
||||||
// const soapClientCustomerInsertUpdate = await soap.createClientAsync(CdkWsdl.CustomerInsertUpdate);
|
error.response && error.response.data,
|
||||||
// const soapResponseCustomerInsertUpdate = await soapClientCustomerInsertUpdate.readAsync({
|
`soapClientCustomerInsertUpdate.readAsync response.`,
|
||||||
// arg0: CDK_CREDENTIALS,
|
true
|
||||||
// arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
);
|
||||||
// arg2: {
|
|
||||||
// // userId: CustomerId,
|
|
||||||
// },
|
|
||||||
// arg3: CustomerId
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const [result, rawResponse, , rawRequest] = soapResponseCustomerInsertUpdate;
|
CdkBase.createLogEvent(socket, "ERROR", `Error in QueryDmsCustomerById - ${error}`);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(socket, rawRequest, `soapClientCustomerInsertUpdate.readAsync request.`);
|
async function QueryDmsCustomerByName({ socket, redisHelpers, JobData }) {
|
||||||
|
const ownerName =
|
||||||
|
JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== ""
|
||||||
|
? [["lastName", JobData.ownr_co_nm.replace(replaceSpecialRegex, "")]]
|
||||||
|
: [["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")], ["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")]];
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerInsertUpdate.readAsync response.`);
|
CreateFortellisLogEvent(
|
||||||
// CdkBase.createLogEvent(
|
socket,
|
||||||
// socket,
|
"DEBUG",
|
||||||
// "SILLY",
|
`Begin query DMS Customer by Name using ${JSON.stringify(ownerName)}`
|
||||||
// `soapClientCustomerInsertUpdate.readAsync Result ${JSON.stringify(result, null, 2)}`
|
);
|
||||||
// );
|
|
||||||
// CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
|
||||||
// const CustomersFromDms = result && result.return && result.return.customerParty;
|
|
||||||
// return CustomersFromDms;
|
|
||||||
// } catch (error) {
|
|
||||||
// CdkBase.createXmlEvent(socket, error.request, `soapClientCustomerInsertUpdate.readAsync request.`, true);
|
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(
|
try {
|
||||||
// socket,
|
const result = await MakeFortellisCall({
|
||||||
// error.response && error.response.data,
|
...FortellisActions.QueryCustomerByName,
|
||||||
// `soapClientCustomerInsertUpdate.readAsync response.`,
|
requestSearchParams: ownerName,
|
||||||
// true
|
headers: {},
|
||||||
// );
|
redisHelpers,
|
||||||
|
socket,
|
||||||
|
jobid: JobData.id,
|
||||||
|
body: {},
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `Error in QueryDmsCustomerById - ${error}`);
|
});
|
||||||
// throw new Error(error);
|
return result.data;
|
||||||
// }
|
} catch (error) {
|
||||||
// }
|
CreateFortellisLogEvent(socket, "ERROR", `Error in QueryDmsCustomerByName - ${error}`, { request: error.request });
|
||||||
|
}
|
||||||
// async function QueryDmsCustomerByName(socket, JobData) {
|
}
|
||||||
// const ownerName = (
|
|
||||||
// JobData.ownr_co_nm && JobData.ownr_co_nm.trim() !== ""
|
|
||||||
// ? JobData.ownr_co_nm
|
|
||||||
// : `${JobData.ownr_ln},${JobData.ownr_fn}`
|
|
||||||
// ).replace(replaceSpecialRegex, "");
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "DEBUG", `Begin Query DMS Customer by Name using: ${ownerName}`);
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// const soapClientCustomerSearch = await soap.createClientAsync(CdkWsdl.CustomerSearch);
|
|
||||||
// const soapResponseCustomerSearch = await soapClientCustomerSearch.executeSearchAsync({
|
|
||||||
// arg0: CDK_CREDENTIALS,
|
|
||||||
// arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
|
||||||
// arg2: {
|
|
||||||
// verb: "EXACT",
|
|
||||||
// key: ownerName
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const [result, rawResponse, , rawRequest] = soapResponseCustomerSearch;
|
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(socket, rawRequest, `soapClientCustomerSearch.executeSearchBulkAsync request.`);
|
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(socket, rawResponse, `soapClientCustomerSearch.executeSearchBulkAsync response.`);
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(
|
|
||||||
// socket,
|
|
||||||
// "SILLY",
|
|
||||||
// `soapClientCustomerSearch.executeSearchBulkAsync Result ${JSON.stringify(result, null, 2)}`
|
|
||||||
// );
|
|
||||||
// CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
|
||||||
// const CustomersFromDms = (result && result.return) || [];
|
|
||||||
// return CustomersFromDms;
|
|
||||||
// } catch (error) {
|
|
||||||
// CdkBase.createXmlEvent(socket, error.request, `soapClientCustomerSearch.executeSearchBulkAsync request.`, true);
|
|
||||||
|
|
||||||
// CdkBase.createXmlEvent(
|
|
||||||
// socket,
|
|
||||||
// error.response && error.response.data,
|
|
||||||
// `soapClientCustomerSearch.executeSearchBulkAsync response.`,
|
|
||||||
// true
|
|
||||||
// );
|
|
||||||
|
|
||||||
// CdkBase.createLogEvent(socket, "ERROR", `Error in QueryDmsCustomerByName - ${error}`);
|
|
||||||
// throw new Error(error);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// async function GenerateDmsCustomerNumber(socket) {
|
// async function GenerateDmsCustomerNumber(socket) {
|
||||||
// try {
|
// try {
|
||||||
|
|||||||
Reference in New Issue
Block a user