-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
50 lines (42 loc) · 1.12 KB
/
helpers.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
const path = require('path');
const autoBind = require('auto-bind');
const moment = require('moment-jalaali');
moment.loadPersian({usePersianDigits: true})
module.exports = class Helpers {
constructor(req , res) {
autoBind(this);
this.req = req;
this.res = res;
this.formData = req.flash('formData')[0];
}
getObjects() {
return {
auth : this.auth(),
viewPath : this.viewPath,
...this.getGlobalVaribales(),
old : this.old,
date : this.date,
req : this.req
}
}
auth() {
return {
check : this.req.isAuthenticated(),
user : this.req.user
}
}
viewPath(dir) {
return path.resolve(config.layout.view_dir + '/' + dir);
}
getGlobalVaribales() {
return {
errors : this.req.flash('errors')
}
}
old(field , defaultValue = '') {
return this.formData && this.formData.hasOwnProperty(field) ? this.formData[field] : defaultValue;
}
date(time) {
return moment(time);
}
}