New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapiapi

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapiapi - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

LICENSE.txt

64

index.js
'use strict';
var inflect = require('i')();
var _ = require('underscore');
var internals = {};
exports.register = function (plugin, options, next) {
plugin.dependency(['hapi-bearer', 'hapi-db']);
plugin.auth.strategy('bearer', 'bearer');

@@ -14,16 +20,19 @@ plugin.expose('get', internals.get);

var inflect = require('i')();
var _ = require('underscore');
var internals = {};
internals.get = function (resource, schema, server) {
return {
auth: 'bearer',
handler: function (request, reply) {
var db = request.server.plugins['hapi-db'].db;
if (request.params.id) {
server.helpers.find(resource, request.params.id, function (docs) {
reply(internals.serialize(resource, docs, schema));
db.collection(resource).findOne({_id: request.params.id}, function (err, doc) {
if (err) {
throw err;
}
reply(internals.serialize(resource, [doc], schema));
});
} else {
server.helpers.findMany(resource, function (docs) {
db.collection(resource).find({}, function (err, docs) {
if (err) {
throw err;
}
reply(internals.serialize(resource, docs, schema));

@@ -38,5 +47,10 @@ });

return {
auth: 'bearer',
validate: internals.validate(resource, schema, types),
handler: function (request, reply) {
server.helpers.insert(resource, internals.deserialize(resource, request.payload), function (docs) {
var db = request.server.plugins['hapi-db'].db;
db.collection(resource).insert(internals.deserialize(resource, request.payload), function (err, docs) {
if (err) {
throw err;
}
reply(internals.serialize(resource, docs, schema));

@@ -50,7 +64,25 @@ });

return {
auth: 'bearer',
validate: internals.validate(resource, schema, types),
handler: function (request, reply) {
server.helpers.update(resource, request.params.id, internals.deserialize(resource, request.payload), function (docs) {
reply(internals.serialize(resource, docs, schema));
var db = request.server.plugins['hapi-db'].db,
filtered = {};
_.each(internals.deserialize(resource, request.payload), function (value, key) {
if (value) {
filtered[key] = value;
}
});
db.collection(resource).update({_id: request.params.id}, {
$set: filtered
}, function (err) {
if (err) {
throw err;
}
db.collection(resource).findOne({_id: request.params.id}, function (err, docs) {
if (err) {
throw err;
}
reply(internals.serialize(resource, docs, schema));
});
});
}

@@ -62,2 +94,3 @@ };

return {
auth: 'bearer',
validate: internals.validate(resource, schema, types),

@@ -72,4 +105,9 @@ handler: function (request, reply) {

return {
auth: 'bearer',
handler: function (request, reply) {
server.helpers.remove(resource, request.params.id, function (docs) {
var db = request.server.plugins['hapi-db'].db;
db.collection(resource).remove({_id: request.params.id}, function (err, docs) {
if (err) {
throw err;
}
reply(docs);

@@ -134,4 +172,2 @@ });

console.log(json);
return json;

@@ -138,0 +174,0 @@ };

{
"name": "hapiapi",
"version": "0.0.1",
"version": "0.0.2",
"description": "",

@@ -16,12 +16,6 @@ "main": "index.js",

"peerDependencies": {
"hapi": "~2.1.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-develop": "~0.2.2",
"grunt-jslint": "~1.1.2"
"hapi": "~2.6.0",
"hapi-bearer": "~0.0.1",
"hapi-db": "~0.0.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc