|
|
@@ -155,30 +155,28 @@ function checkRepoExists(req, res, next) {
|
|
|
/**
|
|
|
* Create a new repo
|
|
|
*/
|
|
|
-app.post('/repos', function(req, res) {
|
|
|
-
|
|
|
- // Check for title and extract params
|
|
|
- if(! req.body || ! req.body.title) {
|
|
|
- res.status(400).send('Le titre ne peut pas être vide !');
|
|
|
- }
|
|
|
- const { title } = req.body;
|
|
|
- const repoSlug = slug(title.toLowerCase());
|
|
|
- const existingRepo = exStore.getRepo(repoSlug);
|
|
|
+app.post('/repos',
|
|
|
+ checkBodyPropsExist('title'),
|
|
|
+ function(req, res) {
|
|
|
|
|
|
- // Prevent duplicate title
|
|
|
- if(existingRepo) {
|
|
|
- return res.status(409).send("La collection '" + title + "' existe déjà !");
|
|
|
- }
|
|
|
+ const { title } = req.body;
|
|
|
+ const repoSlug = slug(title.toLowerCase());
|
|
|
+ const existingRepo = exStore.getRepo(repoSlug);
|
|
|
+ // Prevent duplicate title
|
|
|
+ if(existingRepo) {
|
|
|
+ return res.status(409).send("La collection '" + title + "' existe déjà !");
|
|
|
+ }
|
|
|
|
|
|
- // Prepare config
|
|
|
- var config = Object.assign({
|
|
|
- title
|
|
|
- }, repoTmpl);
|
|
|
+ // Prepare config
|
|
|
+ var config = Object.assign({
|
|
|
+ title
|
|
|
+ }, repoTmpl);
|
|
|
|
|
|
- exStore.addRepository(repoSlug, config)
|
|
|
- .then(repo => res.json(config));
|
|
|
+ exStore.addRepository(repoSlug, config)
|
|
|
+ .then(repo => res.json(config));
|
|
|
|
|
|
-});
|
|
|
+ }
|
|
|
+);
|
|
|
|
|
|
app.post('/:repoSlug/examples/:exampleSlug/file',
|
|
|
checkRepoExists,
|