Skip to content

Commit

Permalink
Merge pull request #226 from openstad/hotfix/add-virtual-end-date
Browse files Browse the repository at this point in the history
hotfix: bring back endDate by adding a virtual field
  • Loading branch information
Badmuts authored May 31, 2022
2 parents eaa5fe4 + 787ebb7 commit 3c77997
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/models/Idea.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ module.exports = function (db, sequelize, DataTypes) {
}
},

endDate: {
type: DataTypes.VIRTUAL(DataTypes.DATE, ['startDate']),
get: function () {
var _config = merge.recursive(true, config, this.site.config);
var duration =
(_config &&
_config.ideas &&
_config.ideas.duration) ||
90;
if (
this.site &&
this.site.config &&
this.site.config.ideas &&
this.site.config.ideas.automaticallyUpdateStatus &&
this.site.config.ideas.automaticallyUpdateStatus.isActive
) {
duration =
this.site.config.ideas.automaticallyUpdateStatus.afterXDays || 0;
}
var endDate = moment(this.getDataValue('startDate'))
.add(duration, 'days')
.toDate();

return endDate
},
},

sort: {
type: DataTypes.INTEGER,
auth: {
Expand Down

0 comments on commit 3c77997

Please sign in to comment.