-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
87 lines (64 loc) · 2.76 KB
/
Copy pathapp.js
File metadata and controls
87 lines (64 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require('express');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const path = require('path');
const config = require('./config/cloudinaryConfig');
const app = express();
const model = require('./model/model');
const auth = require('./middleware/auth');
const multer = require('./middleware/multer');
const uploader = config.uploader;
const cloudinaryConfig = config.cloudinaryConfig;
const multerUploads = multer.multerUploads;
const swaggerJSDoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.resolve(__dirname, 'src/public')));
app.use('*', cloudinaryConfig);
// Swagger definition
const swaggerDefinition = {
info: {
title: 'Teamwork', // Title of the documentation
version: '1', // Version of the app
description: 'Teamwork is an internal social network for employees' +
'of an organization. The goal of this application is to' +
'facilitate more interaction between colleagues and promote' +
'team bonding, short description of the app'
},
host: 'https://api-teamwork.herokuapp.com/', // the host or url of the app
basePath: '/api/v1', // the basepath of your endpoint
};
// options for the swagger docs
const options = {
// import swaggerDefinitions
swaggerDefinition,
// path to the API docs
apis: ['./docs/**/*.yaml'],
};
// initialize swagger-jsdoc
const swaggerSpec = swaggerJSDoc(options);
// use swagger-Ui-express for your app documentation endpoint
app.use('/api/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.post('/api/v1/auth/signin', model.signIn);
//ADMIN
app.post('/api/v1/auth/create-user',auth, model.createUser);
app.get('/api/v1/flags',auth, model.getFlags);
app.delete('/api/v1/flag',auth, model.deleteFlag);
//EMPLOYEE
app.post('/api/v1/articles',auth, model.createArticle);
app.post('/api/v1/gifs',auth,multerUploads, model.createGif);
app.patch('/api/v1/articles/:id',auth, model.editArticle);
app.delete('/api/v1/articles/:id',auth, model.deleteArticle);
app.delete('/api/v1/gifs/:id',auth, model.deleteGif);
app.post('/api/v1/articles/:id/comment',auth, model.commentArticle);
app.post('/api/v1/gifs/:id/comment',auth, model.commentGif);
app.get('/api/v1/feed',auth, model.feed);
app.get('/api/v1/articles/:id',auth, model.viewArticle);
app.get('/api/v1/gifs/:id',auth, model.viewGif);
app.get('/api/v1/feed/search',auth, model.viewCategory);
app.post('/api/v1/articles/:id/flag',auth, model.flagArticle);
app.post('/api/v1/gifs/:id/flag',auth, model.flagGif);
app.delete('/api/v1/employee/:id',model.deleteEmployee);
module.exports = app;