sleep-tracker-backend/services/sessions/sessionsModel.js

39 lines
659 B
JavaScript
Raw Normal View History

2019-08-01 14:25:44 +00:00
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();
}