How to use the meteor/meteor.Meteor.publish function in meteor

To help you get started, we’ve selected a few meteor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleverbeagle / pup / api / Documents / server / publications.js View on Github external
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import Documents from '../Documents';

Meteor.publish('documents', function documents() {
  return Documents.find({ owner: this.userId });
});

// Note: documents.view is also used when editing an existing document.
Meteor.publish('documents.view', (documentId) => {
  check(documentId, String);
  return Documents.find({ _id: documentId });
});

Meteor.publish('documents.edit', function documentsEdit(documentId) {
  check(documentId, String);
  return Documents.find({ _id: documentId, owner: this.userId });
});
github soulmachine / meteor-tutorial / imports / api / notifications.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';

export const Notifications = new Mongo.Collection('notifications');
export const NotificationTotalCounters = new Mongo.Collection('notification_total_counters');
export const NotificationUnreadCounters = new Mongo.Collection('notification_unread_counters');

if (Meteor.isServer) {
  Meteor.publish('notifications', function(skipCount) {
    console.log("skipCount: ", skipCount);
    return Notifications.find({owner: this.userId},
      {sort: {createdAt : -1}, skip: skipCount, limit: parseInt(Meteor.settings.public.recordsPerPage)});
  });
  Meteor.publish('notification_total_counters', function() {
    return NotificationTotalCounters.find({owner: this.userId});
  });
  Meteor.publish('notification_unread_counters', function() {
    return NotificationUnreadCounters.find({owner: this.userId});
  });

  // Initialize counters
  const allNotifications = Notifications.find({}, {fields: {owner: 1, isRead: 1}}).fetch();
  const groupBy = {};
  allNotifications.forEach(function(x, i){
    if (x.owner in groupBy) groupBy[x.owner].push(x);
    else groupBy[x.owner] = [x];
  });

  for (var userId in groupBy) {
    NotificationTotalCounters.update(
github apinf / platform / api_catalog / server / publications.js View on Github external
You may obtain a copy of the licence at
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

// Meteor packages imports
import { Meteor } from 'meteor/meteor';

// Collection imports
import ApiBackendRatings from '/ratings/collection';
import ApiBookmarks from '/bookmarks/collection';

Meteor.publish('catalogueRatings', () => {
  // Find all API Backends
  return ApiBackendRatings.find();
});

Meteor.publish('catalogueBookmarks', () => {
  // Find all API Backends
  return ApiBookmarks.find();
});
github espinr / activioty / controller / app / imports / api / messages / server / publications.js View on Github external
// All mqtt-messages-related publications

import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { Messages } from '../messages.js';

Meteor.publish('messages.all', function () {
  //check(query, Match.OneOf(String, null, undefined));
  return Messages.find();
});
github apinf / platform / organizations / collection / server / publications.js View on Github external
This file is covered by the EUPL license.
You may obtain a copy of the licence at
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

// Meteor packages imports
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

// Meteor contributed packages imports
import { Counts } from 'meteor/tmeasday:publish-counts';

// Collection imports
import OrganizationApis from '/organization_apis/collection';
import Organizations from '../';

Meteor.publish('allOrganizationBasicDetails', () => {
  return Organizations.find({},
    {
      fields: {
        _id: 1,
        name: 1,
        description: 1,
        contact: 1,
      },
    });
});

// Publish collection for pagination
// TODO: Determine if there is a better way to handle pagination
// eslint-disable-next-line no-new
new Meteor.Pagination(Organizations);
github Blockrazor / blockrazor / imports / api / ratings / server / publications.js View on Github external
import { Meteor } from 'meteor/meteor'
import { EloRankings, Ratings, RatingsTemplates } from '/imports/api/indexDB.js'

Meteor.publish('elorankings', function elorankingsPublication() {
  return EloRankings.find({});
});

Meteor.publish('ratings', function ratingsPublication() {
return Ratings.find({owner: this.userId});
})

Meteor.publish('ratings_templates', function ratings_templatesPublication() {
  return RatingsTemplates.find();
  })

Meteor.publish('addCoinQuestions', () => RatingsTemplates.find({
  context: 'add-currency'
})
);

// ['codebase', 'community', 'wallet'].forEach(type => { // this doesn't work with fastrender
	Meteor.publish(`bountyRating`, () => {
		return Ratings.find({}, {
	        sort: {
	            answeredAt: -1
	        },
	        fields: {
	        	context: 1,
	        	catagory: 1,
	        	answeredAt: 1
	        }
	    })
github DemocracyEarth / sovereign / imports / api / server / publications.js View on Github external
if (feed) {
      return feed;
    }
  } else {
    _log += ' } }';
    log(_log);
  }
  return this.ready();
});


/**
* @summary total number of items on a given feed
* @return {Object} querying terms
*/
Meteor.publish('feedCount', function (terms) {
  check(terms, Object);
  const parameters = query(terms);
  log(`{ publish: 'feedCount', user: ${logUser()}, terms: ${JSON.stringify(terms)}`);
  Counts.publish(this, 'feedItems', Contracts.find(parameters.find, parameters.options));
});

/**
* @summary gets a single contract
* @return {Object} querying terms
*/
Meteor.publish('singleContract', function (terms) {
  check(terms, Object);
  const parameters = query(terms);
  log(`{ publish: 'singleContract', user: ${logUser()}, { contractId: '${terms.contractId}' }`);
  return Contracts.find(parameters.find, parameters.options);
});
github remotebase / remotebase-mantra / server / publications / companies.js View on Github external
export default function () {
  Meteor.publish('companies', function (query, limit) {
    check(query, Object);
    check(limit, Match.Optional(Number));

    query['hidden'] = {$ne: true};

    let option = {sort: {official: -1, name: 1}};

    if (limit) {
      option.limit = limit;
    }

    Counts.publish(this, 'companies-counter', Companies.find(query), {noReady: true});
    return Companies.find(query, option);
  });

  Meteor.publish('company', function (slug) {
github CommonGarden / Grow-IoT / imports / api / events / publish.js View on Github external
}
  });

  if (!thing) { throw new Meteor.Error('not-found', `Thing '${thingUuid}' cannot be found.`); }

  return Events.find(
    {'thing._id': thing._id}
  , {
    'sort': {
      'insertedAt': -1
    },
    'limit': 100
  });
});

Meteor.publish('Events.byThingAndType', function(thingUuid, type) {
  check(thingUuid, String);
  check(type, String);

  let thing = Things.findOne(
    {
      'uuid': thingUuid,
      'owner': this.userId
    }
  , {
    fields: {
      _id: 1
    }
  });

  if (!thing) { throw new Meteor.Error('not-found', `Thing '${thingUuid}' cannot be found.`); }
github dotgreg / XinDaw / imports / api / songs.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
import { random, filter, uniq, each } from 'lodash';

import {Sounds} from './sounds';

export const Songs = new Mongo.Collection('songs');

if (!Meteor.isServer) return false

Meteor.publish('songs', () => Songs.find())

Meteor.methods({
  'helloworld' () {
    return `helloworld-${random(10000)}`
  },
  'songs.insert'() {
    Songs.insert({
      'name': `song-${random(10000)}`,
      'selected': false,
      'selectedSound': false,
      'sounds': [],
      'createdAt': new Date()
    });
  },

  'songs.remove'(songId) {