export function initPublications() {
  Meteor.publish('users', function(): Mongo.Cursor<User> {
    if (!this.userId) return;

    return Users.collection.find({}, {
      fields: {
        profile: 1
      }
    });
  });

  Meteor.publish('messages', function(chatId: string): Mongo.Cursor<Message> {
    if (!this.userId) return;
    if (!chatId) return;

    return Messages.collection.find({chatId});
  });

  Meteor.publishComposite('chats', function() {
    if (!this.userId) return;

    return {
      find: () => {
        return Chats.collection.find({memberIds: this.userId});
      },

      children: [
        {
          find: (chat) => {
            return Messages.collection.find({chatId: chat._id}, {
              sort: {createdAt: -1},
              limit: 1
            });
          }
        },
        {
          find: (chat) => {
            return Users.collection.find({
              _id: {$in: chat.memberIds}
            }, {
              fields: {profile: 1}
            });
          }
        }
      ]
    };
  });
}
export default function () {
  Meteor.publish('posts.list', function () {
    const selector = {};
    const options = {
      fields: {_id: 1, title: 1},
      sort: {createdAt: -1},
      limit: 10
    };

    return Posts.find(selector, options);
  });

  Meteor.publish('posts.single', function (postId: string) {
    check(postId, String);
    const selector = {_id: postId};
    return Posts.find(selector);
  });

  Meteor.publish('posts.comments', function (postId: string) {
    check(postId, String);
    const selector = {postId};
    return Comments.find(selector);
  });
}
import {Orders} from '../collections/orders';
import {Meteor} from 'meteor/meteor';

Meteor.publish('orders', function() {
   // return Orders.find();
    return Orders.find({

                $and: [
                    { owner: this.userId },
                    { owner: { $exists: true } }
                ]
    });
});
Example #4
0
import {Meteor} from 'meteor/meteor';
import {Users} from './../../collections/users';
import {Counts} from 'meteor/tmeasday:publish-counts';
import * as Helpers from "./../../lib/helpers";

Meteor.publish("users.all", function(options: Object) {
    Counts.publish(this, "users.total", Users.find({}), { noReady: true });
    let secure = {
        fields: {
            "emails.address": 1,
            "createdAt": 1,
            "profile": 1
        }
    }
    options = Helpers.mergeOptions(options, secure);
    return Users.find({}, options);
});

Meteor.publish("users.detail", function(id: string) {
    return Users.find({ _id: id });
});
import {Meteor} from 'meteor/meteor';
import {GamificationGrid, GamificationRecords} from './collection';


Meteor.publish('gamification.records', function () {
    console.log('publishing records')
    return GamificationRecords.find({
        user_id: this.userId
    });
});

Meteor.publish('gamification.grid', function() {
    console.log('publishing grid')
    return GamificationGrid.find({
        user_id: this.userId
    });
});
import { Meteor } from 'meteor/meteor';

Meteor.publish('users', () => {
  return Meteor.users.find({}, {
    fields: {
      username: 1,
      profile: 1
    }
  });
});
Example #7
0
import { Activity } from '../../../both/collections/activity.collection';
import { Meteor } from 'meteor/meteor';

Meteor.publish("activity", function() {
  return Activity.find({public:true});
});
Example #8
0
import {Tasks} from '../collections/tasks';
import {Meteor} from 'meteor/meteor';


  Meteor.publish('tasks', function tasksPublication() {
  return Tasks.find({owner: this.userId}); // find only user tasks
});



Meteor.publish('task', function(taskId: string) {
  return Tasks.find(
    {
      $and: [{  // find with given task id
          '_id': {
            $eq: taskId
          }
        }, { // find only if the owner access the task
          'owner': this.userId
        }, ],
      }
);

});
Example #9
0
import { Meteor } from 'meteor/meteor';
import { Counts } from 'meteor/tmeasday:publish-counts';

import { Poems } from '../../../both/collections/poems.collection';
import { PoemFilter } from '../../../both/filters/poem-filter';
import { Options } from '../../../both/filters/pagination';

Meteor.publish('poems', function(options: Options, filter?: PoemFilter) {
    // Publish total count
    Counts.publish(
        this,
        'numberOfPoems',
        Poems.collection.find(buildQuery.call(this, filter)),
        { noReady: true });

    // Return filtered poems
    return Poems.find(buildQuery.call(this, filter), options);
});

function buildQuery(filter?: PoemFilter): Object {
    const completeQuery = {
        // All users (even anonymous) can see completed poems
        isComplete: true
    };

    // Base query for poem permissions
    const baseQuery = this.userId
        ? { 
            $or: [completeQuery, {
                lastContributorId: {
                    // Logged in users can edit poems for which they're
Example #10
0
import {Parties} from '../collections/parties';
import {Meteor} from 'meteor/meteor';

Meteor.publish('uninvited', function(partyId: string) {
    let party = Parties.findOne(partyId);

    if (!party)
        throw new Meteor.Error('404', 'No such party!');

    return Meteor.users.find({
        _id: {
            $nin: party.invited || [],
            $ne: this.userId
        }
    });
});