From 124d68ef68c22a5dd7b263bf7843b69b8a0d0e86 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 10 Aug 2021 08:40:38 -0700 Subject: [PATCH] IO-233 CDK Shop Config --- bodyshop_translations.babel | 94 + .../jobs-admin-delete-intake.component.jsx | 2 +- .../shop-info/shop-info.component.jsx | 14 +- ...p-info.responsibilitycenters.component.jsx | 2771 ++++++++++++----- client/src/graphql/bodyshop.queries.js | 2 + client/src/translations/en_us/common.json | 8 + client/src/translations/es/common.json | 8 + client/src/translations/fr/common.json | 8 + .../down.yaml | 5 + .../up.yaml | 5 + .../down.yaml | 89 + .../up.yaml | 90 + .../down.yaml | 81 + .../up.yaml | 82 + hasura/migrations/metadata.yaml | 2 + package.json | 1 + server.js | 6 +- server/accounting/qbxml/qbxml-payables.js | 11 +- server/accounting/qbxml/qbxml-payments.js | 12 +- server/accounting/qbxml/qbxml-receivables.js | 21 +- server/cdk/cdk-job-export.js | 3 +- server/utils/logger.js | 25 + server/web-sockets/web-socket.js | 11 +- yarn.lock | 5 + 24 files changed, 2540 insertions(+), 816 deletions(-) create mode 100644 hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/down.yaml create mode 100644 hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/up.yaml create mode 100644 hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/down.yaml create mode 100644 hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/up.yaml create mode 100644 hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/down.yaml create mode 100644 hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/up.yaml create mode 100644 server/utils/logger.js diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index dbee40f32..bf66fd21d 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -3575,6 +3575,53 @@ + + dms + + + dms_acctnumber + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + dms_wip_acctnumber + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + email false @@ -7458,6 +7505,53 @@ + + dms + + + cdk_dealerid + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + title + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + employees false diff --git a/client/src/components/jobs-admin-delete-intake/jobs-admin-delete-intake.component.jsx b/client/src/components/jobs-admin-delete-intake/jobs-admin-delete-intake.component.jsx index db96f74ef..6b740c7a8 100644 --- a/client/src/components/jobs-admin-delete-intake/jobs-admin-delete-intake.component.jsx +++ b/client/src/components/jobs-admin-delete-intake/jobs-admin-delete-intake.component.jsx @@ -22,7 +22,7 @@ export default function JobAdminDeleteIntake({ job }) { mutation DELETE_DELIVERY($jobId: uuid!) { update_jobs_by_pk( pk_columns: { id: $jobId } - _set: { deliverychecklist: null } + _set: { deliverchecklist: null } ) { id deliverychecklist diff --git a/client/src/components/shop-info/shop-info.component.jsx b/client/src/components/shop-info/shop-info.component.jsx index da993d9c7..df6410e6c 100644 --- a/client/src/components/shop-info/shop-info.component.jsx +++ b/client/src/components/shop-info/shop-info.component.jsx @@ -1,6 +1,9 @@ import { Button, Card, Tabs } from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { selectBodyshop } from "../../redux/user/user.selectors"; import ShopInfoGeneral from "./shop-info.general.component"; import ShopInfoIntakeChecklistComponent from "./shop-info.intake.component"; import ShopInfoLaborRates from "./shop-info.laborrates.component"; @@ -11,7 +14,15 @@ import ShopInfoROStatusComponent from "./shop-info.rostatus.component"; import ShopInfoSchedulingComponent from "./shop-info.scheduling.component"; import ShopInfoSpeedPrint from "./shop-info.speedprint.component"; -export default function ShopInfoComponent({ form, saveLoading }) { +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect(mapStateToProps, mapDispatchToProps)(ShopInfoComponent); + +export function ShopInfoComponent({ bodyshop, form, saveLoading }) { const { t } = useTranslation(); return ( + diff --git a/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx b/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx index e4763d65a..b9201fcef 100644 --- a/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx +++ b/client/src/components/shop-info/shop-info.responsibilitycenters.component.jsx @@ -12,6 +12,10 @@ import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import styled from "styled-components"; import LayoutFormRow from "../layout-form-row/layout-form-row.component"; +import DataLabel from "../data-label/data-label.component"; +import { selectBodyshop } from "../../redux/user/user.selectors"; +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; const SelectorDiv = styled.div` .ant-form-item .ant-select { @@ -19,14 +23,26 @@ const SelectorDiv = styled.div` } `; -export default function ShopInfoResponsibilityCenterComponent({ form }) { +const mapStateToProps = createStructuredSelector({ + //currentUser: selectCurrentUser + bodyshop: selectBodyshop, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); +export default connect( + mapStateToProps, + mapDispatchToProps +)(ShopInfoResponsibilityCenterComponent); + +export function ShopInfoResponsibilityCenterComponent({ bodyshop, form }) { const { t } = useTranslation(); const [costOptions, setCostOptions] = useState( [ ...(form .getFieldValue(["md_responsibility_centers", "costs"]) - .map((i) => i.name) || []), + .map((i) => i && i.name) || []), ] || [] ); @@ -34,7 +50,7 @@ export default function ShopInfoResponsibilityCenterComponent({ form }) { [ ...(form .getFieldValue(["md_responsibility_centers", "profits"]) - .map((i) => i.name) || []), + .map((i) => i && i.name) || []), ] || [] ); @@ -42,17 +58,20 @@ export default function ShopInfoResponsibilityCenterComponent({ form }) { setCostOptions([ ...(form .getFieldValue(["md_responsibility_centers", "costs"]) - .map((i) => i.name) || []), + .map((i) => i && i.name) || []), ]); setProfitOptions([ ...(form .getFieldValue(["md_responsibility_centers", "profits"]) - .map((i) => i.name) || []), + .map((i) => i && i.name) || []), ]); }; return (
+ + {form.getFieldValue("cdk_dealerid")} + {(fields, { add, remove }) => { @@ -134,6 +153,36 @@ export default function ShopInfoResponsibilityCenterComponent({ form }) { > */} + + {bodyshop.cdk_dealerid && ( + + + + )} + {bodyshop.cdk_dealerid && ( + + + + )} + { remove(field.name); @@ -242,6 +291,20 @@ export default function ShopInfoResponsibilityCenterComponent({ form }) { > + {bodyshop.cdk_dealerid && ( + + + + )} { remove(field.name); @@ -268,804 +331,1910 @@ export default function ShopInfoResponsibilityCenterComponent({ form }) { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + {bodyshop.cdk_dealerid && ( + <> + + {(fields, { add, remove }) => { + return ( +
+ {fields.map((field, index) => ( + +
+ + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + remove(field.name); + }} + /> +
+
+ ))} + + + +
+ ); + }} +
+ + )} + + {!bodyshop.cdk_dealerid && ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + )}
+ diff --git a/client/src/graphql/bodyshop.queries.js b/client/src/graphql/bodyshop.queries.js index 947fe64dc..b1e783bf4 100644 --- a/client/src/graphql/bodyshop.queries.js +++ b/client/src/graphql/bodyshop.queries.js @@ -93,6 +93,7 @@ export const QUERY_BODYSHOP = gql` features attach_pdf_to_email tt_allow_post_to_invoiced + cdk_configuration employees { id active @@ -182,6 +183,7 @@ export const UPDATE_SHOP = gql` cdk_dealerid attach_pdf_to_email tt_allow_post_to_invoiced + cdk_configuration employees { id first_name diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 3237e9e05..4e4b642bd 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -231,6 +231,10 @@ "deliver": { "templates": "Delivery Templates" }, + "dms": { + "dms_acctnumber": "DMS Account #", + "dms_wip_acctnumber": "DMS W.I.P. Account #" + }, "email": "General Shop Email", "enforce_class": "Enforce Class on Conversion?", "enforce_referral": "Enforce Referrals", @@ -467,6 +471,10 @@ "defaultcostsmapping": "Default Costs Mapping", "defaultprofitsmapping": "Default Profits Mapping", "deliverchecklist": "Delivery Checklist", + "dms": { + "cdk_dealerid": "CDK Dealer ID", + "title": "DMS" + }, "employees": "Employees", "insurancecos": "Insurance Companies", "intakechecklist": "Intake Checklist", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index f9643a466..c3a08870a 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -231,6 +231,10 @@ "deliver": { "templates": "" }, + "dms": { + "dms_acctnumber": "", + "dms_wip_acctnumber": "" + }, "email": "", "enforce_class": "", "enforce_referral": "", @@ -467,6 +471,10 @@ "defaultcostsmapping": "", "defaultprofitsmapping": "", "deliverchecklist": "", + "dms": { + "cdk_dealerid": "", + "title": "" + }, "employees": "", "insurancecos": "", "intakechecklist": "", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 1dd7c1d32..b6baf0b16 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -231,6 +231,10 @@ "deliver": { "templates": "" }, + "dms": { + "dms_acctnumber": "", + "dms_wip_acctnumber": "" + }, "email": "", "enforce_class": "", "enforce_referral": "", @@ -467,6 +471,10 @@ "defaultcostsmapping": "", "defaultprofitsmapping": "", "deliverchecklist": "", + "dms": { + "cdk_dealerid": "", + "title": "" + }, "employees": "", "insurancecos": "", "intakechecklist": "", diff --git a/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/down.yaml b/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/down.yaml new file mode 100644 index 000000000..be5ebedd7 --- /dev/null +++ b/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/down.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "cdk_configuration"; + type: run_sql diff --git a/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/up.yaml b/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/up.yaml new file mode 100644 index 000000000..dc6dcd3a8 --- /dev/null +++ b/hasura/migrations/1628544240019_alter_table_public_bodyshops_add_column_cdk_configuration/up.yaml @@ -0,0 +1,5 @@ +- args: + cascade: false + read_only: false + sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "cdk_configuration" jsonb NULL; + type: run_sql diff --git a/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/down.yaml b/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/down.yaml new file mode 100644 index 000000000..69267f8fa --- /dev/null +++ b/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/down.yaml @@ -0,0 +1,89 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - accountingconfig + - address1 + - address2 + - appt_alt_transport + - appt_colors + - appt_length + - attach_pdf_to_email + - bill_tax_rates + - cdk_dealerid + - city + - country + - created_at + - default_adjustment_rate + - deliverchecklist + - email + - enforce_class + - enforce_referral + - features + - federal_tax_id + - id + - imexshopid + - inhousevendorid + - insurance_vendor_id + - intakechecklist + - jc_hourly_rates + - jobsizelimit + - logo_img_path + - md_categories + - md_ccc_rates + - md_classes + - md_hour_split + - md_ins_cos + - md_jobline_presets + - md_labor_rates + - md_messaging_presets + - md_notes_presets + - md_order_statuses + - md_parts_locations + - md_payment_types + - md_rbac + - md_referral_sources + - md_responsibility_centers + - md_ro_statuses + - messagingservicesid + - phone + - prodtargethrs + - production_config + - region_config + - schedule_end_time + - schedule_start_time + - scoreboard_target + - shopname + - shoprates + - speedprint + - ssbuckets + - state + - state_tax_id + - stripe_acct_id + - sub_status + - target_touchtime + - template_header + - textid + - tt_allow_post_to_invoiced + - updated_at + - use_fippa + - website + - workingdays + - zip_post + computed_fields: [] + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: bodyshops + schema: public + type: create_select_permission diff --git a/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/up.yaml b/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/up.yaml new file mode 100644 index 000000000..7fa7fe055 --- /dev/null +++ b/hasura/migrations/1628544252299_update_permission_user_public_table_bodyshops/up.yaml @@ -0,0 +1,90 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - accountingconfig + - address1 + - address2 + - appt_alt_transport + - appt_colors + - appt_length + - attach_pdf_to_email + - bill_tax_rates + - cdk_configuration + - cdk_dealerid + - city + - country + - created_at + - default_adjustment_rate + - deliverchecklist + - email + - enforce_class + - enforce_referral + - features + - federal_tax_id + - id + - imexshopid + - inhousevendorid + - insurance_vendor_id + - intakechecklist + - jc_hourly_rates + - jobsizelimit + - logo_img_path + - md_categories + - md_ccc_rates + - md_classes + - md_hour_split + - md_ins_cos + - md_jobline_presets + - md_labor_rates + - md_messaging_presets + - md_notes_presets + - md_order_statuses + - md_parts_locations + - md_payment_types + - md_rbac + - md_referral_sources + - md_responsibility_centers + - md_ro_statuses + - messagingservicesid + - phone + - prodtargethrs + - production_config + - region_config + - schedule_end_time + - schedule_start_time + - scoreboard_target + - shopname + - shoprates + - speedprint + - ssbuckets + - state + - state_tax_id + - stripe_acct_id + - sub_status + - target_touchtime + - template_header + - textid + - tt_allow_post_to_invoiced + - updated_at + - use_fippa + - website + - workingdays + - zip_post + computed_fields: [] + filter: + associations: + user: + authid: + _eq: X-Hasura-User-Id + role: user + table: + name: bodyshops + schema: public + type: create_select_permission diff --git a/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/down.yaml b/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/down.yaml new file mode 100644 index 000000000..410a953e4 --- /dev/null +++ b/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/down.yaml @@ -0,0 +1,81 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_update_permission +- args: + permission: + columns: + - accountingconfig + - address1 + - address2 + - appt_alt_transport + - appt_colors + - appt_length + - attach_pdf_to_email + - bill_tax_rates + - city + - country + - created_at + - default_adjustment_rate + - deliverchecklist + - email + - enforce_class + - enforce_referral + - federal_tax_id + - id + - inhousevendorid + - insurance_vendor_id + - intakechecklist + - jc_hourly_rates + - logo_img_path + - md_categories + - md_ccc_rates + - md_classes + - md_hour_split + - md_ins_cos + - md_jobline_presets + - md_labor_rates + - md_messaging_presets + - md_notes_presets + - md_order_statuses + - md_parts_locations + - md_payment_types + - md_rbac + - md_referral_sources + - md_responsibility_centers + - md_ro_statuses + - phone + - prodtargethrs + - production_config + - schedule_end_time + - schedule_start_time + - scoreboard_target + - shopname + - shoprates + - speedprint + - ssbuckets + - state + - state_tax_id + - target_touchtime + - tt_allow_post_to_invoiced + - updated_at + - use_fippa + - website + - workingdays + - zip_post + filter: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: bodyshops + schema: public + type: create_update_permission diff --git a/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/up.yaml b/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/up.yaml new file mode 100644 index 000000000..1b2d4d09f --- /dev/null +++ b/hasura/migrations/1628544261316_update_permission_user_public_table_bodyshops/up.yaml @@ -0,0 +1,82 @@ +- args: + role: user + table: + name: bodyshops + schema: public + type: drop_update_permission +- args: + permission: + columns: + - accountingconfig + - address1 + - address2 + - appt_alt_transport + - appt_colors + - appt_length + - attach_pdf_to_email + - bill_tax_rates + - cdk_configuration + - city + - country + - created_at + - default_adjustment_rate + - deliverchecklist + - email + - enforce_class + - enforce_referral + - federal_tax_id + - id + - inhousevendorid + - insurance_vendor_id + - intakechecklist + - jc_hourly_rates + - logo_img_path + - md_categories + - md_ccc_rates + - md_classes + - md_hour_split + - md_ins_cos + - md_jobline_presets + - md_labor_rates + - md_messaging_presets + - md_notes_presets + - md_order_statuses + - md_parts_locations + - md_payment_types + - md_rbac + - md_referral_sources + - md_responsibility_centers + - md_ro_statuses + - phone + - prodtargethrs + - production_config + - schedule_end_time + - schedule_start_time + - scoreboard_target + - shopname + - shoprates + - speedprint + - ssbuckets + - state + - state_tax_id + - target_touchtime + - tt_allow_post_to_invoiced + - updated_at + - use_fippa + - website + - workingdays + - zip_post + filter: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + set: {} + role: user + table: + name: bodyshops + schema: public + type: create_update_permission diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml index 3ec04fbf7..62d9f434a 100644 --- a/hasura/migrations/metadata.yaml +++ b/hasura/migrations/metadata.yaml @@ -796,6 +796,7 @@ tables: - appt_length - attach_pdf_to_email - bill_tax_rates + - cdk_configuration - cdk_dealerid - city - country @@ -873,6 +874,7 @@ tables: - appt_length - attach_pdf_to_email - bill_tax_rates + - cdk_configuration - city - country - created_at diff --git a/package.json b/package.json index 70cd48033..3911ab40a 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "firebase-admin": "^9.11.0", "graphql": "^15.5.1", "graphql-request": "^3.4.0", + "graylog2": "^0.2.1", "inline-css": "^3.0.0", "intuit-oauth": "^4.0.0", "lodash": "^4.17.21", diff --git a/server.js b/server.js index cd4e7e5ba..5b59ec283 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,7 @@ const bodyParser = require("body-parser"); const path = require("path"); const compression = require("compression"); const twilio = require("twilio"); +const logger = require("./server/utils/logger"); global.fetch = require("node-fetch"); var fb = require("./server/firebase/firebase-handler"); @@ -33,7 +34,8 @@ app.post("/sendemail", fb.validateFirebaseIdToken, sendEmail.sendEmail); //Test route to ensure Express is responding. app.get("/test", async function (req, res) { - console.log("Incoming request verified.", req); + logger.log("test-api", null, null, null); + const Commit = require("child_process").execSync( "git rev-parse --short HEAD" ); @@ -166,7 +168,7 @@ const io = new Server(server, { server.listen(port, (error) => { if (error) throw error; - console.log(`[${process.env.NODE_ENV}] Server running on port ${port}`); + logger.log(`[${process.env.NODE_ENV}] Server running on port ${port}`); }); exports.io = io; require("./server/web-sockets/web-socket"); diff --git a/server/accounting/qbxml/qbxml-payables.js b/server/accounting/qbxml/qbxml-payables.js index d1685ffeb..b864f4e28 100644 --- a/server/accounting/qbxml/qbxml-payables.js +++ b/server/accounting/qbxml/qbxml-payables.js @@ -6,6 +6,7 @@ const Dinero = require("dinero.js"); var builder = require("xmlbuilder2"); const QbXmlUtils = require("./qbxml-utils"); const moment = require("moment"); +const logger = require("../../utils/logger"); require("dotenv").config({ path: path.resolve( @@ -45,7 +46,13 @@ exports.default = async (req, res) => { res.status(200).json(QbXmlToExecute); } catch (error) { - console.log("error", error); + logger.log( + "qbxml-payable-error", + "error", + req.body.user, + req.body.billsToQuery, + error + ); res.status(400).send(JSON.stringify(error)); } }; @@ -89,7 +96,6 @@ const generateBill = (bill) => { .end({ pretty: true }); const billQbxml_Full = QbXmlUtils.addQbxmlHeader(billQbxml_partial); - console.log("generateBill -> billQbxml_Full", billQbxml_Full); return billQbxml_Full; }; @@ -131,7 +137,6 @@ const findTaxCode = (billLine, taxcode) => { !!t.federal === !!federal ); if (t.length === 1) { - console.log(t); return t[0].code; } else if (t.length > 1) { return "Multiple Tax Codes Match"; diff --git a/server/accounting/qbxml/qbxml-payments.js b/server/accounting/qbxml/qbxml-payments.js index 9d7c8b852..264554dcb 100644 --- a/server/accounting/qbxml/qbxml-payments.js +++ b/server/accounting/qbxml/qbxml-payments.js @@ -7,6 +7,8 @@ var builder = require("xmlbuilder2"); const moment = require("moment"); const QbXmlUtils = require("./qbxml-utils"); const QbxmlReceivables = require("./qbxml-receivables"); +const logger = require("../../utils/logger"); + require("dotenv").config({ path: path.resolve( process.cwd(), @@ -80,13 +82,18 @@ exports.default = async (req, res) => { res.status(200).json(QbXmlToExecute); } catch (error) { - console.log("error", error); + logger.log( + "qbxml-payments-error", + "error", + req.body.user, + req.body.paymentsToQuery, + error + ); res.status(400).send(JSON.stringify(error)); } }; const generatePayment = (payment, isThreeTier, twoTierPref) => { - console.log("generatePayment -> payment", payment); let paymentQbxmlObj; if (payment.amount > 0) { paymentQbxmlObj = { @@ -194,7 +201,6 @@ const generatePayment = (payment, isThreeTier, twoTierPref) => { .end({ pretty: true }); const paymentQbxmlFull = QbXmlUtils.addQbxmlHeader(paymentQbxmlPartial); - console.log("generateBill -> paymentQbxmlFull", paymentQbxmlFull); return paymentQbxmlFull; }; diff --git a/server/accounting/qbxml/qbxml-receivables.js b/server/accounting/qbxml/qbxml-receivables.js index aeb948ed9..82a32da51 100644 --- a/server/accounting/qbxml/qbxml-receivables.js +++ b/server/accounting/qbxml/qbxml-receivables.js @@ -6,6 +6,8 @@ const Dinero = require("dinero.js"); const moment = require("moment"); var builder = require("xmlbuilder2"); const QbXmlUtils = require("./qbxml-utils"); +const logger = require("../../utils/logger"); + require("dotenv").config({ path: path.resolve( process.cwd(), @@ -93,7 +95,13 @@ exports.default = async (req, res) => { res.status(200).json(QbXmlToExecute); } catch (error) { - console.log("error", error); + logger.log( + "qbxml-payments-error", + "error", + req.body.user, + req.body.jobIds, + error + ); res.status(400).send(JSON.stringify(error)); } }; @@ -220,7 +228,7 @@ const generateInvoiceQbxml = ( }).multiply(jobline.part_qty || 1); if (jobline.prt_dsmk_p && jobline.prt_dsmk_p !== 0) { - console.log("Have a part discount", jobline); + // console.log("Have a part discount", jobline); DineroAmount = DineroAmount.add( DineroAmount.percentage(jobline.prt_dsmk_p || 0) ); @@ -230,6 +238,13 @@ const generateInvoiceQbxml = ( ); if (!account) { + logger.log( + "qbxml-receivables-no-account", + "warn", + null, + jobline.id, + null + ); throw new Error( `A matching account does not exist for the part allocation. Center: ${jobline.profitcenter_part}` ); @@ -309,7 +324,7 @@ const generateInvoiceQbxml = ( }, }); } else { - console.log("NO MAPA ACCOUNT FOUND!!"); + //console.log("NO MAPA ACCOUNT FOUND!!"); } } diff --git a/server/cdk/cdk-job-export.js b/server/cdk/cdk-job-export.js index f4e7ee993..a14fd783f 100644 --- a/server/cdk/cdk-job-export.js +++ b/server/cdk/cdk-job-export.js @@ -10,12 +10,14 @@ const soap = require("soap"); const queries = require("../graphql-client/queries"); const CdkBase = require("../web-sockets/web-socket"); const CdkWsdl = require("./cdk-wsdl").default; +const logger = require("../utils/logger"); const IMEX_CDK_USER = process.env.IMEX_CDK_USER, IMEX_CDK_PASSWORD = process.env.IMEX_CDK_PASSWORD; exports.default = async function (socket, jobid) { socket.logEvents = []; + socket.recordid = jobid; try { CdkBase.createLogEvent( socket, @@ -24,7 +26,6 @@ exports.default = async function (socket, jobid) { ); const JobData = await QueryJobData(socket, jobid); - console.log(JSON.stringify(JobData, null, 2)); const DealerId = JobData.bodyshop.cdk_dealerid; CdkBase.createLogEvent( diff --git a/server/utils/logger.js b/server/utils/logger.js new file mode 100644 index 000000000..e3c8c99a8 --- /dev/null +++ b/server/utils/logger.js @@ -0,0 +1,25 @@ +const graylog2 = require("graylog2"); + +const logger = new graylog2.graylog({ + servers: [{ host: "logs.bodyshop.app", port: 12201 }], +}); + +function log(message, type, user, record, object) { + console.log(message, { + type, + env: process.env.NODE_ENV, + user, + record, + ...object, + }); + logger.log(message, { + type, + env: process.env.NODE_ENV || "development", + user, + record, + ...object, + }); +} + +module.exports = { log }; +//const logger = require("./server/utils/logger"); diff --git a/server/web-sockets/web-socket.js b/server/web-sockets/web-socket.js index e3a909889..eb6ffff2a 100644 --- a/server/web-sockets/web-socket.js +++ b/server/web-sockets/web-socket.js @@ -11,6 +11,7 @@ const { io } = require("../../server"); const { admin } = require("../firebase/firebase-handler"); const CdkJobExport = require("../cdk/cdk-job-export").default; const { isArray } = require("lodash"); +const logger = require("../utils/logger"); io.use(function (socket, next) { try { @@ -30,6 +31,10 @@ io.use(function (socket, next) { } } catch (error) { console.log("Uncaught connection error:::", error); + logger.log("websocket-connection-error", "error", null, null, { + token: socket.handshake.auth.token, + ...error, + }); next(new Error(`Authentication error ${error}`)); } }); @@ -55,7 +60,7 @@ io.on("connection", (socket) => { function createLogEvent(socket, level, message) { if (LogLevelHierarchy(socket.log_level) >= LogLevelHierarchy(level)) { console.log( - `[CDK LOG EVENT] ${level} - ${new Date()} - ${socket.user.email} - ${ + `[WS LOG EVENT] ${level} - ${new Date()} - ${socket.user.email} - ${ socket.id } - ${message}` ); @@ -65,6 +70,10 @@ function createLogEvent(socket, level, message) { message, }); + logger.log("ws-log-event", level, socket.user.email, socket.recordid, { + wsmessage: message, + }); + if (socket.logEvents && isArray(socket.logEvents)) { socket.logEvents.push({ timestamp: new Date(), diff --git a/yarn.lock b/yarn.lock index 1f7042173..430c63b5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1901,6 +1901,11 @@ graphql@^15.5.1: resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.5.1.tgz#f2f84415d8985e7b84731e7f3536f8bb9d383aad" integrity sha512-FeTRX67T3LoE3LWAxxOlW2K3Bz+rMYAC18rRguK4wgXaTZMiJwSUwDmPFo3UadAKbzirKIg5Qy+sNJXbpPRnQw== +graylog2@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/graylog2/-/graylog2-0.2.1.tgz#fcb0775766fb6d7d6f5fef3ff873326b8b1d35a9" + integrity sha512-vjysakwOhrAqMeIvSK0WZcmzKvkpxY6pCfT9QqtdSVAidPFIynuin7adqbdFp9MCCTbTE402WIxvg8cph5OWTA== + gtoken@^5.0.4: version "5.2.1" resolved "https://registry.yarnpkg.com/gtoken/-/gtoken-5.2.1.tgz#4dae1fea17270f457954b4a45234bba5fc796d16"