diff --git a/api/controllers/communicator.js b/api/controllers/communicator.js index a2516a88..340e15a1 100644 --- a/api/controllers/communicator.js +++ b/api/controllers/communicator.js @@ -30,7 +30,8 @@ function createCommunicator(req, res) { email: communicator.email, description: communicator.description, rootBoard: communicator.rootBoard, - boards: communicator.boards + boards: communicator.boards, + lastEdited: communicator.lastEdited, }, message: 'Communicator saved successfully' }); diff --git a/api/models/Communicator.js b/api/models/Communicator.js index d8caf891..8491c0e8 100644 --- a/api/models/Communicator.js +++ b/api/models/Communicator.js @@ -3,6 +3,7 @@ const mongoose = require('mongoose'); const bcrypt = require('bcryptjs'); const constants = require('../constants'); +const moment = require('moment'); const Schema = mongoose.Schema; const COMMUNICATOR_SCHEMA_DEFINITION = { @@ -55,7 +56,8 @@ const COMMUNICATOR_SCHEMA_OPTIONS = { ret.id = ret._id; delete ret._id; } - } + }, + timestamps: {updatedAt: 'lastEdited'}, }; const communicatorSchema = new Schema( @@ -126,6 +128,15 @@ communicatorSchema.path('email').validate(async function(email) { */ communicatorSchema.pre('save', function(next) { + + const now = moment().format(); + + if (!this.createdAt) { + this.createdAt = now; + } + + this.lastEdited = now; + if (!this.isNew) return next(); next(); }); diff --git a/test/helper.js b/test/helper.js index e9a19c31..a750532b 100644 --- a/test/helper.js +++ b/test/helper.js @@ -81,7 +81,9 @@ const verifyCommunicatorProperties = (body) => { 'author', 'rootBoard', 'boards', - 'defaultBoardsIncluded' + 'defaultBoardsIncluded', + 'createdAt', + 'lastEdited' ); };