Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ The name is composed of **poll** and **lock** and is the name of a fish, the [po
cd backend
yarn install --dev

node_modules/.bin/snc "../../../Moodle/Webprogrammierung (SoSe 23)/Projekt/Pollack.yaml" --output generated-frontend
node_modules/.bin/snc "../../../Moodle/Webprogrammierung (SoSe 23)/Projekt/Pollack.yaml" --output ../generated-backend
```

1 change: 1 addition & 0 deletions backend/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ app.use(cookieParser());
*/
app.use('/poll', require('./routes/poll'));
app.use('/vote', require('./routes/vote'));
app.use('/user', require('./routes/user'));

// catch 404
app.use((req, res, next) => {
Expand Down
68 changes: 68 additions & 0 deletions backend/src/api/routes/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,72 @@ router.delete('/lack/:token', async (req, res, next) => {
}
});

/**
* Add a new poll
*/
router.post('/lock', async (req, res, next) => {
const options = {
body: req.body
};

try {
const result = await poll.addPollock(options);
res.status(result.status || 200).send(result.data);
} catch (err) {
next(err);
}
});

/**
* Return the statistics of the poll by share token.
*/
router.get('/lock/:token', async (req, res, next) => {
const options = {
token: req.params['token']
};

try {
const result = await poll.findPollock(options);
res.status(result.status || 200).send(result.data);
} catch (err) {
next(err);
}
});

/**
* Update a poll by admin token.
*/
router.put('/lock/:token', async (req, res, next) => {
const options = {
body: req.body,
token: req.params['token']
};

try {
const result = await poll.updatePollock(options);
res.status(200).send(result.data);
} catch (err) {
return res.status(500).send({
status: 500,
error: 'Server Error'
});
}
});

/**
* Deletes a poll by admin token.
*/
router.delete('/lock/:token', async (req, res, next) => {
const options = {
token: req.params['token']
};

try {
const result = await poll.deletePollock(options);
res.status(200).send(result.data);
} catch (err) {
next(err);
}
});

module.exports = router;
69 changes: 69 additions & 0 deletions backend/src/api/routes/vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,73 @@ router.delete('/lack/:token', async (req, res, next) => {
}
});

/**
* Add a new vote to the poll
*/
router.post('/lock/:token', async (req, res, next) => {
const options = {
body: req.body,
token: req.params['token']
};

try {
const result = await vote.addVotePollock(options);
res.status(result.status || 200).send(result.data);
} catch (err) {
next(err);
}
});

/**
* Find the vote of the token
*/
router.get('/lock/:token', async (req, res, next) => {
const options = {
token: req.params['token']
};

try {
const result = await vote.findVotePollock(options);
res.status(result.status || 200).send(result.data);
} catch (err) {
next(err);
}
});

/**
* Update a vote of the token
*/
router.put('/lock/:token', async (req, res, next) => {
const options = {
body: req.body,
token: req.params['token']
};

try {
const result = await vote.updateVotePollock(options);
res.status(200).send(result.data);
} catch (err) {
return res.status(500).send({
status: 500,
error: 'Server Error'
});
}
});

/**
* Delete a vote of the token
*/
router.delete('/lock/:token', async (req, res, next) => {
const options = {
token: req.params['token']
};

try {
const result = await vote.deleteVotePollock(options);
res.status(200).send(result.data);
} catch (err) {
next(err);
}
});

module.exports = router;
119 changes: 119 additions & 0 deletions backend/src/api/services/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,122 @@ module.exports.deletePollack = async (options) => {
};
};

/**
* @param {Object} options
* @throws {Error}
* @return {Promise}
*/
module.exports.addPollock = async (options) => {
// Implement your business logic here...
//
// This function should return as follows:
//
// return {
// status: 200, // Or another success code.
// data: [] // Optional. You can put whatever you want here.
// };
//
// If an error happens during your business logic implementation,
// you should throw an error as follows:
//
// throw new ServerError({
// status: 500, // Or another error code.
// error: 'Server Error' // Or another error message.
// });

return {
status: 200,
data: 'addPollock ok!'
};
};

/**
* @param {Object} options
* @param {String} options.token The share token of poll
* @throws {Error}
* @return {Promise}
*/
module.exports.findPollock = async (options) => {
// Implement your business logic here...
//
// This function should return as follows:
//
// return {
// status: 200, // Or another success code.
// data: [] // Optional. You can put whatever you want here.
// };
//
// If an error happens during your business logic implementation,
// you should throw an error as follows:
//
// throw new ServerError({
// status: 500, // Or another error code.
// error: 'Server Error' // Or another error message.
// });

return {
status: 200,
data: 'findPollock ok!'
};
};

/**
* @param {Object} options
* @param {String} options.token admin token that need to be deleted
* @throws {Error}
* @return {Promise}
*/
module.exports.updatePollock = async (options) => {
// Implement your business logic here...
//
// This function should return as follows:
//
// return {
// status: 200, // Or another success code.
// data: [] // Optional. You can put whatever you want here.
// };
//
// If an error happens during your business logic implementation,
// you should throw an error as follows:
//
// throw new ServerError({
// status: 500, // Or another error code.
// error: 'Server Error' // Or another error message.
// });

return {
status: 200,
data: 'updatePollock ok!'
};
};

/**
* @param {Object} options
* @param {String} options.token Admin token to delete the poll
* @throws {Error}
* @return {Promise}
*/
module.exports.deletePollock = async (options) => {
// Implement your business logic here...
//
// This function should return as follows:
//
// return {
// status: 200, // Or another success code.
// data: [] // Optional. You can put whatever you want here.
// };
//
// If an error happens during your business logic implementation,
// you should throw an error as follows:
//
// throw new ServerError({
// status: 500, // Or another error code.
// error: 'Server Error' // Or another error message.
// });

return {
status: 200,
data: 'deletePollock ok!'
};
};

Loading