當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。