Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.get('/todos/:id', authenticate, (req, res) => {
//get the todo id in todoID
let todoID = req.params.id;
// if the ID is valid not valid, send a message
if (!ObjectID.isValid(todoID)) {
//console.log('Invalid todo ID');
return res.status(400).send({
message : 'InvalidID',
status : 400
});
}
// search for todo with the todo id and the creator
// do not displa todo if the creator id is different
Todo.findOne({
_id : todoID,
_creator : req.user._id
}).then((data) => {
if (!data) {
return res.status(404).send({
message : 'Todo not found',
status : 404
const safeObjectID = (s: string | number | ObjectID) => ObjectID.isValid(s) ? new ObjectID(s) : null;
export declare function emit(k, v);
function normalizeId(id) {
if (ObjectID.isValid(id)) return new ObjectID(id)
return id;
}
async updatePetsOwner(obj, { petID, owner }, context?, info?) {
if (!ObjectID.isValid(owner) || !ObjectID.isValid(petID)) {
throw new ApolloError(WRONG_ID_ERROR);
}
const newOwner = await this.ownerService.changeOwner(petID, owner);
return newOwner.value;
}
setAvailableSlug(product, productId) {
if(product.slug && product.slug.length > 0) {
let newSlug = utils.cleanSlug(product.slug);
let filter = {};
if(productId && ObjectID.isValid(productId)) {
filter._id = { $ne: new ObjectID(productId) }
}
return mongo.db.collection('products').find(filter).project({slug: 1}).toArray()
.then(products => {
while(products.find(p => p.slug === newSlug)) {
newSlug += '-2';
}
product.slug = newSlug;
return product;
})
} else {
return Promise.resolve(product)
}
}
deconstruct: objId => ObjectID.isValid(objId) && [objId.toJSON()],
reconstruct: args => args && new ObjectID(args[0])
deleteAddress(customer_id, address_id) {
if (!ObjectID.isValid(customer_id) || !ObjectID.isValid(address_id)) {
return Promise.reject('Invalid identifier');
}
let customerObjectID = new ObjectID(customer_id);
let addressObjectID = new ObjectID(address_id);
return mongo.db.collection('customers').updateOne({
_id: customerObjectID
}, {
$pull: {
addresses: {
id: addressObjectID
}
}
});
}