Complete crud for accounts and meetings endpoints
This commit is contained in:
@@ -1,14 +1,69 @@
|
||||
const db = require('../../data/db');
|
||||
|
||||
module.exports = {
|
||||
addUser,
|
||||
addAccount,
|
||||
getAccountById,
|
||||
updateAccount,
|
||||
deleteAccount,
|
||||
// getMeetingsByAccountId,
|
||||
};
|
||||
|
||||
function addUser(userData) {
|
||||
// TODO Complete query without providing id
|
||||
// right now if ID is not provided, pg-promise send an erro fo mising column
|
||||
return db.one(
|
||||
'INSERT INTO account VALUES(emptyUpdate, ${username}, ${email}, ${password}, ${timezone}, ${earliest_time}, ${latest_time}) RETURNING *',
|
||||
userData,
|
||||
);
|
||||
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(id) {
|
||||
// // Get all meetings to which an account is participating
|
||||
// // select id, title, description, start_time, timezone, duration, status where
|
||||
// return db('participant')
|
||||
// .where({ id })
|
||||
// .select(
|
||||
// 'id',
|
||||
// 'username',
|
||||
// 'email',
|
||||
// 'timezone',
|
||||
// 'earliest_time',
|
||||
// 'latest_time',
|
||||
// );
|
||||
// }
|
||||
|
||||
function getAccountById(id) {
|
||||
return db('account')
|
||||
.where({ id })
|
||||
.first()
|
||||
.select(
|
||||
'id',
|
||||
'username',
|
||||
'email',
|
||||
'timezone',
|
||||
'earliest_time',
|
||||
'latest_time',
|
||||
);
|
||||
}
|
||||
|
||||
57
api/models/meetingModel.js
Normal file
57
api/models/meetingModel.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const db = require('../../data/db');
|
||||
|
||||
module.exports = {
|
||||
addMeeting,
|
||||
getMeetingById,
|
||||
updateMeeting,
|
||||
deleteMeeting,
|
||||
// getMeetingsByAccountId,
|
||||
};
|
||||
|
||||
function addMeeting(data) {
|
||||
return db('meeting')
|
||||
.insert(data)
|
||||
.returning([
|
||||
'id',
|
||||
'title',
|
||||
'description',
|
||||
'start_time',
|
||||
'timezone',
|
||||
'duration',
|
||||
'status',
|
||||
]);
|
||||
}
|
||||
|
||||
function updateMeeting(data, id) {
|
||||
return db('meeting')
|
||||
.where({ id })
|
||||
.update(data)
|
||||
.returning([
|
||||
'id',
|
||||
'title',
|
||||
'description',
|
||||
'start_time',
|
||||
'timezone',
|
||||
'duration',
|
||||
'status',
|
||||
]);
|
||||
}
|
||||
|
||||
function deleteMeeting(id) {
|
||||
return db('meeting').where({ id }).del();
|
||||
}
|
||||
|
||||
function getMeetingById(id) {
|
||||
return db('meeting')
|
||||
.where({ id })
|
||||
.first()
|
||||
.select(
|
||||
'id',
|
||||
'title',
|
||||
'description',
|
||||
'start_time',
|
||||
'timezone',
|
||||
'duration',
|
||||
'status',
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user