generated from csc301-2023-fall/deliverable-documents
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcampRoutes.js
89 lines (79 loc) · 2.58 KB
/
campRoutes.js
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
88
89
/**
* This module specifies the routes for request endpoints in the camp Service.
*
* @param {Object} [app] The express application
*
* @module api/routes/campRoutes
* @requires api/controllers/campController
* @requires api/middleware/authHandler
* @requires multer
*/
const campController = require('../controllers/campController');
const auth = require('../middleware/authHandler');
const multer = require('multer');
const stor = multer.diskStorage({
destination: "./api/res/public",
filename: (req, file, cb) => {
cb(null, "floorplan.jpg")
}
});
function jpegFilter(req, file, cb) {
if (file.mimetype === "image/jpeg" || file.mimetype === "image/jpg") {
cb(null, true)
} else {
cb(null, false)
}
}
const uploadFloorplanImage = multer({
storage: stor,
limits: {
fileFilter: jpegFilter
}
}).single('floorplan');
const campRoutes = (app) => {
/**
* Route to get all camps.
* @name GET /camp/all
* @memberof module:routes/campRoutes
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
*/
app.get('/camp/all', auth, async (req, res) => {
const all_camps = await campController.getAllCamps(req, res);
res.send(all_camps);
})
/**
* Route to get a camp by id.
* @name GET /camp/:camp_id/
* @memberof module:routes/campRoutes
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
*/
.get('/camp/:camp_id', auth, async (req, res) => {
const camp = await campController.getCamp(req, res);
res.send(camp);
})
/**
* Route to create a new camp.
* @name GET /camp/create/
* @memberof module:routes/campRoutes
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
*/
.post('/camp/create', auth, async (req, res) => {
const status = await campController.createCamp(req, res);
res.send(status);
})
/**
* Route to set floorplan
* @name POST /camp/floorplan/
* @memberof module:routes/campRoutes
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
*/
.post('/camp/floorplan', [auth, uploadFloorplanImage], async (req, res) => {
const status = await campController.setFloorplan(req, res);
res.send(status);
});
};
module.exports = campRoutes;