-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.js
More file actions
76 lines (58 loc) · 1.99 KB
/
Copy pathadmin.js
File metadata and controls
76 lines (58 loc) · 1.99 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
const express = require("express");
const admin = express.Router();
// Your routes will be added at the end of this: localhost:3000/admin
// To access profile the user needs to be logged in!
// Use {passport, bcrypt, dotenv, passport-local, express-session} dependencies to get the user authentication working.
//
/**
* Add the id at the end of the path so as to make it using the id of the user (
* TODO:
* getid from the database
* Make sure that this path is only available if the user is logged in using their id.
*
*
*/
admin.get("/dashboard", (req, res)=>{
console.log("does it get here?")
res.render("dashboard")});
admin.get("/profile", (req, res)=>{
res.render("profile");
});
/**
* TO UPLOAD: use the multer dependency. This will
* help to upload the files you will need.
* TODO:
* 1. Need to fix the uploading mechanism so that I know
* I can get the files back and display them on HTML.
* 2. I need to add the profile object that displays the
* admin profile with their newly uploaded image.
* 3.
*/
const multer = require("multer");
var storage = multer.diskStorage({
destination: function (req, file, callback) {
callback(null, 'files');
},
filename: function (req, file, callback) {
callback(null, file.originalname);
}
});
const upload = multer({dest: storage});
const id = 1;
// TODO: 1. Find the error on the uploading function and make sure it uploads to (directory: files)
admin.post("/post-picture", upload.single('profile-image'), (req, res, next)=>{
const {text} = req.body;
const response = [];
const profileImg = req.file.filename;
if (!profileImg){
const error = new Error("Please upload file!");
error.httpStatusCode = 400;
return next(error);
}else if (profileImg){
console.log("it gets here", text, profileImg);
response.push({message_success: "It works"});
res.send(profileImg);
}
res.render("profile");
})
module.exports = admin