summaryrefslogtreecommitdiffstats
path: root/models/swimlanes.js
diff options
context:
space:
mode:
authorJustin Reynolds <justinr1234@gmail.com>2019-06-26 17:47:27 -0500
committerJustin Reynolds <justinr1234@gmail.com>2019-06-27 09:13:20 -0500
commitc60e80d25baa6a81b28f6090ca848553d20b2bb7 (patch)
tree64bcea66932f4b4635d5df6901f18d5ba6db0a37 /models/swimlanes.js
parentfb728baf0c87bae5fa39d92089b667ff1ed69fa6 (diff)
downloadwekan-c60e80d25baa6a81b28f6090ca848553d20b2bb7.tar.gz
wekan-c60e80d25baa6a81b28f6090ca848553d20b2bb7.tar.bz2
wekan-c60e80d25baa6a81b28f6090ca848553d20b2bb7.zip
Add createdAt and modifiedAt to all collections
Diffstat (limited to 'models/swimlanes.js')
-rw-r--r--models/swimlanes.js336
1 files changed, 198 insertions, 138 deletions
diff --git a/models/swimlanes.js b/models/swimlanes.js
index 9a53d116..82f73f79 100644
--- a/models/swimlanes.js
+++ b/models/swimlanes.js
@@ -3,89 +3,125 @@ Swimlanes = new Mongo.Collection('swimlanes');
/**
* A swimlane is an line in the kaban board.
*/
-Swimlanes.attachSchema(new SimpleSchema({
- title: {
- /**
- * the title of the swimlane
- */
- type: String,
- },
- archived: {
- /**
- * is the swimlane archived?
- */
- type: Boolean,
- autoValue() { // eslint-disable-line consistent-return
- if (this.isInsert && !this.isSet) {
- return false;
- }
+Swimlanes.attachSchema(
+ new SimpleSchema({
+ title: {
+ /**
+ * the title of the swimlane
+ */
+ type: String,
},
- },
- boardId: {
- /**
- * the ID of the board the swimlane is attached to
- */
- type: String,
- },
- createdAt: {
- /**
- * creation date of the swimlane
- */
- type: Date,
- autoValue() { // eslint-disable-line consistent-return
- if (this.isInsert) {
- return new Date();
- } else {
- this.unset();
- }
+ archived: {
+ /**
+ * is the swimlane archived?
+ */
+ type: Boolean,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert && !this.isSet) {
+ return false;
+ }
+ },
},
- },
- sort: {
- /**
- * the sort value of the swimlane
- */
- type: Number,
- decimal: true,
- // XXX We should probably provide a default
- optional: true,
- },
- color: {
- /**
- * the color of the swimlane
- */
- type: String,
- optional: true,
- // silver is the default, so it is left out
- allowedValues: [
- 'white', 'green', 'yellow', 'orange', 'red', 'purple',
- 'blue', 'sky', 'lime', 'pink', 'black',
- 'peachpuff', 'crimson', 'plum', 'darkgreen',
- 'slateblue', 'magenta', 'gold', 'navy', 'gray',
- 'saddlebrown', 'paleturquoise', 'mistyrose', 'indigo',
- ],
- },
- updatedAt: {
- /**
- * when was the swimlane last edited
- */
- type: Date,
- optional: true,
- autoValue() { // eslint-disable-line consistent-return
- if (this.isUpdate) {
- return new Date();
- } else {
- this.unset();
- }
+ boardId: {
+ /**
+ * the ID of the board the swimlane is attached to
+ */
+ type: String,
},
- },
- type: {
- /**
- * The type of swimlane
- */
- type: String,
- defaultValue: 'swimlane',
- },
-}));
+ createdAt: {
+ /**
+ * creation date of the swimlane
+ */
+ type: Date,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ sort: {
+ /**
+ * the sort value of the swimlane
+ */
+ type: Number,
+ decimal: true,
+ // XXX We should probably provide a default
+ optional: true,
+ },
+ color: {
+ /**
+ * the color of the swimlane
+ */
+ type: String,
+ optional: true,
+ // silver is the default, so it is left out
+ allowedValues: [
+ 'white',
+ 'green',
+ 'yellow',
+ 'orange',
+ 'red',
+ 'purple',
+ 'blue',
+ 'sky',
+ 'lime',
+ 'pink',
+ 'black',
+ 'peachpuff',
+ 'crimson',
+ 'plum',
+ 'darkgreen',
+ 'slateblue',
+ 'magenta',
+ 'gold',
+ 'navy',
+ 'gray',
+ 'saddlebrown',
+ 'paleturquoise',
+ 'mistyrose',
+ 'indigo',
+ ],
+ },
+ updatedAt: {
+ /**
+ * when was the swimlane last edited
+ */
+ type: Date,
+ optional: true,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isUpdate || this.isUpsert || this.isInsert) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ modifiedAt: {
+ type: Date,
+ denyUpdate: false,
+ // eslint-disable-next-line consistent-return
+ autoValue() {
+ if (this.isInsert || this.isUpsert || this.isUpdate) {
+ return new Date();
+ } else {
+ this.unset();
+ }
+ },
+ },
+ type: {
+ /**
+ * The type of swimlane
+ */
+ type: String,
+ defaultValue: 'swimlane',
+ },
+ })
+);
Swimlanes.allow({
insert(userId, doc) {
@@ -109,7 +145,7 @@ Swimlanes.helpers({
const _id = Swimlanes.insert(this);
const query = {
- swimlaneId: {$in: [oldId, '']},
+ swimlaneId: { $in: [oldId, ''] },
archived: false,
};
if (oldBoardId) {
@@ -126,18 +162,24 @@ Swimlanes.helpers({
},
cards() {
- return Cards.find(Filter.mongoSelector({
- swimlaneId: this._id,
- archived: false,
- }), { sort: ['sort'] });
+ return Cards.find(
+ Filter.mongoSelector({
+ swimlaneId: this._id,
+ archived: false,
+ }),
+ { sort: ['sort'] }
+ );
},
lists() {
- return Lists.find({
- boardId: this.boardId,
- swimlaneId: {$in: [this._id, '']},
- archived: false,
- }, { sort: ['sort'] });
+ return Lists.find(
+ {
+ boardId: this.boardId,
+ swimlaneId: { $in: [this._id, ''] },
+ archived: false,
+ },
+ { sort: ['sort'] }
+ );
},
myLists() {
@@ -153,8 +195,7 @@ Swimlanes.helpers({
},
colorClass() {
- if (this.color)
- return this.color;
+ if (this.color) return this.color;
return '';
},
@@ -182,7 +223,7 @@ Swimlanes.helpers({
},
remove() {
- Swimlanes.remove({ _id: this._id});
+ Swimlanes.remove({ _id: this._id });
},
});
@@ -221,10 +262,16 @@ Swimlanes.mutations({
},
});
+Swimlanes.before.update((userId, doc, fieldNames, modifier, options) => {
+ modifier.$set = modifier.$set || {};
+ modifier.$set.modifiedAt = Date.now();
+});
+
Swimlanes.hookOptions.after.update = { fetchPrevious: false };
if (Meteor.isServer) {
Meteor.startup(() => {
+ Swimlanes._collection._ensureIndex({ modifiedAt: -1 });
Swimlanes._collection._ensureIndex({ boardId: 1 });
});
@@ -239,18 +286,21 @@ if (Meteor.isServer) {
});
Swimlanes.before.remove(function(userId, doc) {
- const lists = Lists.find({
- boardId: doc.boardId,
- swimlaneId: {$in: [doc._id, '']},
- archived: false,
- }, { sort: ['sort'] });
+ const lists = Lists.find(
+ {
+ boardId: doc.boardId,
+ swimlaneId: { $in: [doc._id, ''] },
+ archived: false,
+ },
+ { sort: ['sort'] }
+ );
if (lists.count() < 2) {
lists.forEach((list) => {
list.remove();
});
} else {
- Cards.remove({swimlaneId: doc._id});
+ Cards.remove({ swimlaneId: doc._id });
}
Activities.insert({
@@ -287,22 +337,23 @@ if (Meteor.isServer) {
* @return_type [{_id: string,
* title: string}]
*/
- JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes', function (req, res) {
+ JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes', function(req, res) {
try {
const paramBoardId = req.params.boardId;
- Authentication.checkBoardAccess( req.userId, paramBoardId);
+ Authentication.checkBoardAccess(req.userId, paramBoardId);
JsonRoutes.sendResult(res, {
code: 200,
- data: Swimlanes.find({ boardId: paramBoardId, archived: false }).map(function (doc) {
- return {
- _id: doc._id,
- title: doc.title,
- };
- }),
+ data: Swimlanes.find({ boardId: paramBoardId, archived: false }).map(
+ function(doc) {
+ return {
+ _id: doc._id,
+ title: doc.title,
+ };
+ }
+ ),
});
- }
- catch (error) {
+ } catch (error) {
JsonRoutes.sendResult(res, {
code: 200,
data: error,
@@ -319,17 +370,23 @@ if (Meteor.isServer) {
* @param {string} swimlaneId the ID of the swimlane
* @return_type Swimlanes
*/
- JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes/:swimlaneId', function (req, res) {
+ JsonRoutes.add('GET', '/api/boards/:boardId/swimlanes/:swimlaneId', function(
+ req,
+ res
+ ) {
try {
const paramBoardId = req.params.boardId;
const paramSwimlaneId = req.params.swimlaneId;
- Authentication.checkBoardAccess( req.userId, paramBoardId);
+ Authentication.checkBoardAccess(req.userId, paramBoardId);
JsonRoutes.sendResult(res, {
code: 200,
- data: Swimlanes.findOne({ _id: paramSwimlaneId, boardId: paramBoardId, archived: false }),
+ data: Swimlanes.findOne({
+ _id: paramSwimlaneId,
+ boardId: paramBoardId,
+ archived: false,
+ }),
});
- }
- catch (error) {
+ } catch (error) {
JsonRoutes.sendResult(res, {
code: 200,
data: error,
@@ -346,9 +403,9 @@ if (Meteor.isServer) {
* @param {string} title the new title of the swimlane
* @return_type {_id: string}
*/
- JsonRoutes.add('POST', '/api/boards/:boardId/swimlanes', function (req, res) {
+ JsonRoutes.add('POST', '/api/boards/:boardId/swimlanes', function(req, res) {
try {
- Authentication.checkUserId( req.userId);
+ Authentication.checkUserId(req.userId);
const paramBoardId = req.params.boardId;
const board = Boards.findOne(paramBoardId);
const id = Swimlanes.insert({
@@ -362,8 +419,7 @@ if (Meteor.isServer) {
_id: id,
},
});
- }
- catch (error) {
+ } catch (error) {
JsonRoutes.sendResult(res, {
code: 200,
data: error,
@@ -382,25 +438,29 @@ if (Meteor.isServer) {
* @param {string} swimlaneId the ID of the swimlane
* @return_type {_id: string}
*/
- JsonRoutes.add('DELETE', '/api/boards/:boardId/swimlanes/:swimlaneId', function (req, res) {
- try {
- Authentication.checkUserId( req.userId);
- const paramBoardId = req.params.boardId;
- const paramSwimlaneId = req.params.swimlaneId;
- Swimlanes.remove({ _id: paramSwimlaneId, boardId: paramBoardId });
- JsonRoutes.sendResult(res, {
- code: 200,
- data: {
- _id: paramSwimlaneId,
- },
- });
- }
- catch (error) {
- JsonRoutes.sendResult(res, {
- code: 200,
- data: error,
- });
+ JsonRoutes.add(
+ 'DELETE',
+ '/api/boards/:boardId/swimlanes/:swimlaneId',
+ function(req, res) {
+ try {
+ Authentication.checkUserId(req.userId);
+ const paramBoardId = req.params.boardId;
+ const paramSwimlaneId = req.params.swimlaneId;
+ Swimlanes.remove({ _id: paramSwimlaneId, boardId: paramBoardId });
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: {
+ _id: paramSwimlaneId,
+ },
+ });
+ } catch (error) {
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: error,
+ });
+ }
}
- });
-
+ );
}
+
+export default Swimlanes;