mirror of
https://github.com/wekan/wekan.git
synced 2026-02-21 07:24:07 +01:00
Part 3 of ReactiveCache async migration: - Add await before all ReactiveCache.getX() calls - Make functions containing ReactiveCache calls async - Convert forEach/map/filter loops with async callbacks to for...of - Update model helpers, Meteor methods, JsonRoutes handlers - Update collection hooks (.before/.after insert/update/remove) - Update .allow() callbacks to async Files updated across models/ and server/ directories: - Model files: cards, boards, lists, swimlanes, activities, users, checklists, checklistItems, customFields, attachments, integrations, cardComments, settings files, creators, exporters, and more - Server files: publications, methods, notifications, routes, migrations
72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
Triggers = new Mongo.Collection('triggers');
|
|
|
|
Triggers.before.insert((userId, doc) => {
|
|
doc.createdAt = new Date();
|
|
doc.updatedAt = doc.createdAt;
|
|
});
|
|
|
|
Triggers.before.update((userId, doc, fieldNames, modifier) => {
|
|
modifier.$set = modifier.$set || {};
|
|
modifier.$set.updatedAt = new Date();
|
|
});
|
|
|
|
Triggers.allow({
|
|
async insert(userId, doc) {
|
|
return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId));
|
|
},
|
|
async update(userId, doc) {
|
|
return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId));
|
|
},
|
|
async remove(userId, doc) {
|
|
return allowIsBoardAdmin(userId, await ReactiveCache.getBoard(doc.boardId));
|
|
},
|
|
});
|
|
|
|
Triggers.helpers({
|
|
async rename(description) {
|
|
return await Triggers.updateAsync(this._id, {
|
|
$set: { description },
|
|
});
|
|
},
|
|
|
|
description() {
|
|
return this.desc;
|
|
},
|
|
|
|
async getRule() {
|
|
return await ReactiveCache.getRule({ triggerId: this._id });
|
|
},
|
|
|
|
async fromList() {
|
|
return await ReactiveCache.getList(this.fromId);
|
|
},
|
|
|
|
async toList() {
|
|
return await ReactiveCache.getList(this.toId);
|
|
},
|
|
|
|
async findList(title) {
|
|
return await ReactiveCache.getList({
|
|
title,
|
|
});
|
|
},
|
|
|
|
labels() {
|
|
const boardLabels = this.board().labels;
|
|
const cardLabels = _.filter(boardLabels, label => {
|
|
return _.contains(this.labelIds, label._id);
|
|
});
|
|
return cardLabels;
|
|
},
|
|
});
|
|
|
|
if (Meteor.isServer) {
|
|
Meteor.startup(async () => {
|
|
await Triggers._collection.createIndexAsync({ modifiedAt: -1 });
|
|
});
|
|
}
|
|
|
|
export default Triggers;
|