本文整理匯總了TypeScript中meteor/check.check函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript check函數的具體用法?TypeScript check怎麽用?TypeScript check使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了check函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
setComment: function(id: string, comment: string) {
check(comment, String);
check(id, String);
comment = comment.replace(/[^\w\s]/gi, '');
let character = Characters.findOne({
uid: this.userId
});
if (!character) {
throw new Meteor.Error("error", "The server does not know about your character.");
}
let fit = _.findWhere(character.fits, {
fid: id,
});
if (!fit) {
throw new Meteor.Error("error", "Can't find that fit in your fits.");
}
return Characters.update({
_id: character._id,
"fits.fid": id
}, {
$set: {
"fits.$.comment": comment
}
});
},
示例2: function
addMessageTask: function (taskId: string, message: string) {
check(taskId, String);
check(message, String);
if (!message.length || message.length < 3) {
throw new Meteor.Error('400', 'message-to-short');
}
if (message.length > 1024) {
throw new Meteor.Error('400', 'message-to-long');
}
// verif user & task
let user = Meteor.user();
if (!user) {
throw new Meteor.Error('403', 'not-authorized');
}
let task = Tasks.find({
_id: taskId,
$or: [
{ owner: this.userId },
{ 'targets.userId': this.userId }
]
});
if (!task) {
throw new Meteor.Error('403', 'not-authorized');
}
Tasks.update(taskId, {
$push: {
conversation: {
message: message,
createdAt: new Date(),
owner: user._id,
ownerEmail: user.emails[0].address
}
}
});
},
示例3: check
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!');
}
});
},
示例4: function
invite: function (trackId:string, userId:string) {
check(trackId, String);
check(userId, String);
let track = Tracks.collection.findOne(trackId);
if (!track)
throw new Meteor.Error('404', 'No such track!');
if (track.public)
throw new Meteor.Error('400', 'That track is public. No need to invite people.');
if (track.owner !== this.userId)
throw new Meteor.Error('403', 'No permissions!');
if (userId !== track.owner && (track.invited || []).indexOf(userId) == -1) {
Tracks.collection.update(trackId, {$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@beetrut.com',
to: to,
replyTo: from || undefined,
subject: 'TRACK: ' + track.name,
text: `Hi, I just invited you to ${track.name} on Beetrut.
\n\nCome check it out: ${Meteor.absoluteUrl()}\n`
});
}
}
},
示例5: function
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`
});
}
}
},
示例6: function
foo: function (arg1: string, arg2: number[]) {
check(arg1, String);
check(arg2, [Number]);
var you_want_to_throw_an_error = true;
if (you_want_to_throw_an_error)
throw new Meteor.Error("404", "Can't find my pants");
return "some return value";
},
示例7: constructor
constructor(
hCurObserver: Meteor.LiveQueryHandle,
hAutoNotify?: Tracker.Computation) {
check(hAutoNotify, Match.Optional(Tracker.Computation));
check(hCurObserver, Match.Where(function(observer) {
return !!observer.stop;
}));
this._hAutoNotify = hAutoNotify;
this._hCurObserver = hCurObserver;
}
示例8: function
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(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!'); // It's private but let's not tell user that
}
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}}
});
}
}
示例9: function
sendAnswer: function (ticket: Ticket) {
check(ticket._id, String);
check(ticket.nbTokensToGive, Number);
check(ticket.answerComment, String);
Tickets.update(ticket._id, {
$set: {
nbTokensToGive: ticket.nbTokensToGive,
answerComment: ticket.answerComment
}
});
//TODO : send an email
}