本文整理匯總了TypeScript中meteor/meteor.Meteor.users.update方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Meteor.users.update方法的具體用法?TypeScript Meteor.users.update怎麽用?TypeScript Meteor.users.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類meteor/meteor.Meteor.users
的用法示例。
在下文中一共展示了Meteor.users.update方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
Meteor.startup(function () {
if (Meteor.users.find().fetch().length === 0)
{
var users = [
{name:"Test1",email:"test1@example.com",roles:[]},
{name:"Test2",email:"test2@example.com",roles:[]},
{name:"Test3",email:"test3@example.com",roles:[]},
{name:"Admin",email:"admin@example.com",roles:['admin']}
];
for (var i = 0; i < users.length; i++)
{
console.log(users[i]);
var id = Accounts.createUser({
email: users[i].email,
password: "password",
profile: { name: users[i].name }
});
// email verification
Meteor.users.update({_id: id}, {$set:{'emails.0.verified': true}});
Roles.addUsersToRoles(id, users[i].roles);
}
}
});
示例2: Promise
return new Promise((resolve, reject) => {
Meteor.users.update(
{
opponents: {
$elemMatch: {
poemId: id
}
}
},
{
$pull: {
opponents: {
poemId: id
}
}
},
{
multi: true
}, Meteor.bindEnvironment((err, id) => {
if (err || !Boolean(id)) {
return reject(err);
}
return resolve(id);
})
);
})
示例3: Promise
return new Promise((resolve, reject) => {
if (!userId) {
return reject('user is not authorized');
}
if (!isLiked) {
setter = {
$push: {
liked: {
userId: userId,
poemId: poemId
}
}
}
} else {
setter = {
$pull: {
liked: {
userId: userId,
poemId: poemId
}
},
$push: {
disliked: {
userId: userId,
poemId: poemId
}
}
}
}
return Meteor.users.update({
_id: userId
},
setter,
(err, id) => {
if (err || !Boolean(id)) {
return reject(err);
}
return resolve(id);
}
)
});
示例4: keys
Accounts.onLogin(({ user }) => {
const SKIP_SERVICES = ['resume'];
const WHITELIST_SERVICES = ['facebook'];
if (!user.services) {
return;
}
const verifiedEmails = [];
if (user.verified_emails) {
user.verified_emails
.filter(Boolean)
.forEach((email) => verifiedEmails.push(email));
}
keys(user.services)
.filter((service) => !contains(SKIP_SERVICES, service))
.forEach((serviceName) => {
const service = user.services[serviceName];
if (contains(WHITELIST_SERVICES, serviceName)) {
verifiedEmails.push(service.email);
}
if (service.emails) {
Object.keys(service.emails)
.map((email: string) => service.emails[email] as IServiceEmail)
.filter(({ verified }) => verified)
.map(({ email }) => email)
.forEach((email) => verifiedEmails.push(email));
}
});
Meteor.users.update(user._id, {
$set: { verified_emails: unique(verifiedEmails) }
});
});
示例5:
Meteor.loginWithPassword(username, password, (error) => {
if (typeof error !== 'undefined') {
this.swalService.swal('Warning', error.reason, 'error');
} else {
var user = Meteor.users.findOne(Meteor.userId());
Meteor.users.update(
{
_id: user._id
}, {
$set: {
profile: {
name: user.profile.name,
status: 'online'
}
}
}
);
this.swalService.swal('Info', 'anda berhasil login', 'success');
window.location.href = '/post';
}
});
示例6: initMethods
export function initMethods() {
Meteor.methods({
addChat(receiverId: string): void {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to create a new chat');
check(receiverId, nonEmptyString);
if (receiverId == this.userId) throw new Meteor.Error('illegal-receiver',
'Receiver must be different than the current logged in user');
const chatExists = !!Chats.collection.find({
memberIds: {$all: [this.userId, receiverId]}
}).count();
if (chatExists) throw new Meteor.Error('chat-exists',
'Chat already exists');
const chat = {
memberIds: [this.userId, receiverId]
};
Chats.insert(chat);
},
removeChat(chatId: string): void {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to remove chat');
check(chatId, nonEmptyString);
const chatExists = !!Chats.collection.find(chatId).count();
if (!chatExists) throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');
Messages.remove({chatId});
Chats.remove(chatId);
},
updateProfile(profile: Profile): void {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to create a new chat');
check(profile, {
name: nonEmptyString,
picture: nonEmptyString
});
Meteor.users.update(this.userId, {
$set: {profile}
});
},
addMessage(chatId: string, content: string) {
if (!this.userId) throw new Meteor.Error('unauthorized',
'User must be logged-in to create a new chat');
check(chatId, nonEmptyString);
check(content, nonEmptyString);
const chatExists = !!Chats.collection.find(chatId).count();
if (!chatExists) throw new Meteor.Error('chat-not-exists',
'Chat doesn\'t exist');
return {
messageId: Messages.collection.insert({
senderId: this.userId,
chatId: chatId,
content: content,
createdAt: new Date()
})
}
}
});
}
示例7: function
// 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;
},
示例8:
commonAppUpdateUser:function (user: IUser) {
if (user._id !== this.userId) {
throw new Meteor.Error("403-profile-update-for-wrong-user", "Only the user can update his/her own profile.");
}
return Meteor.users.update({_id: user._id}, {$set: user}); // TODO: Check into whether this has the necessary dupe checks, or if they need to be done here
}