Nodejs Stale (PocketBase client SDK not compatible)

This commit is contained in:
2022-09-14 17:03:05 +02:00
parent 8028436d2c
commit 7412fd9238
3 changed files with 652 additions and 33 deletions

View File

@@ -0,0 +1,57 @@
import reader from "xlsx";
import { getJsDateFromExcel } from "excel-date-to-js";
import PocketBase from "pocketbase";
import { readdirSync } from "fs";
import { join } from "path";
const excelPath = join(__dirname, "..", "..", "Excel");
const excelFiles = readdirSync(excelPath);
const readExcel = (filePath: string) => {
let data: unknown[] = [];
const file = reader.readFile(filePath);
const sheets = file.SheetNames;
for (let i = 0; i < sheets.length; i++) {
const temp = reader.utils.sheet_to_json(file.Sheets[file.SheetNames[i]]);
temp.forEach((res) => {
data.push(res);
});
}
return data;
};
excelFiles.forEach((file) => {
if (!file.includes("raw_") && !file.includes("lock")) {
const excelFile = join(excelPath, file);
const data = readExcel(excelFile);
data.forEach((record: any) => {
if (
record.DATELINDJA_KORIGJ !== "" &&
record.DATELINDJA_KORIGJ !== "DEKLARUAR"
) {
const pacient = {
emer: record.EMER,
mbiemer: record.MBIEMER,
mosha: record.MOSHA,
datelindja: getJsDateFromExcel(record.DATELINDJA_KORIGJ),
error: record.ERROR,
};
}
});
}
});
const loginToPocketBase = async () => {
const client = new PocketBase("http://127.0.0.1:8090");
const adminAuthData = await client.admins.authViaEmail(
"test@example.com",
"123456"
);
console.log(adminAuthData);
};
(async () => {
await loginToPocketBase();
})();