refactor(siloadjustment): refactored to get the settings from the state vs direct from db
This commit is contained in:
@@ -9,6 +9,10 @@ import { sendEmail } from "../../../notifications/controller/sendMail.js";
|
|||||||
import { settings } from "../../../../../database/schema/settings.js";
|
import { settings } from "../../../../../database/schema/settings.js";
|
||||||
import { generateOneTimeKey } from "../../../../globalUtils/singleUseKey.js";
|
import { generateOneTimeKey } from "../../../../globalUtils/singleUseKey.js";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
import {
|
||||||
|
getSettings,
|
||||||
|
serverSettings,
|
||||||
|
} from "../../../server/controller/settings/getSettings.js";
|
||||||
|
|
||||||
export const createSiloAdjustment = async (
|
export const createSiloAdjustment = async (
|
||||||
data: any | null,
|
data: any | null,
|
||||||
@@ -18,18 +22,21 @@ export const createSiloAdjustment = async (
|
|||||||
* Creates a silo adjustment based off warehouse, location, and qty.
|
* Creates a silo adjustment based off warehouse, location, and qty.
|
||||||
* qty will come from the hmi, prolink, or silo patrol
|
* qty will come from the hmi, prolink, or silo patrol
|
||||||
*/
|
*/
|
||||||
const { data: set, error: setError } = await tryCatch(
|
// const { data: set, error: setError } = await tryCatch(
|
||||||
db.select().from(settings)
|
// db.select().from(settings)
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (setError) {
|
// const { data: set, error: setError } = await tryCatch(getSettings());
|
||||||
return {
|
|
||||||
success: false,
|
|
||||||
message: `There was an error getting setting data to post to the server.`,
|
|
||||||
data: setError,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// if (setError) {
|
||||||
|
// return {
|
||||||
|
// success: false,
|
||||||
|
// message: `There was an error getting setting data to post to the server.`,
|
||||||
|
// data: setError,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
const set = serverSettings.length === 0 ? [] : serverSettings;
|
||||||
// getting stock data first so we have it prior to the adjustment
|
// getting stock data first so we have it prior to the adjustment
|
||||||
const { data: s, error: stockError } = await tryCatch(
|
const { data: s, error: stockError } = await tryCatch(
|
||||||
query(siloQuery, "Silo data Query")
|
query(siloQuery, "Silo data Query")
|
||||||
|
|||||||
Reference in New Issue
Block a user