How to use meteor - 10 common examples

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 meteor / simple-todos-react / imports / api / tasks.tests.js View on Github external
describe('methods', () => {
      const userId = Random.id();
      let taskId;

      beforeEach(() => {
        Tasks.remove({});
        taskId = Tasks.insert({
          text: 'test task',
          createdAt: new Date(),
          owner: userId,
          username: 'tmeasday',
        });
      });

      it('can delete owned task', () => {
        // Find the internal implementation of the task method so we can
        // test it in isolation
        const deleteTask = Meteor.server.method_handlers['tasks.remove'];
github meteor / todos / imports / api / generate-data.app-tests.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Factory } from 'meteor/dburles:factory';
import { resetDatabase } from 'meteor/xolvio:cleaner';
import { Random } from 'meteor/random';
import { _ } from 'meteor/underscore';

import { denodeify } from '../utils/denodeify';

const createList = (userId) => {
  const list = Factory.create('list', { userId });
  _.times(3, () => Factory.create('todo', { listId: list._id }));
  return list;
};

Meteor.methods({
  generateFixtures() {
    resetDatabase();

    // create 3 public lists
    _.times(3, () => createList());

    // create 3 private lists
    _.times(3, () => createList(Random.id()));
  },
});

if (Meteor.isClient) {
  // Create a second connection to the server to use to call test data methods
  // We do this so there's no contention w/ the currently tested user's connection
  const testConnection = Meteor.connect(Meteor.absoluteUrl());
github berkmancenter / question_tool / server / methods.tests.js View on Github external
/* eslint-env mocha  */
/* eslint-disable prefer-arrow-callback, func-names, camelcase */

import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { Accounts } from 'meteor/accounts-base';
import { assert } from 'chai';
import { resetDatabase } from 'meteor/xolvio:cleaner';
import { Instances, Questions, Answers, Votes } from '/lib/common.js';
import './methods.js';

if (Meteor.isServer) {
  describe('Methods', function () {
    const test_admin = {
      email: 'admin@admins.us',
      password: Random.hexString(10),
      profile: {
        name: 'Ms. Admin',
      },
    };

    const test_mod = {
      email: 'mod@mods.us',
      password: Random.hexString(10),
      profile: {
        name: 'Mod McMod',
      },
    };
github srtucker22 / glipchat / server / streams / room.stream.js View on Github external
roomStream.on('join', function(roomId) {
  check(roomId, String);
  // eslint-disable-next-line no-console
  console.log('join', roomId, this.userId);
  const self = this;

  // notify everyone in the room that the peer has connected
  const room = Rooms.findOne({ _id: roomId });

  // don't let connected users add connection in different browser or tab
  if (_.contains(room.connected, self.userId)) {
    roomStream.emit(self.userId, {
      room: roomId,
      type: 'error.duplicate',
      error: {
        status: 409,
        description: 'Conflict: user is already connected to this room',
      },
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 4minitz / 4minitz / imports / collections / minutes_private.js View on Github external
// Make sure the user is logged in before changing collections
        if (!Meteor.userId()) {
            throw new Meteor.Error('not-authorized');
        }

        // Ensure user is moderator before sending the agenda
        let userRoles = new UserRoles(Meteor.userId());
        let aMin = new Minutes(id);
        if (userRoles.isModeratorOf(aMin.parentMeetingSeriesID())) {
            if (!GlobalSettings.isEMailDeliveryEnabled()) {
                console.log('Skip sending mails because email delivery is not enabled. To enable email delivery set enableMailDelivery to true in your settings.json file');
                throw new Meteor.Error('Cannot send agenda', 'Email delivery is not enabled in your 4minitz installation.');
            }

            if (!Meteor.isClient) {
                let emails = Meteor.user().emails;
                let senderEmail = (emails && emails.length > 0)
                    ? emails[0].address
                    : GlobalSettings.getDefaultEmailSenderAddress();
                let sendAgendaMailHandler = new SendAgendaMailHandler(senderEmail, aMin);
                sendAgendaMailHandler.send();

                MinutesSchema.update({_id: aMin._id, isFinalized: false}, {$set: {agendaSentAt: new Date()}});

                return sendAgendaMailHandler.getCountRecipients();
            }
        } else {
            throw new Meteor.Error('Cannot send agenda', 'You are not moderator of the parent meeting series.');
        }
    },
github 4minitz / 4minitz / imports / collections / minutes_private.js View on Github external
'minutes.updateTopic'(topicId, doc) {
        check(topicId, String);
        console.log(`updateTopic: ${topicId}`);

        // Make sure the user is logged in before changing collections
        if (!Meteor.userId()) {
            throw new Meteor.Error('not-authorized', 'You are not authorized to perform this action.');
        }

        doc.updatedAt = new Date();
        doc.updatedBy = User.PROFILENAMEWITHFALLBACK(Meteor.user());

        let modifierDoc = {};
        for (let property in doc) {
            if (doc.hasOwnProperty(property)) {
                modifierDoc['topics.$.' + property] = doc[property];
            }
        }

        let minDoc = MinutesSchema.findOne({isFinalized: false, 'topics._id': topicId});
        let aMin = new Minutes(minDoc);

        // Ensure user can not update documents of other users
        let userRoles = new UserRoles(Meteor.userId());
        if (userRoles.isModeratorOf(aMin.parentMeetingSeriesID())) {
            // Ensure user can not update finalized minutes
github forbole / big_dipper / imports / ui / proposals / Proposal.jsx View on Github external
componentDidUpdate(prevProps){
        if (this.props.proposal != prevProps.proposal){
            // console.log(this.props.proposal.value);
            this.setState({
                proposal: this.props.proposal,
                deposit: <div>{this.props.proposal.total_deposit?this.props.proposal.total_deposit.map((deposit, i) =&gt; {
                    return <div>{new Coin(deposit.amount).toString()}</div>
                }):''} </div>
            });

            let now = moment();
            const powerReduction = Meteor.settings.public.powerReduction || Meteor.settings.public.stakingFraction;
            let totalVotingPower = this.props.chain.activeVotingPower * powerReduction;
            if (this.props.proposal.voting_start_time != '0001-01-01T00:00:00Z'){
                if (now.diff(moment(this.props.proposal.voting_start_time)) &gt; 0){
                    let endVotingTime = moment(this.props.proposal.voting_end_time);
                    if (now.diff(endVotingTime) &lt; 0){
                        // not reach end voting time yet
                        let totalVotes = 0;
                        for (let i in this.props.proposal.tally){
                            totalVotes += parseInt(this.props.proposal.tally[i]);
                        }

                        this.setState({
                            tally: this.props.proposal.tally,
                            tallyDate: ,
                            voteStarted: true,
                            voteEnded: false,
github zencrepes / zencrepes / imports / ui / data / utils / ingestIssue.js View on Github external
issueObj['points'] = points;
      } else if (pointsExp.test(currentLabel.node.description)) {
        let points = parseInt(currentLabel.node.description.replace('SP:', ''));
        issueObj['points'] = points;
      } else if (
        Meteor.settings.public.labels.effort !== undefined &&
        Meteor.settings.public.labels.effort[currentLabel.node.name] !==
          undefined &&
        Number.isInteger(
          Meteor.settings.public.labels.effort[currentLabel.node.name]
        )
      ) {
        // Interesting edge case, if the label is actually named "constructor"
        // Added this check: Number.isInteger(Meteor.settings.public.labels.effort[currentLabel.node.name])
        issueObj['points'] = parseInt(
          Meteor.settings.public.labels.effort[currentLabel.node.name]
        );
        /*
                if (Meteor.settings.public.labels.effort !== undefined) {
                    const pointsLabel = pointsLabelExp.exec(currentLabel.node.name);
                    const efforts = Meteor.settings.public.labels.effort;
                    if (efforts[pointsLabel.groups.name] !== undefined) {
                        issueObj['points'] = efforts[pointsLabel.groups.name];
                    }
                }
                */
      }
      if (boardExp.test(currentLabel.node.description)) {
        const boardLabel = boardExp.exec(currentLabel.node.description);
        issueObj['boardState'] = {
          name: boardLabel.groups.name,
          priority: boardLabel.groups.priority,