import axios from "axios"; import { db } from "../../../../../database/dbclient.js"; import { commandLog } from "../../../../../database/schema/commandLog.js"; import { createSSCC } from "../../../../globalUtils/createSSCC.js"; import { prodEndpointCreation } from "../../../../globalUtils/createUrl.js"; import { tryCatch } from "../../../../globalUtils/tryCatch.js"; import { createLog } from "../../../logger/logger.js"; import { query } from "../../../sqlServer/prodSqlServer.js"; type Data = { runningNr: number; laneID: number; }; export const relatePallet = async (data: Data) => { const { runningNr, laneID } = data; // replace the rn // console.log(data); // create the url to post // do we have warehousing turned on? const { data: feature, error: featureError } = (await tryCatch( query( `SELECT [Id] ,[Feature] ,[Enabled] ,[ActivationDate] FROM [test1_AlplaPROD2.0_Read].[support].[FeatureActivation] where [Feature] = 7`, "feature switch check", ), )) as any; let prodUrl = "/public/v1.0/Warehousing/Relocate"; if (featureError) { prodUrl = "/public/v1.0/Warehousing/Relocate"; } if (feature?.data.length > 0) { prodUrl = "/public/v1.1/Warehousing/Unit/Relocate"; } // 1.0 "/public/v1.0/Warehousing/AdjustSiloStockLevel"," // 1.1 "/public/v1.1/Warehousing/Lane/AdjustSiloStockLevel" let url = await prodEndpointCreation(prodUrl); const SSCC = await createSSCC(runningNr); const consumeSomething = { ScannerId: 999, laneId: laneID, sscc: SSCC.slice(2), }; console.log(consumeSomething); try { const results = await axios.post(url, consumeSomething, { headers: { "X-API-Key": process.env.TEC_API_KEY || "", "Content-Type": "application/json", }, }); if (results.data.Errors) { return { success: false, message: results.data.Errors.Error.Description, }; } if (results.data.Result !== 0 || results.data.data.length <= 0) { return { success: false, message: results.data.Message, }; } const { data: commandL, error: ce } = await tryCatch( db.insert(commandLog).values({ commandUsed: "relocate", bodySent: data, }), ); return { success: true, message: "Pallet Was Relocated", status: results.status, }; } catch (error: any) { console.log(error); return { success: false, status: 200, message: error.response?.data.errors[0].message, }; } };