/
meetup.js
executable file
·45 lines (31 loc) · 995 Bytes
/
meetup.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
"use strict";
/**
* Module dependencies.
*/
const App = require('widget-cms');
const markdown = require('markdown-it')();
const _ = require('lodash');
const Meetup = App.Model.extend({
tableName: 'meetups',
hasTimestamps: true,
saving: function (model, attr, options) {
if (this.get('updated_by') && options.context && options.context.user_id) {
this.set('updated_by', options.context.user_id);
}
// if is new or slug has changed and has slug field - generate new slug
if (!this.get('slug') || this.hasChanged('slug')) {
return this.generateSlug(this.get('slug') || this.get('name') || this.get('title'))
.then( (slug) => {
this.set({slug: slug});
})
.catch(function (err) {
console.error(err);
});
}
},
viewed: function () {
let views = this.get('views') || 0;
return this.save({'views': views + 1}, {patch: true});
}
});
module.exports = App.addModel('Meetup', Meetup);