本文整理汇总了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");
}
});
});
示例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}
});
}
})
示例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};
}
},
//
});
示例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;
}
}
});
示例5: simpanPost
import { Posts } from './posts';
import { Meteor } from 'meteor/meteor';
Meteor.methods({
simpanPost(post) {
Posts.insert(post);
},
hapusPost(post) {
Posts.remove(post);
}
});
示例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 } } });
}
}
});
示例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) {
示例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);
},
});
示例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);
},
});
示例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;