backend/api/models/accountModel.js

86 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-05-02 19:06:34 +00:00
const db = require('../../data/db');
2020-05-01 15:32:46 +00:00
module.exports = {
addAccount,
getAccountById,
updateAccount,
deleteAccount,
2020-05-06 10:30:32 +00:00
getMeetingsByAccountId,
getAccountByEmail,
2020-05-01 15:32:46 +00:00
};
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();
}
2020-05-06 10:30:32 +00:00
function getMeetingsByAccountId(account_id) {
return db('participant as p')
.select(
'm.id',
'm.title',
'm.description',
'm.start_time',
'm.timezone',
'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',
);
2020-05-01 16:24:59 +00:00
}
function getAccountByEmail(email) {
return db('account')
.where({ email })
.first()
.select(
'id',
'username',
'password',
'email',
'timezone',
'earliest_time',
'latest_time',
);
}