Making Fredy an ESM project (#70)

Making Fredy an ESM project
This commit is contained in:
Christian Kellner
2023-03-13 13:42:43 +01:00
committed by GitHub
parent 7d0ec72a0c
commit 2c5eceb0c1
69 changed files with 862 additions and 1567 deletions

View File

@@ -1,10 +1,15 @@
const path = require('path');
import { JSONFileSync } from 'lowdb/node';
import { getDirName } from '../../utils.js';
import path from 'path';
import LowdashAdapter from './LowDashAdapter.js';
const DB_PATH = path.dirname(require.main.filename) + '/db/jobListingData.json';
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync(DB_PATH);
const low = require('lowdb');
const db = low(adapter);
const file = path.join(getDirName(), '../', 'db/jobListingData.json');
const adapter = new JSONFileSync(file);
const db = new LowdashAdapter(adapter);
db.read();
db.data ||= {};
const buildKey = (jobKey, providerId, endpoint) => {
let key = `${jobKey}`;
@@ -19,35 +24,31 @@ const buildKey = (jobKey, providerId, endpoint) => {
}
return key;
};
exports.getNumberOfAllKnownListings = (jobId) => {
const data = db.get(`${jobId}.providerData`).value() || {};
export const getNumberOfAllKnownListings = (jobId) => {
const data = db.chain.get(`${jobId}.providerData`).value() || {};
return Object.values(data)
.map((values) => Object.keys(values).length)
.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
};
exports.getListingProviderDataForAnalytics = (jobId) => {
export const getListingProviderDataForAnalytics = (jobId) => {
const key = buildKey(jobId, 'providerData');
return db.get(key).value() || {};
return db.chain.get(key).value() || {};
};
exports.getKnownListings = (jobId, providerId) => {
export const getKnownListings = (jobId, providerId) => {
const providerListingsKey = buildKey(jobId, 'providerData', providerId, 'listings');
return db.get(providerListingsKey).value() || {};
return db.chain.get(providerListingsKey).value() || {};
};
exports.setKnownListings = (jobId, providerId, listings) => {
export const setKnownListings = (jobId, providerId, listings) => {
const providerListingsKey = buildKey(jobId, 'providerData', providerId, 'listings');
return db.set(providerListingsKey, listings).write();
db.chain.set(providerListingsKey, listings).value();
return db.write();
};
exports.setLastJobExecution = (jobId) => {
export const setLastJobExecution = (jobId) => {
const key = buildKey(jobId, null, 'lastExecution');
return db.set(key, Date.now()).write();
db.chain.set(key, Date.now()).value();
return db.write();
};
exports.removeListings = (jobId) => {
db.unset(jobId).write();
export const removeListings = (jobId) => {
db.chain.unset(jobId).value();
db.write();
};