39 lines
659 B
JavaScript
39 lines
659 B
JavaScript
const db = require('../../data/dbConfig');
|
|
|
|
module.exports = {
|
|
addSession,
|
|
findUserSessions,
|
|
updateSession,
|
|
removeSession
|
|
};
|
|
|
|
async function addSession(session) {
|
|
const [id] = await db('sessions')
|
|
.insert(session);
|
|
return findSessionById(id);
|
|
}
|
|
|
|
function findUserSessions(user_id) {
|
|
return db
|
|
.from("sessions")
|
|
.where({ user_id });
|
|
}
|
|
|
|
function findSessionById(id) {
|
|
return db('sessions')
|
|
.where({ id })
|
|
.first();
|
|
}
|
|
|
|
async function updateSession(id, changes) {
|
|
await db('sessions')
|
|
.where({ id })
|
|
.update(changes, '*');
|
|
return findSessionById(id);
|
|
}
|
|
|
|
async function removeSession(id) {
|
|
await db('sessions')
|
|
.where({ id })
|
|
.del();
|
|
} |