@tiledesk/tiledesk-server 2.3.100 → 2.3.101
Sign up to get free protection for your applications and to get access to all the features.
- package/app.js +5 -4
- package/models/property.js +49 -0
- package/package.json +1 -1
- package/routes/property.js +175 -0
package/app.js
CHANGED
@@ -56,7 +56,7 @@ const masked_databaseUri = MaskData.maskPhone(databaseUri, {
|
|
56
56
|
if (process.env.DISABLE_MONGO_PASSWORD_MASK ==true || process.env.DISABLE_MONGO_PASSWORD_MASK == "true") {
|
57
57
|
winston.info("DatabaseUri: " + databaseUri);
|
58
58
|
}else {
|
59
|
-
winston.info("DatabaseUri: " + masked_databaseUri);
|
59
|
+
winston.info("DatabaseUri masked: " + masked_databaseUri);
|
60
60
|
}
|
61
61
|
|
62
62
|
|
@@ -125,6 +125,7 @@ var logs = require('./routes/logs');
|
|
125
125
|
var requestUtilRoot = require('./routes/requestUtilRoot');
|
126
126
|
var urls = require('./routes/urls');
|
127
127
|
var email = require('./routes/email');
|
128
|
+
var property = require('./routes/property');
|
128
129
|
|
129
130
|
var bootDataLoader = require('./services/bootDataLoader');
|
130
131
|
var settingDataLoader = require('./services/settingDataLoader');
|
@@ -242,7 +243,7 @@ if (process.env.ENABLE_ALTERNATIVE_CORS_MIDDLEWARE === "true") {
|
|
242
243
|
|
243
244
|
// https://stackoverflow.com/questions/18710225/node-js-get-raw-request-body-using-express
|
244
245
|
|
245
|
-
const JSON_BODY_LIMIT = process.
|
246
|
+
const JSON_BODY_LIMIT = process.env.JSON_BODY_LIMIT || '500KB';
|
246
247
|
winston.debug("JSON_BODY_LIMIT : " + JSON_BODY_LIMIT);
|
247
248
|
|
248
249
|
app.use(bodyParser.json({limit: JSON_BODY_LIMIT,
|
@@ -491,6 +492,7 @@ app.use('/:projectid/campaigns',[passport.authenticate(['basic', 'jwt'], { sessi
|
|
491
492
|
|
492
493
|
app.use('/:projectid/emails',[passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('agent', ['bot','subscription'])], email);
|
493
494
|
|
495
|
+
app.use('/:projectid/properties',[passport.authenticate(['basic', 'jwt'], { session: false }), validtoken, roleChecker.hasRoleOrTypes('owner', ['bot','subscription'])], property);
|
494
496
|
|
495
497
|
|
496
498
|
|
@@ -545,5 +547,4 @@ app.use((err, req, res, next) => {
|
|
545
547
|
|
546
548
|
|
547
549
|
|
548
|
-
|
549
|
-
module.exports = app;
|
550
|
+
module.exports = app;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
var mongoose = require('mongoose');
|
2
|
+
var Schema = mongoose.Schema;
|
3
|
+
var winston = require('../config/winston');
|
4
|
+
|
5
|
+
var PropertySchema = new Schema({
|
6
|
+
|
7
|
+
label: {
|
8
|
+
type: String,
|
9
|
+
required: true,
|
10
|
+
},
|
11
|
+
name: {
|
12
|
+
type: String,
|
13
|
+
required: true,
|
14
|
+
index: true
|
15
|
+
},
|
16
|
+
type: {
|
17
|
+
type: String,
|
18
|
+
required: true,
|
19
|
+
default: "text",
|
20
|
+
index: true
|
21
|
+
},
|
22
|
+
status: {
|
23
|
+
type: Number,
|
24
|
+
required: true,
|
25
|
+
default: 100,
|
26
|
+
index: true
|
27
|
+
},
|
28
|
+
createdBy: {
|
29
|
+
type: String,
|
30
|
+
required: true
|
31
|
+
},
|
32
|
+
id_project: {
|
33
|
+
type: String,
|
34
|
+
required: true,
|
35
|
+
index: true
|
36
|
+
}
|
37
|
+
},{
|
38
|
+
timestamps: true
|
39
|
+
}
|
40
|
+
);
|
41
|
+
|
42
|
+
var property = mongoose.model('property', PropertySchema);
|
43
|
+
|
44
|
+
if (process.env.MONGOOSE_SYNCINDEX) {
|
45
|
+
property.syncIndexes();
|
46
|
+
winston.info("property syncIndexes")
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = property;
|
package/package.json
CHANGED
@@ -0,0 +1,175 @@
|
|
1
|
+
var express = require('express');
|
2
|
+
var router = express.Router();
|
3
|
+
var Property = require("../models/property");
|
4
|
+
var winston = require('../config/winston');
|
5
|
+
|
6
|
+
router.post('/', function (req, res) {
|
7
|
+
|
8
|
+
winston.debug(req.body);
|
9
|
+
winston.debug("req.user", req.user);
|
10
|
+
|
11
|
+
var newProperty= new Property({
|
12
|
+
label: req.body.label,
|
13
|
+
name: req.body.name,
|
14
|
+
type: req.body.type,
|
15
|
+
id_project: req.projectid,
|
16
|
+
createdBy: req.user._id,
|
17
|
+
});
|
18
|
+
|
19
|
+
newProperty.save(function(err, savedProperty) {
|
20
|
+
if (err) {
|
21
|
+
winston.error('Error saving the property '+ JSON.stringify(savedProperty), err)
|
22
|
+
return reject(err);
|
23
|
+
}
|
24
|
+
winston.verbose('Property created ', savedProperty.toJSON());
|
25
|
+
|
26
|
+
res.json(savedProperty);
|
27
|
+
});
|
28
|
+
|
29
|
+
});
|
30
|
+
|
31
|
+
router.put('/:propertyid', function (req, res) {
|
32
|
+
winston.debug(req.body);
|
33
|
+
var update = {};
|
34
|
+
|
35
|
+
if (req.body.label!=undefined) {
|
36
|
+
update.label = req.body.label;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (req.body.name!=undefined) {
|
40
|
+
update.name = req.body.name;
|
41
|
+
}
|
42
|
+
if (req.body.type!=undefined) {
|
43
|
+
update.type = req.body.type;
|
44
|
+
}
|
45
|
+
if (req.body.status!=undefined) {
|
46
|
+
update.status = req.body.status;
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
Property.findByIdAndUpdate(req.params.propertyid, update, { new: true, upsert: true }, function (err, updatedProperty) {
|
51
|
+
if (err) {
|
52
|
+
winston.error('--- > ERROR ', err);
|
53
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
54
|
+
}
|
55
|
+
|
56
|
+
res.json(updatedProperty);
|
57
|
+
});
|
58
|
+
});
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
router.delete('/:propertyid', function (req, res) {
|
64
|
+
winston.debug(req.body);
|
65
|
+
|
66
|
+
Property.findByIdAndUpdate(req.params.propertyid, {status: 1000}, { new: true, upsert: true }, function (err, updatedProperty) {
|
67
|
+
if (err) {
|
68
|
+
winston.error('--- > ERROR ', err);
|
69
|
+
return res.status(500).send({ success: false, msg: 'Error updating object.' });
|
70
|
+
}
|
71
|
+
|
72
|
+
res.json(updatedProperty);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
router.delete('/:propertyid/physical', function (req, res) {
|
77
|
+
winston.debug(req.body);
|
78
|
+
|
79
|
+
var projectuser = req.projectuser;
|
80
|
+
|
81
|
+
|
82
|
+
if (projectuser.role != "owner" ) {
|
83
|
+
return res.status(403).send({ success: false, msg: 'Unauthorized.' });
|
84
|
+
}
|
85
|
+
|
86
|
+
Property.remove({ _id: req.params.propertyid }, function (err, property) {
|
87
|
+
if (err) {
|
88
|
+
winston.error('--- > ERROR ', err);
|
89
|
+
return res.status(500).send({ success: false, msg: 'Error deleting object.' });
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
res.json(property);
|
94
|
+
});
|
95
|
+
});
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
router.get('/:propertyid', function (req, res) {
|
100
|
+
winston.debug(req.body);
|
101
|
+
|
102
|
+
Property.findById(req.params.propertyid, function (err, property) {
|
103
|
+
if (err) {
|
104
|
+
return res.status(500).send({ success: false, msg: 'Error getting object.' });
|
105
|
+
}
|
106
|
+
if (!property) {
|
107
|
+
return res.status(404).send({ success: false, msg: 'Object not found.' });
|
108
|
+
}
|
109
|
+
res.json(property);
|
110
|
+
});
|
111
|
+
});
|
112
|
+
|
113
|
+
|
114
|
+
router.get('/', function (req, res) {
|
115
|
+
|
116
|
+
var limit = 40; // Number of request per page
|
117
|
+
|
118
|
+
if (req.query.limit) {
|
119
|
+
limit = parseInt(req.query.limit);
|
120
|
+
winston.debug('property ROUTE - limit: '+limit);
|
121
|
+
}
|
122
|
+
|
123
|
+
var page = 0;
|
124
|
+
|
125
|
+
if (req.query.page) {
|
126
|
+
page = req.query.page;
|
127
|
+
}
|
128
|
+
|
129
|
+
var skip = page * limit;
|
130
|
+
winston.debug('property ROUTE - SKIP PAGE ', skip);
|
131
|
+
|
132
|
+
|
133
|
+
var query = { "id_project": req.projectid, "status": 100};
|
134
|
+
|
135
|
+
if (req.query.name) {
|
136
|
+
winston.debug('property ROUTE req.query.name', req.query.name);
|
137
|
+
query.name = req.query.name;
|
138
|
+
}
|
139
|
+
|
140
|
+
if (req.query.status) {
|
141
|
+
query.status = req.query.status;
|
142
|
+
}
|
143
|
+
|
144
|
+
var direction = -1; //-1 descending , 1 ascending
|
145
|
+
if (req.query.direction) {
|
146
|
+
direction = req.query.direction;
|
147
|
+
}
|
148
|
+
|
149
|
+
var sortField = "createdAt";
|
150
|
+
if (req.query.sort) {
|
151
|
+
sortField = req.query.sort;
|
152
|
+
}
|
153
|
+
|
154
|
+
var sortQuery = {};
|
155
|
+
sortQuery[sortField] = direction;
|
156
|
+
|
157
|
+
winston.debug("sort query", sortQuery);
|
158
|
+
|
159
|
+
return Property.find(query).
|
160
|
+
skip(skip).limit(limit).
|
161
|
+
sort(sortQuery).
|
162
|
+
exec(function (err, properties) {
|
163
|
+
if (err) {
|
164
|
+
winston.error('property ROUTE - REQUEST FIND ERR ', err)
|
165
|
+
return (err);
|
166
|
+
}
|
167
|
+
|
168
|
+
return res.json(properties);
|
169
|
+
});
|
170
|
+
});
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
module.exports = router;
|