@vulkano/core 1.12.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -319,7 +319,7 @@ module.exports = function loadServer() {
319
319
  }
320
320
 
321
321
  // ---------------
322
- // Permission Policy - File: app/config/express/permissionPolicy.js
322
+ // Permission Policy - File: app/config/express/permissionPolicy.js
323
323
  // ---------------
324
324
  const {
325
325
  enabled: ppEnabled,
@@ -347,6 +347,28 @@ module.exports = function loadServer() {
347
347
 
348
348
  }
349
349
 
350
+ // ---------------
351
+ // REDIS - File: app/config/redis.js
352
+ // ---------------
353
+ const {
354
+ enabled: redisEnabled
355
+ } = app.config.redis || {};
356
+
357
+ app.redisClient = null;
358
+
359
+ if (redisEnabled === true) {
360
+
361
+ const {
362
+ redis
363
+ } = app.config || {};
364
+
365
+ const rClient = socketRedis(redis);
366
+ rClient.on('error', (err) => console.log('Redis Client Error', err));
367
+
368
+ app.redisClient = await rClient.connect();
369
+
370
+ }
371
+
350
372
  // ---------------
351
373
  // VIEWS
352
374
  // ---------------
@@ -56,6 +56,7 @@ module.exports = {
56
56
 
57
57
  /**
58
58
  * Method to create a new record
59
+ *
59
60
  * @param {Promise} data
60
61
  */
61
62
  create(data) {
@@ -72,6 +73,7 @@ module.exports = {
72
73
 
73
74
  /**
74
75
  * Method to update a record
76
+ *
75
77
  * @param {ObjectID} id
76
78
  * @param {Object} data
77
79
  * @returns {Promise}
@@ -102,6 +104,7 @@ module.exports = {
102
104
 
103
105
  /**
104
106
  * Method to delete a record
107
+ *
105
108
  * @param {ObjectID} id
106
109
  * @returns {Promise}
107
110
  */
@@ -113,6 +116,121 @@ module.exports = {
113
116
  // Soft delete
114
117
  return this.update(id, { active: false });
115
118
 
119
+ },
120
+
121
+ /**
122
+ * Method to add a subdocument
123
+ *
124
+ * @param {String} key
125
+ * @param {ObjectID} parent
126
+ * @param {Object} data
127
+ * @returns {Promise}
128
+ */
129
+ createSubdoc(key, parent, data) {
130
+
131
+ return this
132
+ .findOne({ _id: parent })
133
+ .then( (r) => {
134
+
135
+ if (!r) {
136
+ return VSError.reject('Invalid ID. Record not found.', 404);
137
+ }
138
+
139
+ r[key].push(data);
140
+
141
+ r.markModified(key);
142
+
143
+ return r.save()
144
+ .then( () => {
145
+ return r[key][r[key].length - 1];
146
+ });
147
+
148
+ });
149
+
150
+ },
151
+
152
+ /**
153
+ * Method to update a subdocument
154
+ *
155
+ * @param {String} key
156
+ * @param {ObjectID} parent
157
+ * @param {ObjectID} subdoc
158
+ * @param {Object} data
159
+ * @returns {Promise}
160
+ */
161
+ updateSubdoc(key, parent, subdoc, data) {
162
+
163
+ return this
164
+ .findOne({ _id: parent })
165
+ .then( (r) => {
166
+
167
+ if (!r) {
168
+ return VSError.reject('Invalid ID. Record not found.', 404);
169
+ }
170
+
171
+ const current = r[key] ? r[key].id(subdoc) : null;
172
+
173
+ if (!current) {
174
+ return VSError.reject('Invalid ID. Item not found.', 404);
175
+ }
176
+
177
+ r[key].id(subdoc).set({ ...data, _id: subdoc });
178
+
179
+ r.markModified(key);
180
+
181
+ return r.save()
182
+ .then( () => {
183
+ return r[key].id(subdoc);
184
+ });
185
+
186
+ });
187
+
188
+ },
189
+
190
+ /**
191
+ * Method to remove a subdocument
192
+ *
193
+ * @param {String} key
194
+ * @param {ObjectID} parent
195
+ * @param {ObjectID} subdoc
196
+ * @returns {Promise}
197
+ */
198
+ removeSubdoc(key, parent, subdoc) {
199
+
200
+ return this
201
+ .findOne({ _id: parent })
202
+ .then( (r) => {
203
+
204
+ if (!r) {
205
+ return VSError.reject('Invalid ID. Record not found.', 404);
206
+ }
207
+
208
+ const current = r[key] ? r[key].id(subdoc) : null;
209
+
210
+ if (!current) {
211
+ return VSError.reject('Invalid ID. Item not found.', 404);
212
+ }
213
+
214
+ r[key].id(subdoc).deleteOne();
215
+
216
+ r.markModified(key);
217
+
218
+ return r.save();
219
+
220
+ });
221
+
222
+ },
223
+
224
+ /**
225
+ * ALIAS: removeSubdoc
226
+ *
227
+ * @param {String} key
228
+ * @param {ObjectID} parent
229
+ * @param {ObjectID} subdoc
230
+ * @returns {Promise}
231
+ */
232
+ deleteSubdoc(key, parent, subdoc) {
233
+ return this.removeSubdoc(key, parent, subdoc);
116
234
  }
117
235
 
118
236
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulkano/core",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "A MVC framework using Express 4",
5
5
  "license": "MIT",
6
6
  "author": "Vulkano Team",