Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request.query = query
const listResult = await _listHandler(childModel, request, Log)
if (manyMany && association.linkingModel) {
// EXPL: we have to manually insert the extra fields into the result
const extraFieldData = result
if (_.isArray(listResult.docs)) {
for (const object of listResult.docs) {
const data = extraFieldData.find(data => {
return (
data[association.model]._id.toString() === object._id.toString()
)
})
if (!data) {
throw Boom.notFound('child object not found')
}
const fields = data.toJSON()
delete fields._id
delete fields[association.model]
object[association.linkingModel] = fields
}
}
try {
if (
ownerModel.routeOptions &&
ownerModel.routeOptions.getAll &&
ownerModel.routeOptions.getAll[associationName] &&
ownerModel.routeOptions.getAll[associationName].post
) {
listResult.docs = await ownerModel.routeOptions.getAll[
if (duplicateIndex < 0) {
// EXPL: if the association doesn't already exist, create it
ownerObject[associationName].push(childId)
}
await Promise.all([
ownerModel.findByIdAndUpdate(ownerObject._id, ownerObject, {
runValidators: config.enableMongooseRunValidators
})
])
} else {
throw Boom.badRequest('Association type incorrectly defined.')
}
} else {
throw Boom.notFound('Child object not found.')
}
}
h: Hapi.ResponseToolkit,
{
filename,
bundleType,
bundleNames,
}: { filename: string; bundleType?: string; bundleNames?: string[] },
result: {
file?: any;
errors: string[];
mimeType: string;
}
) {
if (result.errors) {
return h.response({ errors: result.errors }).code(500);
} else if (!result.file) {
return Boom.notFound(`File ${filename} not found`);
}
let file;
if (bundleType === 'delta') {
// We have a bundle, but RN is expecting a delta bundle.
// Convert full bundle into the simplest delta possible.
// This will load slower in RN, but it won't error, which is
// nice for automated use-cases where changing the dev setting
// is not possible.
file = createDeltaBundle(result.file.toString());
} else {
file =
result.file.type === 'Buffer'
? Buffer.from(result.file.data)
: result.file;
}
if (config.enableSoftDelete && config.filterDeletedEmbeds) {
// EXPL: remove soft deleted documents from populated properties
filterDeletedEmbeds(result, {}, '', 0, Log)
}
if (flatten && $embed) {
flattenEmbeds(result, associations, $embed)
}
}
Log.log('Result: %s', JSON.stringify(result))
return result
} else {
throw Boom.notFound('No resource was found with that id.')
}
} catch (err) {
handleError(err, null, null, Log)
}
}
validate: async () => {
throw Boom.notFound('User not found')
}
})
handler: async function (request, h) {
const id = request.params.id;
const update = {
$set: {
permissions: request.payload.permissions
}
};
const adminGroup = await AdminGroup.findByIdAndUpdate(id, update);
if (!adminGroup) {
throw Boom.notFound('AdminGroup not found.');
}
return adminGroup;
}
});
async handler (request, h) {
const ipfs = request.server.app.ipfs
const { arg } = request.query
let res
try {
res = await ipfs.dht.findPeer(arg)
} catch (err) {
if (err.code === 'ERR_LOOKUP_FAILED') {
throw Boom.notFound(err.toString())
} else {
throw Boom.boomify(err, { message: err.toString() })
}
}
return h.response({
Responses: [{
ID: res.id.toB58String(),
Addrs: res.multiaddrs.toArray().map((a) => a.toString())
}],
Type: 2
})
}
}
module.exports = (req, res, next) => {
next(Boom.notFound());
};
public async showUnconfirmed(request: Hapi.Request, h: Hapi.ResponseToolkit) {
const transaction: Interfaces.ITransaction = this.transactionPool.getTransaction(request.params.id);
if (!transaction) {
return Boom.notFound("Transaction not found");
}
const data = { id: transaction.id, serialized: transaction.serialized.toString("hex") };
return super.respondWithResource(data, "transaction", (request.query.transform as unknown) as boolean);
}
static async findByEmailOrFail (email) {
return this
.findOne({ email })
.orFail(Boom.notFound(null, { email: 'Email address is not registered' }))
}