External links
Category:Electronics magazines
Category:Magazines established in 2001
Category:American monthly magazinesQ:
Mocking "in" for Jest
I have some code in a controller that looks like this:
exports.createEvent = async (req, res) => {
const authUser = await getUserAuthByToken(req.headers.authorization);
await Event.findOne({ user: authUser, date: req.body.date })
.then((event) => {
req.body.event = event;
res.status(201).json({
token: jwt_token,
user: authUser,
event: event
})
});
}
The Event model has the following relationship:
const eventSchema = mongoose.Schema({
eventId: { type: mongoose.Schema.Types.ObjectId, ref: 'event' },
title: { type: String, required: true },
description: { type: String, required: true },
date: { type: Date, default: Date.now },
user: { type: mongoose.Schema.Types.ObjectId, ref: 'user' },
location: { type: String },
notes: { type: String },
published: { type: Boolean, default: false }
});
and the getUserAuthByToken function is as follows:
const getUserAuthByToken = (token) => {
return new Promise((resolve, reject) => {
AuthUser.findOne({ authTokens: { $elemMatch: { token: token } } }, function (err, user) {
if (err) {
return reject(err); ac619d1d87
Related links:
Comments