Compare commits
12 Commits
085dc64db9
...
ecb07c7e7c
| Author | SHA1 | Date | |
|---|---|---|---|
| ecb07c7e7c | |||
| dcfa96b710 | |||
| 8c5c9fd244 | |||
| 2ffc3cc242 | |||
| e780a24a8a | |||
| 8b7353d42b | |||
| 4ef0c51ab2 | |||
| c6fe7dbbce | |||
| 9ae324193a | |||
| e8cd5916d0 | |||
| 9c65b8b377 | |||
| 7aa897bcc9 |
@@ -5,6 +5,12 @@ import { useEffect } from "react";
|
|||||||
const fetchSession = async () => {
|
const fetchSession = async () => {
|
||||||
const token = localStorage.getItem("auth_token");
|
const token = localStorage.getItem("auth_token");
|
||||||
|
|
||||||
|
//temp
|
||||||
|
localStorage.removeItem("ally-supports-cache");
|
||||||
|
localStorage.removeItem("auth-storage");
|
||||||
|
localStorage.removeItem("nextauth.message");
|
||||||
|
localStorage.removeItem("prod");
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error("No token found");
|
throw new Error("No token found");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"dev:frontend": "cd frontend && npm run dev",
|
"dev:frontend": "cd frontend && npm run dev",
|
||||||
"dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts",
|
"dev:dbgen": " drizzle-kit generate --config=drizzle-dev.config.ts",
|
||||||
"dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts",
|
"dev:dbmigrate": " drizzle-kit migrate --config=drizzle-dev.config.ts",
|
||||||
"build": "npm run build:server && npm run build:frontend",
|
"build": "npm run build:server && npm run build:frontend && npm run zipServer && npm run dev",
|
||||||
"build:server": "rimraf dist && tsc --build && npm run copy:scripts && xcopy server\\services\\notifications\\utils\\views\\ dist\\server\\services\\notifications\\utils\\views\\ /E /I /Y",
|
"build:server": "rimraf dist && tsc --build && npm run copy:scripts && xcopy server\\services\\notifications\\utils\\views\\ dist\\server\\services\\notifications\\utils\\views\\ /E /I /Y",
|
||||||
"build:frontend": "cd frontend && npm run build",
|
"build:frontend": "cd frontend && npm run build",
|
||||||
"copy:scripts": "tsx server/scripts/copyScripts.ts",
|
"copy:scripts": "tsx server/scripts/copyScripts.ts",
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admConfig": {
|
"admConfig": {
|
||||||
"build": 253,
|
"build": 260,
|
||||||
"oldBuild": "backend-0.1.3.zip"
|
"oldBuild": "backend-0.1.3.zip"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ param (
|
|||||||
[string]$serviceName,
|
[string]$serviceName,
|
||||||
[string]$option,
|
[string]$option,
|
||||||
[string]$appPath,
|
[string]$appPath,
|
||||||
[string]$command, # just the command like run startadm or what ever you have in npm.
|
[string]$command, # just the command like run start or what ever you have in npm.
|
||||||
[string]$description
|
[string]$description,
|
||||||
[string]$remote
|
[string]$remote
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,16 +11,6 @@ param (
|
|||||||
# .\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
# .\services.ps1 -serviceName "LSTV2" -option "install" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
||||||
|
|
||||||
|
|
||||||
### the fix
|
|
||||||
# .\services.ps1 -serviceName "LST-App" -option "delete" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
|
||||||
# .\services.ps1 -serviceName "LST-frontend" -option "delete" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
|
||||||
# .\services.ps1 -serviceName "LST-System" -option "delete" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
|
||||||
# .\services.ps1 -serviceName "LST-Gateway" -option "delete" -appPath "E:\LST\lstV2" -description "Logistics Support Tool V2" -command "run start"
|
|
||||||
|
|
||||||
# .\services.ps1 -serviceName "LST-App" -option "install" -appPath "E:\LST\lst_backend" -description "Logistics Support Tool V2" -command "run startapp"
|
|
||||||
# .\services.ps1 -serviceName "LST-frontend" -option "install" -appPath "E:\LST\lst_backend" -description "Logistics Support Tool V2" -command "run startfront"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$nssmPath = $AppPath + "\nssm.exe"
|
$nssmPath = $AppPath + "\nssm.exe"
|
||||||
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
$npmPath = "C:\Program Files\nodejs\npm.cmd" # Path to npm.cmd
|
||||||
@@ -74,6 +64,30 @@ if ($option -eq "delete"){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($option -eq "prodStop"){
|
||||||
|
if(-not $appPath){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath stop $serviceName
|
||||||
|
write-host "Removing $($serviceName)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $serviceName start= disabled
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($option -eq "prodStart"){
|
||||||
|
if(-not $appPath){
|
||||||
|
Write-host "The path to the app is missing please add it in and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
& $nssmPath start $serviceName
|
||||||
|
write-host "Removing $($serviceName)"
|
||||||
|
#& $nssmPath remove $serviceName confirm
|
||||||
|
sc.exe config $serviceName start= auto
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if($option -eq "install"){
|
if($option -eq "install"){
|
||||||
if(-not $appPath -or -not $description -or -not $command){
|
if(-not $appPath -or -not $description -or -not $command){
|
||||||
Write-host "Please check all parameters are passed to install the app.."
|
Write-host "Please check all parameters are passed to install the app.."
|
||||||
|
|||||||
@@ -119,29 +119,29 @@ $plantFunness = {
|
|||||||
exit 1 # Exit with a non-zero code if there's an error
|
exit 1 # Exit with a non-zero code if there's an error
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "-----------------------Dealing with LSTv1 Stuff ------------------------------------"
|
# Write-Host "-----------------------Dealing with LSTv1 Stuff ------------------------------------"
|
||||||
try {
|
# try {
|
||||||
# Expand the archive
|
# # Expand the archive
|
||||||
Expand-Archive -Path "$($localPath)\$($obsBuild)" -DestinationPath $obslst -Force
|
# Expand-Archive -Path "$($localPath)\$($obsBuild)" -DestinationPath $obslst -Force
|
||||||
|
|
||||||
# Delete the zip file after extraction
|
# # Delete the zip file after extraction
|
||||||
Write-Host "Deleting the zip file..."
|
# Write-Host "Deleting the zip file..."
|
||||||
Remove-Item -Path "$($localPath)\$($obsBuild)" -Force
|
# Remove-Item -Path "$($localPath)\$($obsBuild)" -Force
|
||||||
} catch {
|
# } catch {
|
||||||
Write-Host "Error: $_"
|
# Write-Host "Error: $_"
|
||||||
exit 1 # Exit with a non-zero code if there's an error
|
# exit 1 # Exit with a non-zero code if there's an error
|
||||||
}
|
# }
|
||||||
|
|
||||||
# for iowa 2 need to change the port config on the start up of nextjs server
|
# # for iowa 2 need to change the port config on the start up of nextjs server
|
||||||
if($token -eq "usiow2"){
|
# if($token -eq "usiow2"){
|
||||||
$jsonPkgloc = "$($obslst)\apps\frontend\package.json"
|
# $jsonPkgloc = "$($obslst)\apps\frontend\package.json"
|
||||||
#read the file
|
# #read the file
|
||||||
$jsonContent = Get-Content -Path $jsonPkgloc | ConvertFrom-Json
|
# $jsonContent = Get-Content -Path $jsonPkgloc | ConvertFrom-Json
|
||||||
#change the second we want to update
|
# #change the second we want to update
|
||||||
$jsonContent.scripts.start = "next start -p 3001"
|
# $jsonContent.scripts.start = "next start -p 3001"
|
||||||
# convert back to json
|
# # convert back to json
|
||||||
$jsonContent | ConvertTo-Json | Set-Content -Path $jsonPkgloc
|
# $jsonContent | ConvertTo-Json | Set-Content -Path $jsonPkgloc
|
||||||
}
|
# }
|
||||||
|
|
||||||
############################################################################
|
############################################################################
|
||||||
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
Write-Host "Stopping the services to do the updates, pkgs and db changes."
|
||||||
@@ -426,15 +426,15 @@ try {
|
|||||||
# Write-Host "Starting $($serviceGateway)"
|
# Write-Host "Starting $($serviceGateway)"
|
||||||
# Start-Service -DisplayName $serviceGateway
|
# Start-Service -DisplayName $serviceGateway
|
||||||
# Start-Sleep -Seconds 1
|
# Start-Sleep -Seconds 1
|
||||||
#Write-Host "Starting $($serviceAuth)"
|
# Write-Host "Starting $($serviceAuth)"
|
||||||
#Start-Service -DisplayName $serviceAuth
|
# Start-Service -DisplayName $serviceAuth
|
||||||
#Start-Sleep -Seconds 1
|
# Start-Sleep -Seconds 1
|
||||||
Write-Host "Starting $($serviceApp)"
|
# Write-Host "Starting $($serviceApp)"
|
||||||
Start-Service -DisplayName $serviceApp
|
# Start-Service -DisplayName $serviceApp
|
||||||
Start-Sleep -Seconds 1
|
# Start-Sleep -Seconds 1
|
||||||
Write-Host "Starting $($serviceFrontEnd)"
|
# Write-Host "Starting $($serviceFrontEnd)"
|
||||||
Start-Service -DisplayName $serviceFrontEnd
|
# Start-Service -DisplayName $serviceFrontEnd
|
||||||
Start-Sleep -Seconds 1
|
# Start-Sleep -Seconds 1
|
||||||
Write-Host "Starting $( $serviceLstV2)"
|
Write-Host "Starting $( $serviceLstV2)"
|
||||||
Start-Service -DisplayName $serviceLstV2
|
Start-Service -DisplayName $serviceLstV2
|
||||||
Start-Sleep -Seconds 1
|
Start-Sleep -Seconds 1
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import * as XLSX from "xlsx";
|
||||||
|
|
||||||
|
export const standardForCastTemplate = async () => {
|
||||||
|
/**
|
||||||
|
* Creates the standard Template for bulk orders in
|
||||||
|
*/
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
["CustomerArticleNumber", "Quantity", "RequirementDate", "CustomerID"],
|
||||||
|
];
|
||||||
|
|
||||||
|
// create a new workbook
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
const ws = XLSX.utils.aoa_to_sheet(headers);
|
||||||
|
//const ws2 = XLSX.utils.aoa_to_sheet(headers2);
|
||||||
|
|
||||||
|
const columnWidths = headers[0].map((header) => ({
|
||||||
|
width: header.length + 2,
|
||||||
|
}));
|
||||||
|
|
||||||
|
ws["!cols"] = columnWidths;
|
||||||
|
|
||||||
|
// append the worksheet to the workbook
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, `Sheet1`);
|
||||||
|
//XLSX.utils.book_append_sheet(wb, ws2, `Sheet2`);
|
||||||
|
|
||||||
|
// Write the excel file and trigger the download'
|
||||||
|
XLSX.writeFile(wb, "BulkForecastTemplate");
|
||||||
|
|
||||||
|
// Write the workbook to a buffer and return it
|
||||||
|
const excelBuffer = XLSX.write(wb, { bookType: "xlsx", type: "buffer" });
|
||||||
|
|
||||||
|
return excelBuffer;
|
||||||
|
};
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { standardForecast } from "./mappings/standardForcast.js";
|
||||||
|
|
||||||
|
export const forecastIn = async (data: any, user: any) => {
|
||||||
|
/**
|
||||||
|
* Bulk orders in, and custom file parsing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let success = true;
|
||||||
|
let message = "";
|
||||||
|
let orderData: any = [];
|
||||||
|
|
||||||
|
// what type of order are we dealing with?
|
||||||
|
if (data["fileType"] === "standard") {
|
||||||
|
//run the standard forecast in
|
||||||
|
const standard = await standardForecast(data["postPostForecast"], user);
|
||||||
|
success = standard.success ?? false;
|
||||||
|
message = standard.message ?? "Error posting standard forecast";
|
||||||
|
orderData = standard.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data["fileType"] === "energizer") {
|
||||||
|
// orders in
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data["fileType"] === "loreal") {
|
||||||
|
// orders in
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data["fileType"] === "pg") {
|
||||||
|
// orders in
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success,
|
||||||
|
message,
|
||||||
|
data: orderData,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export const standardForecast = async (data: any, user: any) => {
|
||||||
|
/**
|
||||||
|
* Post a standard forecast based on the standard template.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Forecast Posted",
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import { prodEndpointCreation } from "../../../../../globalUtils/createUrl.js";
|
||||||
|
import { createLog } from "../../../../logger/logger.js";
|
||||||
|
|
||||||
|
export const postForecast = async (data: any, user: any) => {
|
||||||
|
let endpoint = await prodEndpointCreation(
|
||||||
|
"/public/v1.0/DemandManagement/DELFOR"
|
||||||
|
);
|
||||||
|
|
||||||
|
//console.log(endpoint);
|
||||||
|
//console.log(req.body.orders[0]);
|
||||||
|
try {
|
||||||
|
const results = await axios({
|
||||||
|
url: endpoint,
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Basic ${user.prod}`,
|
||||||
|
},
|
||||||
|
// if a body is sent over it would be like below
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
|
||||||
|
//console.log(results.data);
|
||||||
|
//console.log(results.status);
|
||||||
|
if (results.data.errors) {
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"forecast",
|
||||||
|
"logistics",
|
||||||
|
`There was an error posting the Forecast: ${JSON.stringify(
|
||||||
|
results.data.errors
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Error processing forecast",
|
||||||
|
data: results.data.errors[0].message,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.status === 200) {
|
||||||
|
createLog(
|
||||||
|
"info",
|
||||||
|
"forecast",
|
||||||
|
"logistics",
|
||||||
|
`Forcast was successfully posted: ${JSON.stringify(
|
||||||
|
results.data
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Success on posting forecast",
|
||||||
|
data: results.data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
//console.log(`There is an error`, error);
|
||||||
|
if (error) {
|
||||||
|
//console.log(error.response.data);
|
||||||
|
createLog(
|
||||||
|
"error",
|
||||||
|
"forecast",
|
||||||
|
"logistics",
|
||||||
|
`There was an error posting the Forecast: ${JSON.stringify(
|
||||||
|
error.response.data
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "There was an error posting the Forecast",
|
||||||
|
data: error.response.data,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -50,6 +50,7 @@ export const standardOrders = async (data: any, user: any) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const plantToken = s.filter((s) => s.name === "plantToken");
|
const plantToken = s.filter((s) => s.name === "plantToken");
|
||||||
|
|
||||||
const arrayBuffer = await data.arrayBuffer();
|
const arrayBuffer = await data.arrayBuffer();
|
||||||
const buffer = Buffer.from(arrayBuffer);
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
|
||||||
@@ -110,11 +111,15 @@ export const standardOrders = async (data: any, user: any) => {
|
|||||||
|
|
||||||
// map everything out for each order
|
// map everything out for each order
|
||||||
const nOrder = newOrders.map((o: any) => {
|
const nOrder = newOrders.map((o: any) => {
|
||||||
|
const invoice = i.filter(
|
||||||
|
(i: any) => i.deliveryAddress === parseInt(customerID)
|
||||||
|
);
|
||||||
|
if (!invoice) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
customerId: parseInt(customerID),
|
customerId: parseInt(customerID),
|
||||||
invoiceAddressId: i.filter(
|
invoiceAddressId: invoice[0].invoiceAddress, // matched to the default invoice address
|
||||||
(i: any) => i.deliveryAddress === parseInt(customerID)
|
|
||||||
)[0].invoiceAddress, // matched to the default invoice address
|
|
||||||
customerOrderNo: o.CustomerOrderNumber,
|
customerOrderNo: o.CustomerOrderNumber,
|
||||||
orderDate: new Date(Date.now()).toLocaleString("en-US"),
|
orderDate: new Date(Date.now()).toLocaleString("en-US"),
|
||||||
positions: [
|
positions: [
|
||||||
@@ -143,8 +148,10 @@ export const standardOrders = async (data: any, user: any) => {
|
|||||||
|
|
||||||
postedOrders.push({
|
postedOrders.push({
|
||||||
customer: customerID,
|
customer: customerID,
|
||||||
|
//totalOrders: orders?.length(),
|
||||||
success: posting.success,
|
success: posting.success,
|
||||||
message: posting.message,
|
message: posting.message,
|
||||||
|
data: posting.data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { abbottOrders } from "./customMappings/abbottTruckList.js";
|
import { abbottOrders } from "./mappings/abbottTruckList.js";
|
||||||
import { standardOrders } from "./customMappings/standardOrders.js";
|
import { standardOrders } from "./mappings/standardOrders.js";
|
||||||
|
|
||||||
export const ordersIn = async (data: any, user: any) => {
|
export const ordersIn = async (data: any, user: any) => {
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +15,7 @@ export const ordersIn = async (data: any, user: any) => {
|
|||||||
// run the standard orders in
|
// run the standard orders in
|
||||||
const standard = await standardOrders(data["postOrders"], user);
|
const standard = await standardOrders(data["postOrders"], user);
|
||||||
success = standard.success ?? false;
|
success = standard.success ?? false;
|
||||||
message = standard.message ?? "Error posting Abbott Orders";
|
message = standard.message ?? "Error posting Standard Orders";
|
||||||
orderData = standard.data;
|
orderData = standard.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import getPPOO from "./route/getPPOO.js";
|
|||||||
import getcyclecount from "./route/getCycleCountLanes.js";
|
import getcyclecount from "./route/getCycleCountLanes.js";
|
||||||
import postBulkOrders from "./route/dm/bulkOrdersIn.js";
|
import postBulkOrders from "./route/dm/bulkOrdersIn.js";
|
||||||
import standardTemplate from "./route/dm/getStandardTemplate.js";
|
import standardTemplate from "./route/dm/getStandardTemplate.js";
|
||||||
|
import standardForcasttemplate from "./route/dm/getStandardForecastTemplate.js";
|
||||||
|
import postForecast from "./route/dm/forecastIn.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -33,6 +35,8 @@ const routes = [
|
|||||||
//DM
|
//DM
|
||||||
postBulkOrders,
|
postBulkOrders,
|
||||||
standardTemplate,
|
standardTemplate,
|
||||||
|
postForecast,
|
||||||
|
standardForcasttemplate,
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
// app.route("/server", modules);
|
// app.route("/server", modules);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|||||||
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
||||||
import { verify } from "hono/jwt";
|
import { verify } from "hono/jwt";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
const app = new OpenAPIHono();
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
@@ -39,19 +40,34 @@ app.openapi(
|
|||||||
// if (body["fileType"] === "standard") {
|
// if (body["fileType"] === "standard") {
|
||||||
// console.log(`doing standard orders in.`);
|
// console.log(`doing standard orders in.`);
|
||||||
// }
|
// }
|
||||||
try {
|
const { data: payload, error: pe } = await tryCatch(
|
||||||
const payload = await verify(token, process.env.JWT_SECRET!);
|
verify(token, process.env.JWT_SECRET!)
|
||||||
const orders = await ordersIn(body, payload.user);
|
);
|
||||||
|
|
||||||
return c.json({
|
if (pe) {
|
||||||
success: orders.success,
|
|
||||||
message: orders.message,
|
|
||||||
data: orders.data,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { data: orders, error } = await tryCatch(
|
||||||
|
ordersIn(body, payload.user)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Error posting forecast",
|
||||||
|
data: error,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: orders?.success ?? false,
|
||||||
|
message: orders?.message ?? "Error posting forecast",
|
||||||
|
data: orders?.data ?? [],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
export default app;
|
export default app;
|
||||||
|
|||||||
74
server/services/logistics/route/dm/forecastIn.ts
Normal file
74
server/services/logistics/route/dm/forecastIn.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { ordersIn } from "../../controller/dm/ordersIn/ordersIn.js";
|
||||||
|
import { verify } from "hono/jwt";
|
||||||
|
import { forecastIn } from "../../controller/dm/forecast/forecastIn.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
// const Body = z
|
||||||
|
// .object({
|
||||||
|
// age: z.number().optional().openapi({ example: 90 }),
|
||||||
|
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
||||||
|
// type: z.string().optional().openapi({ example: "fg" }),
|
||||||
|
// })
|
||||||
|
// .openapi("User");
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["logistics"],
|
||||||
|
summary: "Post forecast to DM",
|
||||||
|
method: "post",
|
||||||
|
path: "/postforecastin",
|
||||||
|
// request: {
|
||||||
|
// body: {
|
||||||
|
// content: {
|
||||||
|
// "application/json": { schema: Body },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// description:
|
||||||
|
// "Provided a running number and lot number you can consume material.",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c) => {
|
||||||
|
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
||||||
|
const body = await c.req.parseBody();
|
||||||
|
const authHeader = c.req.header("Authorization");
|
||||||
|
const token = authHeader?.split("Bearer ")[1] || "";
|
||||||
|
//console.log(body); // File | string
|
||||||
|
|
||||||
|
// if (body["fileType"] === "standard") {
|
||||||
|
// console.log(`doing standard orders in.`);
|
||||||
|
// }
|
||||||
|
const { data: payload, error: pe } = await tryCatch(
|
||||||
|
verify(token, process.env.JWT_SECRET!)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pe) {
|
||||||
|
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: orders, error } = await tryCatch(
|
||||||
|
forecastIn(body, payload.user)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return c.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Error posting forecast",
|
||||||
|
data: error,
|
||||||
|
},
|
||||||
|
400
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({
|
||||||
|
success: orders?.success ?? false,
|
||||||
|
message: orders?.message ?? "Error posting forecast",
|
||||||
|
data: orders?.data ?? [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { responses } from "../../../../globalUtils/routeDefs/responses.js";
|
||||||
|
import { standardTemplate } from "../../controller/dm/ordersIn/createTemplate.js";
|
||||||
|
import { tryCatch } from "../../../../globalUtils/tryCatch.js";
|
||||||
|
import { standardForCastTemplate } from "../../controller/dm/forecast/createTemplate.js";
|
||||||
|
|
||||||
|
const app = new OpenAPIHono();
|
||||||
|
|
||||||
|
// const Body = z
|
||||||
|
// .object({
|
||||||
|
// age: z.number().optional().openapi({ example: 90 }),
|
||||||
|
// //email: z.string().optional().openapi({example: "s.smith@example.com"}),
|
||||||
|
// type: z.string().optional().openapi({ example: "fg" }),
|
||||||
|
// })
|
||||||
|
// .openapi("User");
|
||||||
|
app.openapi(
|
||||||
|
createRoute({
|
||||||
|
tags: ["logistics"],
|
||||||
|
summary: "Gets the standard Forecast Template",
|
||||||
|
method: "get",
|
||||||
|
path: "/bulkforcasttemplate",
|
||||||
|
// request: {
|
||||||
|
// body: {
|
||||||
|
// content: {
|
||||||
|
// "application/json": { schema: Body },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// description:
|
||||||
|
// "Provided a running number and lot number you can consume material.",
|
||||||
|
responses: responses(),
|
||||||
|
}),
|
||||||
|
async (c: any) => {
|
||||||
|
//apiHit(c, { endpoint: "api/sqlProd/close" });
|
||||||
|
const defaultFilename = `bulkForcastTemplate-${format(
|
||||||
|
new Date(Date.now()),
|
||||||
|
"M-d-yyyy"
|
||||||
|
)}.xlsx`;
|
||||||
|
const filename = c.req.query("filename") || defaultFilename;
|
||||||
|
const { data, error } = await tryCatch(standardForCastTemplate());
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return c.json({
|
||||||
|
success: false,
|
||||||
|
message: "Error creating template",
|
||||||
|
data: error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(data, {
|
||||||
|
headers: {
|
||||||
|
"Content-Type":
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// return c.json({
|
||||||
|
// success: data.success,
|
||||||
|
// message: data.message,
|
||||||
|
// data: data.data,
|
||||||
|
// });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
export default app;
|
||||||
Reference in New Issue
Block a user