本文整理匯總了TypeScript中mongoose.Types類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Types類的具體用法?TypeScript Types怎麽用?TypeScript Types使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Types類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
Account.statics.verifyAccount = function(verificationCode: string, cb) {
//console.log("inside verify account:" + verificationCode);
this.findOne({
'verificationCode': mongoose.Types.ObjectId(verificationCode)
},
'username',
(err, user) => {
if (user != null) {
//console.log("User with verificationCode: " + verificationCode);
if (err) {
//console.log("findUserByVerficationCode: " + err);
cb(err, null);
};
user.verificationCode = null;
user.isVerified = true;
user.save(function(saveErr) {
if (saveErr) {
return cb(saveErr);
}
cb(null, user);
});
}else{
cb({error: 'Invalid verification code or verification code no longer valid.'}, null);
}
});
}
示例2: DislikeComentario
export function DislikeComentario(req: express.Request, res: express.Response, next: NextFunction) {
Comentario.findOneAndUpdate({_id: mongoose.Types.ObjectId(req.params.id)}, {$inc : {"dislike" : 1}}).exec(function(err, comentario) {
if (err) return errorHandler.handleError(res, err);
res.json(comentario);
});
}
示例3: getOneTema
export function getOneTema(req: express.Request, res: express.Response, next: NextFunction) {
const tema_id = mongoose.Types.ObjectId(req.params.tema_id);
Tema.findOne({_id: tema_id}).exec(function (err, tema) {
if (err) return next();
res.json(tema);
});
}
示例4:
const results = await Promise.all(users.map(user => {
return Channel.update({
user_id: mongoose.Types.ObjectId(user._id.$oid),
type: CHANNEL_TYPE_MAIN
}, {profileImg: user.profileImg});
//
// return Channel.findOneAndUpdate(
// {
// user_id: mongoose.Types.ObjectId(user._id.$oid),
// type: CHANNEL_TYPE_MAIN
// }, {
// user_id: mongoose.Types.ObjectId(user._id.$oid),
// name: user.username,
// profileImg: user.profileImg
// },
// {
// upsert: true,
// new: true,
// setDefaultsOnInsert: true
// },
// (err, res) => {
// console.log('err', err);
// console.log('res', res);
// // Deal with the response data/error
// });
}));
示例5: function
const decline: TDeclineFunc = async function(this: IFriendshipDocument, declinedUserId) {
if (!this.accepted) {
if (!this.senderId.equals(declinedUserId)) {
throw new WrongUserDeclineFriendshipError();
}
await this.remove();
return null;
}
if (!this.senderId.equals(declinedUserId) && !this.receiverId.equals(declinedUserId)) {
throw new WrongUserDeclineFriendshipError();
}
if (this.receiverId.equals(declinedUserId)) {
this.accepted = false;
await this.save();
return this;
}
this.senderId = this.receiverId;
this.receiverId = mongoose.Types.ObjectId(declinedUserId);
this.accepted = false;
await this.save();
return this;
};
示例6: getCurrentPost
export function getCurrentPost(req: express.Request, res: express.Response, next: NextFunction) {
console.log("ID: " + req.params.postid);
Post.findOne({_id: mongoose.Types.ObjectId(req.params.postid)}).exec(function(error, post) {
if (error) {
return next(); }
res.json(post);
});
}
示例7: function
app.get('/booking', function (req, res) {
Booking.find({ userID: mongoose.Types.ObjectId("53b81a2f034eb5db75ec16ad")}, function (err, booking:any[]) {
if (err) return console.log(err);
res.send(booking);
});
console.log('get booking',req.body);
});
示例8: deletePost
export function deletePost(req: express.Request, res: express.Response, next: NextFunction ) {
Post.deleteOne({_id: mongoose.Types.ObjectId(req.params.postid) }).exec(function(error, post) {
if (error) return next();
return res.json(post);
});
}