Improve EMS interfaces and add LIN decoding.
This commit is contained in:
@@ -2,21 +2,24 @@ import { DBFFile } from "dbffile";
|
||||
import log from "electron-log/main";
|
||||
import _ from "lodash";
|
||||
import deepLowerCaseKeys from "../../util/deepLowercaseKeys";
|
||||
import { OwnerRecordInterface, ParsedAD1 } from "./decode-ad1.interface";
|
||||
import { OwnerRecordInterface, DecodedAd1 } from "./decode-ad1.interface";
|
||||
import errorTypeCheck from "../../util/errorTypeCheck";
|
||||
|
||||
const DecodeAD1 = async (extensionlessFilePath: string): Promise<ParsedAD1> => {
|
||||
let dbf;
|
||||
const DecodeAD1 = async (
|
||||
extensionlessFilePath: string
|
||||
): Promise<DecodedAd1> => {
|
||||
let dbf: DBFFile;
|
||||
try {
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}A.AD1`);
|
||||
} catch (error) {
|
||||
log.error("Error opening AD1 File.", error);
|
||||
log.error("Error opening AD1 File.", errorTypeCheck(error));
|
||||
dbf = await DBFFile.open(`${extensionlessFilePath}.AD1`);
|
||||
log.log("Found AD1 file using regular CIECA Id.");
|
||||
}
|
||||
|
||||
if (!dbf) {
|
||||
log.error(`Could not find any AD1 files at ${extensionlessFilePath}`);
|
||||
return null;
|
||||
throw new Error(`Could not find any AD1 files at ${extensionlessFilePath}`);
|
||||
}
|
||||
|
||||
const rawDBFRecord = await dbf.readRecords(1);
|
||||
@@ -24,7 +27,7 @@ const DecodeAD1 = async (extensionlessFilePath: string): Promise<ParsedAD1> => {
|
||||
//AD1 will always have only 1 row.
|
||||
//Commented lines have been cross referenced with existing partner fields.
|
||||
|
||||
const rawAd1Data = deepLowerCaseKeys(
|
||||
const rawAd1Data: DecodedAd1 = deepLowerCaseKeys(
|
||||
_.pick(rawDBFRecord[0], [
|
||||
//TODO: Add typings for EMS File Formats.
|
||||
"INS_CO_ID",
|
||||
@@ -192,7 +195,7 @@ const DecodeAD1 = async (extensionlessFilePath: string): Promise<ParsedAD1> => {
|
||||
ownr_ph1: rawAd1Data.ownr_ph1,
|
||||
ownr_ph2: rawAd1Data.ownr_ph2,
|
||||
ownr_ea: rawAd1Data.ownr_ea,
|
||||
shopid: "UUID",
|
||||
shopid: "UUID", //TODO: Need to add the shop uuid to this set of functions.
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user