70 lines
1.1 KiB
JavaScript
70 lines
1.1 KiB
JavaScript
const db = require('../../data/db');
|
|
|
|
module.exports = {
|
|
addAccount,
|
|
getAccountById,
|
|
updateAccount,
|
|
deleteAccount,
|
|
getMeetingsByAccountId,
|
|
};
|
|
|
|
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.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',
|
|
);
|
|
}
|