Skip to content

Commit

Permalink
#22 add backend functionality to post timekeeping boards and cards
Browse files Browse the repository at this point in the history
  • Loading branch information
scmet committed Oct 26, 2024
1 parent 584c97f commit c24ab0a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
53 changes: 52 additions & 1 deletion backend/api/routes/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,58 @@ async function deleteTaskTrackingEntry(req, res) {
}
}

/*
* timekeeping for student assistants
*/

const postTimekeepingBoardByUser= (req, res) => {
//const userId = req.params.userId;
const name = req.body.name; // request body includes name of board
const year = req.body.year;
const hours = req.body.hours;

// validation of input data
if (!name || !year || !hours) {
return res.status(400).json({error: 'Name, Jahr und Stundenangabe sind erforderlich'});
}
const query = 'INSERT INTO timekeeping_board (name, year, hours) VALUES ($1, $2, $3) RETURNING *;';
const values = [name, year, hours];

pool.query(query, values, (error, results) => {
if (error) {
console.error('Fehler beim Einfügen des Timekeeping Boards:', error);
return res.status(500).json({error: 'Fehler beim Einfügen des Boards'});
}

res.status(201).json(results.rows[0]); // return new board
});
}

const postCardToTimekeepingBoardOfUser= (req, res) => {
const boardId = req.params.boardId;
const { name, description, start, duration, month } = req.body;

// validation of input data
if (!name || !start || !duration || !month) {
return res.status(400).json({ error: 'Titel, Start, Dauer und Monat sind erforderlich' });
}

const query = `
INSERT INTO time_entry (board_id, name, description, start, duration, month)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING *;
`;
const values = [boardId, name, description, start, duration, month];

pool.query(query, values, (error, results) => {
if (error) {
console.error('Fehler beim Einfügen des Zeiteintags:', error);
return res.status(500).json({ error: 'Fehler beim Einfügen des Zeiteintrags' });
}

res.status(201).json(results.rows[0]); // return new card
});
};

module.exports = {
getGroups,
Expand Down Expand Up @@ -817,5 +867,6 @@ module.exports = {
getTaskEntriesByTime,
createTaskEntry,
deleteTaskTrackingEntry,

postTimekeepingBoardByUser,
postCardToTimekeepingBoardOfUser
};
4 changes: 4 additions & 0 deletions backend/api/routes/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ router.put('/:id', controller.updateTimeEntry);

router.delete('/:id', controller.deleteTimeEntry);

// timekeeping for student assistants

router.post('/users/:userid/boards', controller.postTimekeepingBoardByUser)
router.post('users/:userid/boards/boardid/cards', controller.postCardToTimekeepingBoardOfUser)
// TODO: test it

module.exports = router;

0 comments on commit c24ab0a

Please sign in to comment.