Update .gitignore and add new dependencies and routes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-04-02 20:59:13 +02:00
parent aa75d50361
commit 8f3e604774
16 changed files with 823 additions and 187 deletions

View File

@@ -1,7 +1,7 @@
const fs = require('fs').promises;
const path = require('path');
const filePath = path.join(__dirname, '../user.json');
const filePath = path.join(__dirname, '../data/user.json');
async function getUserData() {
try {
@@ -15,9 +15,14 @@ async function getUserData() {
async function checkUserExistsAD(req, res, next) {
let userData = await getUserData();
console.log('User data:', userData);
if (!req.user || (!req.user.name && !req.user.id)) {
return res.status(500).send('Internal Server Error');
if (Array.isArray(req.user)) {
req.user = req.user.find(u => u._json && u._json.sAMAccountName);
}
if (req.user && req.user._json && req.user._json.sAMAccountName) {
req.user.name = req.user._json.sAMAccountName;
}
try {
@@ -40,7 +45,7 @@ async function checkUserExistsAD(req, res, next) {
users.push(newUser);
try {
await fs.promises.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
await fs.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
} catch (error) {
console.error(`Failed to write to ${filePath}: ${error}`);
return next(error);