backend/api/models/accountModel.js

85 lines
1.3 KiB
JavaScript

const db = require('../../data/db');
module.exports = {
addAccount,
getAccountById,
updateAccount,
deleteAccount,
getMeetingsByAccountId,
getAccountByEmail,
};
function addAccount(data) {
return db('account')
.insert(data)
.returning([
'id',
'username',
'email',
'timezone',
'earliest_time',
'latest_time',
]);
}
function updateAccount(data, id) {
return db('account')
.where({ id })
.update(data)
.returning([
'id',
'username',
'email',
'timezone',
'earliest_time',
'latest_time',
]);
}
function deleteAccount(id) {
return db('account').where({ id }).del();
}
function getMeetingsByAccountId(account_id) {
return db('participant as p')
.select(
'm.id',
'm.title',
'm.description',
'm.start_time',
'm.duration',
'm.status',
)
.join('meeting as m', { 'm.id': 'p.meeting_id' })
.where({ account_id });
}
function getAccountById(id) {
return db('account')
.where({ id })
.first()
.select(
'id',
'username',
'email',
'timezone',
'earliest_time',
'latest_time',
);
}
function getAccountByEmail(email) {
return db('account')
.where({ email })
.first()
.select(
'id',
'username',
'password',
'email',
'timezone',
'earliest_time',
'latest_time',
);
}