本文整理汇总了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
}