Refactor getUserData function to use fs.promises for file reading
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,9 +1,18 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs').promises;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { getUserData } = require('../Middlewares/watcherMiddleware');
|
|
||||||
|
|
||||||
const filePath = path.join(__dirname, '../user.json');
|
const filePath = path.join(__dirname, '../user.json');
|
||||||
|
|
||||||
|
async function getUserData() {
|
||||||
|
try {
|
||||||
|
const fileContent = await fs.readFile(filePath, 'utf8');
|
||||||
|
return JSON.parse(fileContent);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to read from ${filePath}: ${err}`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkUserExistsAD(req, res, next) {
|
async function checkUserExistsAD(req, res, next) {
|
||||||
let userData = await getUserData();
|
let userData = await getUserData();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user