Skip to content

Commit

Permalink
Merge pull request #361 from RodriSanchez1/feature/communicatorTimest…
Browse files Browse the repository at this point in the history
…amps

Feature/communicatorTimestamps
  • Loading branch information
tomivm authored Jul 3, 2024
2 parents 6dce123 + d3c9ce0 commit 16bc263
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion api/controllers/communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
Expand Down
13 changes: 12 additions & 1 deletion api/models/Communicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -55,7 +56,8 @@ const COMMUNICATOR_SCHEMA_OPTIONS = {
ret.id = ret._id;
delete ret._id;
}
}
},
timestamps: {updatedAt: 'lastEdited'},
};

const communicatorSchema = new Schema(
Expand Down Expand Up @@ -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();
});
Expand Down
4 changes: 3 additions & 1 deletion test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const verifyCommunicatorProperties = (body) => {
'author',
'rootBoard',
'boards',
'defaultBoardsIncluded'
'defaultBoardsIncluded',
'createdAt',
'lastEdited'
);
};

Expand Down

0 comments on commit 16bc263

Please sign in to comment.