lts-stats-api/app/db/mongo/mongoUsers.js

46 lines
1004 B
JavaScript
Raw Normal View History

2023-01-22 00:02:30 +01:00
const { mongoExecute } = require('./mongoDBPool');
async function createUserMongo({ id, username, hash, roles = [], firstname, lastname, vid }) {
return await mongoExecute(async({ database }) => {
const usersCol = database.collection('users');
const createdOn = new Date();
2023-09-09 18:24:57 +02:00
const updatedOn = new Date();
2023-01-22 00:02:30 +01:00
await usersCol.insertOne({
id,
username,
hash,
createdOn,
2023-09-09 18:24:57 +02:00
updatedOn,
2023-01-22 00:02:30 +01:00
roles,
firstname,
lastname,
vid
});
});
}
2023-09-09 18:24:57 +02:00
async function updateUserHash(id, hash) {
return await mongoExecute(async({ collection }) => {
return await collection.updateOne({
id
}, {
$set: {
hash,
updatedOn: new Date()
}
})
}, { colName: 'users' });
}
2023-01-22 00:02:30 +01:00
async function getUserMongo(username) {
return await mongoExecute(async({ collection }) => {
return await collection.findOne({ username });
}, { colName: 'users' })
}
module.exports = {
createUserMongo,
getUserMongo,
2023-09-09 18:24:57 +02:00
updateUserHash
2023-01-22 00:02:30 +01:00
};