Zwei Fixes für korrekten DB aufbau

This commit is contained in:
Torsten Schulz
2024-09-04 12:05:40 +02:00
parent 8fe833d527
commit 6d31c0f86e
2 changed files with 12 additions and 5 deletions

View File

@@ -37,7 +37,7 @@ const addClub = async (req, res) => {
console.log('[addClub] - create club');
const newClub = await Club.create({ name: clubName });
console.log('[addClub] - add user to new club');
UserClub.create({ userId: user.id, clubId: newClub.id, approved: true });
await UserClub.create({ userId: user.id, clubId: newClub.id, approved: true });
console.log('[addClub] - prepare response');
res.status(200).json(newClub);
console.log('[addClub] - done');

View File

@@ -5,16 +5,23 @@ const createHash = (value) => {
}
function encryptData(data) {
try {
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), Buffer.alloc(16, 0));
try {
if (data === null || data === undefined) {
data = '';
}
const cipher = crypto.createCipheriv(
'aes-256-cbc',
Buffer.from(process.env.ENCRYPTION_KEY, 'hex'),
Buffer.alloc(16, 0)
);
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
return encrypted;
} catch (error) {
console.log(error, data, process.env.ENCRYPTION_KEY, typeof data, process.env.ENCRYPTION_KEY.length);
return '';
}
}
}
function decryptData(data) {
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(process.env.ENCRYPTION_KEY, 'hex'), Buffer.alloc(16, 0));