2020-05-02 19:06:34 +00:00
|
|
|
const db = require('../../data/db');
|
2020-05-01 15:32:46 +00:00
|
|
|
|
|
|
|
module.exports = {
|
2020-05-04 14:02:31 +00:00
|
|
|
addAccount,
|
|
|
|
getAccountById,
|
|
|
|
updateAccount,
|
|
|
|
deleteAccount,
|
2020-05-06 10:30:32 +00:00
|
|
|
getMeetingsByAccountId,
|
2020-05-08 11:12:10 +00:00
|
|
|
getAccountByEmail,
|
2020-05-01 15:32:46 +00:00
|
|
|
};
|
|
|
|
|
2020-05-04 14:02:31 +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.duration',
|
|
|
|
'm.status',
|
|
|
|
)
|
|
|
|
.join('meeting as m', { 'm.id': 'p.meeting_id' })
|
|
|
|
.where({ account_id });
|
|
|
|
}
|
2020-05-04 14:02:31 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2020-05-08 11:12:10 +00:00
|
|
|
|
|
|
|
function getAccountByEmail(email) {
|
|
|
|
return db('account')
|
|
|
|
.where({ email })
|
|
|
|
.first()
|
|
|
|
.select(
|
|
|
|
'id',
|
|
|
|
'username',
|
|
|
|
'password',
|
|
|
|
'email',
|
|
|
|
'timezone',
|
|
|
|
'earliest_time',
|
|
|
|
'latest_time',
|
|
|
|
);
|
|
|
|
}
|