feat(datamart): new query to check if the city state will be valid to process in tms
This commit is contained in:
21
server/services/dataMart/controller/validateCityState.ts
Normal file
21
server/services/dataMart/controller/validateCityState.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createLog } from "../../logger/logger.js";
|
||||
import { query } from "../../sqlServer/prodSqlServer.js";
|
||||
import { validateCityState } from "../../sqlServer/querys/dataMart/validatecityState.js";
|
||||
|
||||
export const validateCS = async () => {
|
||||
let cs: any = [];
|
||||
|
||||
let updatedQuery = validateCityState;
|
||||
|
||||
try {
|
||||
cs = await query(updatedQuery, "Get address data");
|
||||
return { success: true, message: "City State Data", data: cs.data };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
success: false,
|
||||
message: "There was an error getting city state data.",
|
||||
data: error,
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -6,6 +6,7 @@ import getCustomerInv from "./route/getCustomerInv.js";
|
||||
import getOpenOrders from "./route/getOpenOrders.js";
|
||||
import getDeliveryByDate from "./route/getDeliveryDateByRange.js";
|
||||
import fakeEDI from "./route/fakeEDI.js";
|
||||
import addressCorrections from "./route/getCityStateData.js";
|
||||
|
||||
const app = new OpenAPIHono();
|
||||
|
||||
@@ -17,6 +18,7 @@ const routes = [
|
||||
getOpenOrders,
|
||||
getDeliveryByDate,
|
||||
fakeEDI,
|
||||
addressCorrections,
|
||||
] as const;
|
||||
|
||||
const appRoutes = routes.forEach((route) => {
|
||||
|
||||
50
server/services/dataMart/route/getCityStateData.ts
Normal file
50
server/services/dataMart/route/getCityStateData.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { getINV } from "../controller/getinventory.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { validateCS } from "../controller/validateCityState.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
const Body = z.object({
|
||||
includeRunnningNumbers: z.string().openapi({ example: "x" }),
|
||||
});
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["dataMart"],
|
||||
summary: "Returns Address with incorrect city state.",
|
||||
method: "get",
|
||||
path: "/getaddressdata",
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
"application/json": { schema: Body },
|
||||
},
|
||||
},
|
||||
},
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
// make sure we have a vaid user being accessed thats really logged in
|
||||
apiHit(c, { endpoint: "/getaddressdata" });
|
||||
const { data, error } = await tryCatch(validateCS());
|
||||
|
||||
if (error) {
|
||||
return c.json(
|
||||
{
|
||||
success: false,
|
||||
message: "There was an error getting address data.",
|
||||
data: error,
|
||||
},
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
return c.json({
|
||||
success: data.success,
|
||||
message: data.message,
|
||||
data: data.data,
|
||||
});
|
||||
}
|
||||
);
|
||||
export default app;
|
||||
@@ -95,6 +95,14 @@ const current: any = [
|
||||
"Returns all open orders to correct and resubmit, leaving blank will get everything putting an address only returns the specified address",
|
||||
criteria: "address", // uncomment this out once the improt process can be faster
|
||||
},
|
||||
{
|
||||
name: "Address Corrections",
|
||||
endpoint: "/api/datamart/getaddressdata",
|
||||
// description: "Returns all inventory, by default excludes running numebrs, also excludes inv locations.",
|
||||
description:
|
||||
"Returns all addresses that will not process correctly in tms due to incorrect city state setup.",
|
||||
//criteria: "address", // uncomment this out once the improt process can be faster
|
||||
},
|
||||
];
|
||||
|
||||
app.openapi(
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
export const validateCityState = `
|
||||
select IdAdressen addressID,
|
||||
x.Bezeichnung as name,
|
||||
c.Bezeichnung as deliveryCondition,
|
||||
c.Kurzbezeichnung as Abbreviation,
|
||||
ort as cityState
|
||||
--,*
|
||||
from AlplaPROD_test1.dbo.t_Adressen (nolock) x
|
||||
left join
|
||||
AlplaPROD_test1.[dbo].[T_Lieferkonditionen] (nolock) c
|
||||
on x.IdLieferkondition = c.IdLieferkondition
|
||||
|
||||
WHERE c.Kurzbezeichnung not in ('exw') and ort not like '%,%'
|
||||
`;
|
||||
Reference in New Issue
Block a user