-
Notifications
You must be signed in to change notification settings - Fork 0
/
extras.txt
30 lines (25 loc) · 913 Bytes
/
extras.txt
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
/*-------------------------------------------EXTRAS-------------------------------------------------------------------*/
//Document Middleware to Embed users data into tour data
PRE Document Middleware
tourSchema.pre('save', async function(next) {
const guidePromises = this.guides.map(async id => {
return await UserModel.findById(id);
});
this.guides = await Promise.all(guidePromises);
next();
});
//POST Document Middleware
tourSchema.post('save', function(doc, next) {
console.log(doc);
next();
});
// Multer function to configure the desination and name of the file
const multerStorage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'public/img/users');
},
filename: (req, file, cb) => {
let fileName = `user-${req.user.id}-${Date.now()}.${file.mimetype.split('/')[1]}`;
cb(null, fileName);
},
});