当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Meteor.methods方法代码示例

本文整理汇总了TypeScript中meteor/meteor.Meteor.methods方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Meteor.methods方法的具体用法?TypeScript Meteor.methods怎么用?TypeScript Meteor.methods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在meteor/meteor.Meteor的用法示例。


在下文中一共展示了Meteor.methods方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createJobs

Meteor.startup(function () {
    createJobs();
    createUsers();

    var filepath = '/Users/michaelbattcock/Desktop/test.txt';

    Meteor.methods({
      'writeFileTest': function () {
        console.log('write file test success!');
        fs.writeFileSync('/Users/michaelbattcock/Desktop/test.txt', "HelloWorld");
      }
    });
});
开发者ID:michaelb-01,项目名称:pipe-meteor,代码行数:13,代码来源:main.ts

示例2: Message

Meteor.methods({
	// CREATES A NEW CONVERSATION
	createNewConversation:function(title:string, sender:string, recipient:string, message:string){
		check(title, String); check(sender, String); check(recipient, String); check(message, String);
		var dateCreated = moment().format('MMMM Do YYYY, h:mm:ss a');

		var first = Users.find({"_id":sender}).fetch()[0].profile.firstname;
		var last = Users.find({"_id":sender}).fetch()[0].profile.lastname;
		var senderName = first + " " + last;

		ConversationStreams.insert({
			title:title,
			created: dateCreated,
			subscribers:[
			{'user':sender, 'unread':0, 'subscribed':1},
			{'user':recipient, 'unread':1, 'subscribed':1}
			],
			messages:[
			new Message(dateCreated, senderName, message)
			]
		}, (err, insertionID)=>{
			if(err){
					// message insertion failed
					console.log(err);
				}else{
					// Insert new conversation reference in the users subscriptions
					updateUserSubscription(sender, insertionID, 'sender');
					updateUserSubscription(recipient, insertionID, 'recipient');
					// console.log('maybe we got it right!');
				}
			});
	},



	// SENDS A MESSAGE
	sendMessage:function(conversationID:string, sender:string, message:string){
		check(conversationID, String); check(sender, String); check(message, String);
		var sent = moment().format('MMMM Do YYYY, h:mm:ss a');
		var senderName = getSenderName(sender);
		var recipientList = getRecipient(conversationID, sender);
		updateUnread(conversationID, recipientList);
		
		// insert message into ConversationStream
		ConversationStreams.update({"_id":conversationID}, {$addToSet:{
			'messages':new Message(sent, senderName, message)
		}});

		// insert conversation into recipient if they have deleted it
		for(var i = 0; i < recipientList.length; i++){
			if(recipientList[i] != Meteor.userId()){
				var convSubsID = Users.find({'_id':recipientList[i]}).fetch()[0].profile.conversationSubs;
				ConversationSubscriptions.update({'_id':convSubsID}, {$addToSet: {
					'conversations':conversationID
				}});
			}
		}
	},



	// Delete Conversation
	deleteConversation:function(conversationID:string, conversationStreamID:string){
		// unsubscribe user in conversationStream
		unsubscribeConversation(conversationStreamID);
		// delete subscription from user conversationSubscriptions
		var userConvSubs = Users.find({'_id':Meteor.userId()}).fetch()[0].profile.conversationSubs;
		ConversationSubscriptions.update({'_id':userConvSubs}, {$pull : {
			conversations : conversationID
		}});
	},


	//Clear conversation unread count
	clearConversationUnread:function(conversationStreamID:string){
		//ConversationsStream Level
		var subscribers = ConversationStreams.find({'_id':conversationStreamID}).fetch()[0].subscribers;
		var unread = 0;
		for(var i = 0; i < subscribers.length; i++){
			if(subscribers[i].user == Meteor.userId()){
				unread = subscribers[i].unread;
			}
		}
		// Clear ConversationStream Level
		ConversationStreams.update({'_id':conversationStreamID, 'subscribers':{$elemMatch: {'user':Meteor.userId()}}}, {
			$set : {'subscribers.$.unread':0}
		});

		// ConversationSubscription Level
		// Decrease the unread counter by the number of unread messages in the opened conversation
		var conversationSubsID = Users.find({'_id':Meteor.userId()}).fetch()[0].profile.conversationSubs;
		unread *= -1; // Make the unread value negative
		ConversationSubscriptions.update({'_id':conversationSubsID}, {
			$inc : {'unread':unread}
		});

	}
})
开发者ID:gab3alm,项目名称:lemonaidev3,代码行数:98,代码来源:conversation-methods.ts

示例3: function

Meteor.methods({
  // Create new task in the given ProjectStream
  createNewTask: function(streamID:string, title:string, duedate:string, description:string){
    var now = new Date().toString();
    var assigner = getName(Meteor.userId());
    var task = new Task(now, assigner, title, description, duedate);
    ProjectsStream.update({'_id':streamID}, {$addToSet:{
      'pending': task
    }});
  },

  // Changes Project Visibility Field (public field)
  changeProjectVisibility: function(projectID:string, visibility:boolean){
    ProjectsStream.update({'_id':projectID}, {$set: {
      'public':visibility
    }});
  },

  checkProjectVisibility: function(projectID:string){
    // get the visibility of the project
    var visibility = ProjectsStream.find({'_id':projectID}).fetch()[0].public;
    if(!visibility){
      // Get array of all users allowed into the project
      var exceptions = ProjectsStream.find({'_id':projectID}).fetch()[0].allowed;
      if(exceptions.indexOf(Meteor.userId()) != -1){
        // user was found on list
        return {permission:true};
      }else{
        // user was not found on list
        return {permission:false};
      }
    }else{
      // Project visibility is open to everyone
      return {permission:true};
    }
  },

  // 

});
开发者ID:gab3alm,项目名称:lemonaidev3,代码行数:40,代码来源:project-methods.ts

示例4: function

import { Meteor } from 'meteor/meteor';
import { course_search } from './search.ts'

Meteor.methods({
  'search_courses': function(text: string, results_per_page: number, page_no: number) {
    var courseAsync = Meteor.wrapAsync(course_search);
    var result;
    var error;
    courseAsync(text, results_per_page, page_no, function(res, err) {
      if(err) {
        result = null;
        error = err;
      }
      else {
        result = res;
        error = null;
      }
    });
    if(error) {
      throw new Meteor.Error("Search Error");
    }
    else {
      return result;
    }
  }
});
开发者ID:cemersoz,项目名称:tuxlab-app,代码行数:26,代码来源:methods.ts

示例5: simpanPost

import { Posts } from './posts';
import { Meteor } from 'meteor/meteor';

Meteor.methods({
  simpanPost(post) {
    Posts.insert(post);
  },
  hapusPost(post) {
    Posts.remove(post);
  }
});
开发者ID:RizkiMufrizal,项目名称:Socially-Angular2-Meteor,代码行数:11,代码来源:methods.ts

示例6: function

Meteor.methods({
  invite: function (partyId:string, userId:string) {
    check(partyId, String);
    check(userId, String);
 
    let party = Parties.findOne(partyId);
 
    if (!party)
      throw new Meteor.Error('404', 'No such party!');
 
    if (party.public)
      throw new Meteor.Error('400', 'That party is public. No need to invite people.');
 
    if (party.owner !== this.userId)
      throw new Meteor.Error('403', 'No permissions!');
 
    if (userId !== party.owner && (party.invited || []).indexOf(userId) == -1) {
      Parties.update(partyId, {$addToSet: {invited: userId}});
 
      let from = getContactEmail(Meteor.users.findOne(this.userId));
      let to = getContactEmail(Meteor.users.findOne(userId));
 
      if (Meteor.isServer && to) {
        Email.send({
          from: 'noreply@socially.com',
          to: to,
          replyTo: from || undefined,
          subject: 'PARTY: ' + party.name,
          text: `Hi, I just invited you to ${party.name} on Socially.
                        \n\nCome check it out: ${Meteor.absoluteUrl()}\n`
        });
      }
    }
  },
  reply: function(partyId: string, rsvp: string) {
    check(partyId, String);
    check(rsvp, String);

    if (!this.userId)
      throw new Meteor.Error('403', 'You must be logged-in to reply');
 
    if (['yes', 'no', 'maybe'].indexOf(rsvp) === -1)
      throw new Meteor.Error('400', 'Invalid RSVP');
 
    let party = Parties.findOne({ _id: partyId });
 
    if (!party)
      throw new Meteor.Error('404', 'No such party');
 
    if (party.owner === this.userId)
      throw new Meteor.Error('500', 'You are the owner!');
 
    if (!party.public && (!party.invited || party.invited.indexOf(this.userId) == -1))
      throw new Meteor.Error('403', 'No such party'); // its private, but let's not tell this to the user
 
    let rsvpIndex = party.rsvps ? party.rsvps.findIndex((rsvp) => rsvp.userId === this.userId) : -1;
 
    if (rsvpIndex !== -1) {
      // update existing rsvp entry
      if (Meteor.isServer) {
        // update the appropriate rsvp entry with $
        Parties.update(
          { _id: partyId, 'rsvps.userId': this.userId },
          { $set: { 'rsvps.$.response': rsvp } });
      } else {
        // minimongo doesn't yet support $ in modifier. as a temporary
        // workaround, make a modifier that uses an index. this is
        // safe on the client since there's only one thread.
        let modifier = { $set: {} };
        modifier.$set['rsvps.' + rsvpIndex + '.response'] = rsvp;
 
        Parties.update(partyId, modifier);
      }
    } else {
      // add new rsvp entry
      Parties.update(partyId,
        { $push: { rsvps: { userId: this.userId, response: rsvp } } });
    }
  }
});
开发者ID:ElijahWolfe,项目名称:socially,代码行数:80,代码来源:methods.ts

示例7: function

export let Tasks = new MongoObservable.Collection<TodoTask>('tasks');

Meteor.methods({
  'tasks.addTask': function(text: string) {
    Tasks.insert({
      text: text,
      checked: false,
      private: false,
      createdAt: new Date()
    })
  },

  'tasks.deleteTask': function(taskId) {
    Tasks.remove(taskId);
  },

  'tasks.setChecked': function(taskId, setChecked) {
    let task = Tasks.findOne(taskId);
    Tasks.update(taskId, {
      $set: { checked: setChecked }
    });
  },

  'tasks.setPrivate': function(taskId, setToPrivate) {
    let task = Tasks.findOne(taskId);
    Tasks.update(taskId, {
      $set: { private: setToPrivate }
    });
  }
});

if (Meteor.isServer) {
开发者ID:barbatus,项目名称:angular-meteor,代码行数:32,代码来源:tasks.ts

示例8: function

import { Meteor } from 'meteor/meteor';
import {Locales} from '../imports/api/locales';


Meteor.publish('locales', function () {


    return Locales.find({});


});

Meteor.methods({


    'locales.insert'(locale) {
        var self = this;
        Locales.insert(locale);
    },
    'locales.remove'(localeId) {

        Locales.remove(localeId);
    },
    'locales.update'(localeId, action) {
        
        Locales.update(localeId, action);
        
    },


});
开发者ID:admirkb,项目名称:ads,代码行数:31,代码来源:locales.ts

示例9:

    return MediaLibraries.find({ "$and": [{ "heading": search }, { "customerId": customerId }] }, options)


});

// Meteor.publish('mediaLibraries', (options: Object, searchString: string) => {

//     console.log("options")


// }


// );

Meteor.methods({


    'mediaLibraries.insert'(ml) {
        MediaLibraries.insert(ml);
    },
    'mediaLibraries.remove'(mlId) {
        MediaLibraries.remove(mlId);
    },
    'mediaLibraries.update'(mlId, action) {

        MediaLibraries.update(mlId, action);
    },


});
开发者ID:admirkb,项目名称:ads,代码行数:31,代码来源:mediaLibraries.ts

示例10: function

//         console.dir(selector)
//                 console.dir(options)
//     console.log("searchString" + searchString)
//   return Meteor.users.find(selector , options);
// });


Meteor.methods({

    'users.insert'(user) {
        Meteor.users.insert(user);
    },
    'users.remove'(userId) {
        Meteor.users.remove(userId);
    },
    'users.update'(userId, action) {
        Meteor.users.update(userId, action);
    },
    'users.getUsers'() {
        console.log('on server, Meteor.users.find({}) called');
        return Meteor.users.find({}).fetch();
    },

});

Meteor.users.allow({
    insert: function () {
        return true;
    },
    update: function () {
        return true;
开发者ID:admirkb,项目名称:ads,代码行数:31,代码来源:users.ts


注:本文中的meteor/meteor.Meteor.methods方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。