Added delete all EMS functionality RPS-11

This commit is contained in:
Patrick Fic
2020-10-26 10:22:21 -07:00
parent 89a8ad380f
commit 6359641b8c
6 changed files with 68 additions and 16 deletions

View File

@@ -2,7 +2,7 @@ const { ipcMain } = require("electron");
const Nucleus = require("nucleus-nodejs");
const ipcTypes = require("../../src/ipc.types");
const { ImportJob } = require("../decoder/decoder");
const { GetListOfEstimates } = require("./file-scan");
const { GetListOfEstimates, DeleteAllEms } = require("./file-scan");
ipcMain.on(
ipcTypes.default.fileScan.toMain.scanFilePaths,
@@ -22,3 +22,16 @@ ipcMain.on(
await ImportJob(filePath);
}
);
ipcMain.on(
ipcTypes.default.fileScan.toMain.deleteAllEms,
async (event, filePath) => {
Nucleus.track("DELETE_ALLEMS");
await DeleteAllEms();
const ret = await GetListOfEstimates();
event.reply(
ipcTypes.default.fileScan.toRenderer.scanFilePathsResponse,
ret
);
}
);

View File

@@ -6,6 +6,7 @@ const fsPromises = fs.promises;
const _ = require("lodash");
const { DecodeEstimate } = require("../decoder/decoder");
const Nucleus = require("nucleus-nodejs");
const { format } = require("path");
async function GetListOfEstimates() {
Nucleus.track("SCAN_ALL_ESTIMATES");
@@ -42,4 +43,32 @@ async function GetEnvFiles() {
return allFilePaths;
}
async function DeleteAllEms() {
try {
const filePaths = store.get("filePaths");
const allFilePaths = [];
await Promise.all(
filePaths.map(async (fp) => {
const allFilesinDir = await fsPromises.readdir(fp);
allFilesinDir.map((envFileName) => {
allFilePaths.push(path.join(fp, envFileName));
return null;
});
})
);
await Promise.all(
allFilePaths.map(async (file) => {
await fsPromises.unlink(file);
})
);
return true;
} catch (error) {
return false;
}
}
exports.GetListOfEstimates = GetListOfEstimates;
exports.DeleteAllEms = DeleteAllEms