Add opcode and bodyshop query to main

This commit is contained in:
Patrick Fic
2025-03-21 08:33:41 -07:00
parent 6345b5a9a8
commit 6da5822197
9 changed files with 199 additions and 40 deletions

View File

@@ -1,12 +1,38 @@
import { IpcMainEvent } from "electron";
import { User } from "firebase/auth";
import client from "../graphql/graphql-client";
import {
ActiveBodyshopQueryResult,
MasterdataQueryResult,
QUERY_ACTIVE_BODYSHOP_TYPED,
QUERY_MASTERDATA_TYPED,
} from "../graphql/queries";
import Store from "../store/store";
import log from "electron-log/main";
const ipcMainHandleAuthStateChanged = async (
event: IpcMainEvent,
user: User | null
): Promise<void> => {
Store.set("user", user);
//Need to query the currently active shop, and store the metadata as well.
//Also need to query the OP Codes for decoding reference.
const activeBodyshop: ActiveBodyshopQueryResult = await client.request(
QUERY_ACTIVE_BODYSHOP_TYPED
);
Store.set("app.bodyshop", activeBodyshop.bodyshops[0]);
const OpCodes: MasterdataQueryResult = await client.request(
QUERY_MASTERDATA_TYPED,
{
key: `${activeBodyshop.bodyshops[0].region_config}_ciecaopcodes`,
}
);
Store.set("app.masterdata.opcodes", JSON.parse(OpCodes.masterdata[0]?.value));
log.debug("Received authentication state change from Renderer.", user);
log.debug("Requery shop information & master data.");
};
export { ipcMainHandleAuthStateChanged };