feature/IO-3638-Reynolds-OpenSearch - Add Search on DMS id in Reynolds shops
This commit is contained in:
@@ -4,6 +4,7 @@ const queries = require("../graphql-client/queries");
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const { pick, isNil } = require("lodash");
|
||||
const { getClient } = require("../../libs/awsUtils");
|
||||
const { JOB_DOCUMENT_FIELDS, getGlobalSearchQueryStringFields } = require("./os-search-config");
|
||||
|
||||
async function OpenSearchUpdateHandler(req, res) {
|
||||
try {
|
||||
@@ -21,27 +22,7 @@ async function OpenSearchUpdateHandler(req, res) {
|
||||
|
||||
switch (req.body.table.name) {
|
||||
case "jobs":
|
||||
document = pick(req.body.event.data.new, [
|
||||
"id",
|
||||
"bodyshopid",
|
||||
"clm_no",
|
||||
"clm_total",
|
||||
"comment",
|
||||
"ins_co_nm",
|
||||
"owner_owing",
|
||||
"ownr_co_nm",
|
||||
"ownr_fn",
|
||||
"ownr_ln",
|
||||
"ownr_ph1",
|
||||
"ownr_ph2",
|
||||
"plate_no",
|
||||
"ro_number",
|
||||
"status",
|
||||
"v_model_yr",
|
||||
"v_make_desc",
|
||||
"v_model_desc",
|
||||
"v_vin"
|
||||
]);
|
||||
document = pick(req.body.event.data.new, JOB_DOCUMENT_FIELDS);
|
||||
document.bodyshopid = req.body.event.data.new.shopid;
|
||||
break;
|
||||
case "vehicles":
|
||||
@@ -197,15 +178,18 @@ async function OpenSearchSearchHandler(req, res) {
|
||||
user: req.user.email
|
||||
});
|
||||
|
||||
if (assocs.length === 0) {
|
||||
if (assocs.associations.length === 0) {
|
||||
res.sendStatus(401);
|
||||
return;
|
||||
}
|
||||
|
||||
const osClient = await getClient();
|
||||
|
||||
const activeAssociation = assocs.associations[0];
|
||||
const bodyShopIdMatchOverride = isNil(process.env.BODY_SHOP_ID_MATCH_OVERRIDE)
|
||||
? assocs.associations[0].shopid
|
||||
? activeAssociation.shopid
|
||||
: process.env.BODY_SHOP_ID_MATCH_OVERRIDE;
|
||||
const isReynoldsEnabled = Boolean(activeAssociation.bodyshop?.rr_dealerid);
|
||||
|
||||
const { body } = await osClient.search({
|
||||
...(index ? { index } : { index: ["jobs", "vehicles", "owners", "bills", "payments"] }),
|
||||
@@ -241,21 +225,8 @@ async function OpenSearchSearchHandler(req, res) {
|
||||
query: `*${search}*`,
|
||||
// Weighted Fields
|
||||
fields: [
|
||||
"*ro_number^20",
|
||||
"*clm_no^14",
|
||||
"*v_vin^12",
|
||||
"*plate_no^12",
|
||||
"*ownr_ln^10",
|
||||
"transactionid^10",
|
||||
"paymentnum^10",
|
||||
"invoice_number^10",
|
||||
"*ownr_fn^8",
|
||||
"*ownr_co_nm^8",
|
||||
"*ownr_ph1^8",
|
||||
"*ownr_ph2^8",
|
||||
"*vendor.name^8",
|
||||
"*comment^6"
|
||||
// "*"
|
||||
...getGlobalSearchQueryStringFields({ isReynoldsEnabled })
|
||||
// "*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user