Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-backpack

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-backpack - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

2

index.js

@@ -1,1 +0,1 @@

const express=require("express"),multer=require("multer"),{successResponse,errorResponse,validationResponse}=require("rest-api-response-npm"),fs=require("fs"),path=require("path");function appendParams(e,s){if(e&&s)try{for(var r in s)e.virtual(r).get(s[r]);e.set("toJSON",{virtuals:!0,transform:(e,s)=>{}})}catch(e){console.log("appendParams() Failed! Something went wrong"),console.log(e)}else console.log("ERROR! Schema and Data parameter's are missing")}function modelsParams(e){var s=e.paths,r=[],t=[],o=[],a=[];for(const l in s){var n=!!s[l]?.options?.required;r.push({field:l,is_required:n}),(n?o:a).push(l),t.push(l)}const i=["_id","createdAt","updatedAt","__v"];e=t.filter(e=>!i.includes(e));return{parameters:r,allFields:t,requiredFields:o,optionalFields:a,filteredFormFields:e}}function mongooseRouteName(p,u){var e=express.Router(),s=multer.diskStorage({destination:function(e,s,r){var t="./uploads/"+p;fs.existsSync(t)||fs.mkdirSync(t,{recursive:!0}),r(null,t)},filename:function(e,s,r){s=path.extname(s.originalname);r(null,p+"-"+Date.now()+s)}}),s=multer({storage:s}),r=modelsParams(u.schema),t=[],h=[];if(r&&r?.filteredFormFields&&r?.filteredFormFields.length){var o,a=r?.filteredFormFields;for(o in a)a[o]&&t.push({name:a[o]});h=r?.filteredFormFields}return e.get(`/${p}/`,async(r,t)=>{try{var o=parseInt(r?.query?.page_no)||1,a=parseInt(r?.query?.page_limit)||10,n=r?.query?.search||"",e=[];if(n&&h&&h?.length){var s,i,l=new RegExp(n,"i");for(s in h)h[s]&&(i=h[s],e.push({[i]:l}))}const c=await u.countDocuments({$or:0<e?.length?e:[{}]}),d=Math.ceil(c/a);await u.find({$or:0<e?.length?e:[{}]}).skip((o-1)*a).limit(a).then(e=>{var e={totalRecords:c,totalPages:d,currentPage:o,perPage:a,results:e},s=`${r.protocol}://${r.get("host")}${r.baseUrl}/${p}?page_no=1&page_limit=${a}&search=`+n,s=(e.firstLink=s,1<o?(s=o-1,s=`${r.protocol}://${r.get("host")}${r.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n,e.previousLink=s):e.previousLink=null,1<=o||o<=d?(s=`${r.protocol}://${r.get("host")}${r.baseUrl}/${p}?page_no=${o}&page_limit=${a}&search=`+n,e.currentLink=s):e.currentLink=null,o<d?(s=o+1,s=`${r.protocol}://${r.get("host")}${r.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n,e.nextLink=s):e.nextLink=null,d),s=`${r.protocol}://${r.get("host")}${r.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n;e.lastLink=s,successResponse(t,e,"List fetched successfully!")}).catch(e=>errorResponse(t,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(t,null,"Error adding data",500)}}),e.get(`/${p}/:id`,async(e,s)=>{await u.findById(e.params.id).then(e=>{e?successResponse(s,e,"Detail fetched successfully!"):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}),e.post(`/${p}/`,s.fields(t),async(r,t)=>{try{r.files&&0<Object.keys(r.files).length&&Object.keys(r.files).forEach(function(e){var s;0<r.files[e].length&&(s=r.files[e][0],r.body[e]=s?.path)}),r.body&&0<Object.keys(r.body).length&&Object.keys(r.body).forEach(function(e){}),await new u(r.body).save().then(e=>{successResponse(t,e,"Created successfully!")}).catch(e=>{var s=e?.message||"Opps something went wrong!";errorResponse(t,e,s,500)})}catch(e){console.error(e),errorResponse(t,null,"Error adding data",500)}}),e.put(`/${p}/:id`,s.fields(t),async(r,s)=>{try{r.files&&0<Object.keys(r.files).length&&Object.keys(r.files).forEach(function(e){var s;0<r.files[e].length&&(s=r.files[e][0],r.body[e]=s?.path)}),r.body&&0<Object.keys(r.body).length&&Object.keys(r.body).forEach(function(e){}),await u.findByIdAndUpdate(r.params.id,r.body,{new:!0}).then(e=>{e?successResponse(s,e,"Updated successfully!..."):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(s,null,"Error updating data",500)}}),e.delete(`/${p}/:id`,async(e,s)=>{try{await u.findByIdAndDelete(e.params.id).then(e=>{e?successResponse(s,e,"Deleted successfully!"):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(s,null,"Error deleting data",500)}}),e}module.exports={appendParams:appendParams,modelsParams:modelsParams,mongooseRouteName:mongooseRouteName};
const express=require("express"),multer=require("multer"),{successResponse,errorResponse,validationResponse,checkValidation}=require("rest-api-response-npm"),fs=require("fs"),path=require("path");function appendParams(e,s){if(e&&s)try{for(var t in s)e.virtual(t).get(s[t]);e.set("toJSON",{virtuals:!0,transform:(e,s)=>{}})}catch(e){console.log("appendParams() Failed! Something went wrong"),console.log(e)}else console.log("ERROR! Schema and Data parameter's are missing")}function modelsParams(e){var s=e.paths,t=[],r=[],o=[],a=[];for(const l in s){var n=!!s[l]?.options?.required;t.push({field:l,is_required:n}),(n?o:a).push(l),r.push(l)}const i=["_id","createdAt","updatedAt","__v"];e=r.filter(e=>!i.includes(e));return{parameters:t,allFields:r,requiredFields:o,optionalFields:a,filteredFormFields:e}}function mongooseRouteName(p,u){var e=express.Router(),s=multer.diskStorage({destination:function(e,s,t){var r="./uploads/"+p;fs.existsSync(r)||fs.mkdirSync(r,{recursive:!0}),t(null,r)},filename:function(e,s,t){s=path.extname(s.originalname);t(null,p+"-"+Date.now()+s)}}),s=multer({storage:s}),t=modelsParams(u.schema),r=[],h=[];if(t&&t?.filteredFormFields&&t?.filteredFormFields.length){var o,a=t?.filteredFormFields;for(o in a)a[o]&&r.push({name:a[o]});h=t?.filteredFormFields}return e.get(`/${p}/`,async(t,r)=>{try{var o=parseInt(t?.query?.page_no)||1,a=parseInt(t?.query?.page_limit)||10,n=t?.query?.search||"",e=[];if(n&&h&&h?.length){var s,i,l=new RegExp(n,"i");for(s in h)h[s]&&(i=h[s],e.push({[i]:l}))}const c=await u.countDocuments({$or:0<e?.length?e:[{}]}),d=Math.ceil(c/a);await u.find({$or:0<e?.length?e:[{}]}).skip((o-1)*a).limit(a).then(e=>{var e={totalRecords:c,totalPages:d,currentPage:o,perPage:a,results:e},s=`${t.protocol}://${t.get("host")}${t.baseUrl}/${p}?page_no=1&page_limit=${a}&search=`+n,s=(e.firstLink=s,1<o?(s=o-1,s=`${t.protocol}://${t.get("host")}${t.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n,e.previousLink=s):e.previousLink=null,1<=o||o<=d?(s=`${t.protocol}://${t.get("host")}${t.baseUrl}/${p}?page_no=${o}&page_limit=${a}&search=`+n,e.currentLink=s):e.currentLink=null,o<d?(s=o+1,s=`${t.protocol}://${t.get("host")}${t.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n,e.nextLink=s):e.nextLink=null,d),s=`${t.protocol}://${t.get("host")}${t.baseUrl}/${p}?page_no=${s}&page_limit=${a}&search=`+n;e.lastLink=s,successResponse(r,e,"List fetched successfully!")}).catch(e=>errorResponse(r,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(r,null,"Error adding data",500)}}),e.get(`/${p}/:id`,async(e,s)=>{await u.findById(e.params.id).then(e=>{e?successResponse(s,e,"Detail fetched successfully!"):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}),e.post(`/${p}/`,s.fields(r),async(t,n)=>{try{t.files&&0<Object.keys(t.files).length&&Object.keys(t.files).forEach(function(e){var s;0<t.files[e].length&&(s=t.files[e][0],t.body[e]=s?.path)}),t.body&&0<Object.keys(t.body).length&&Object.keys(t.body).forEach(function(e){}),await new u(t.body).save().then(e=>{successResponse(n,e,"Created successfully!")}).catch(e=>{var s=e?.message||"Opps something went wrong!";if(e&&e?.errors){var t,r=e?.errors,o={};for(const a in r)Object.prototype.hasOwnProperty.call(r,a)&&(t=r[a],o[path]?o[t.path].push(t.message):o[t.path]=[t.message]);o&&validationResponse(n,o,s)}else validationResponse(n,e,s)})}catch(e){console.error(e),errorResponse(n,null,"Error adding data",500)}}),e.put(`/${p}/:id`,s.fields(r),async(t,s)=>{try{t.files&&0<Object.keys(t.files).length&&Object.keys(t.files).forEach(function(e){var s;0<t.files[e].length&&(s=t.files[e][0],t.body[e]=s?.path)}),t.body&&0<Object.keys(t.body).length&&Object.keys(t.body).forEach(function(e){}),await u.findByIdAndUpdate(t.params.id,t.body,{new:!0}).then(e=>{e?successResponse(s,e,"Updated successfully!..."):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(s,null,"Error updating data",500)}}),e.delete(`/${p}/:id`,async(e,s)=>{try{await u.findByIdAndDelete(e.params.id).then(e=>{e?successResponse(s,e,"Deleted successfully!"):(data={id:["Record doesn't exist!"]},validationResponse(s,data,"Record doesn't exist!"))}).catch(e=>errorResponse(s,e,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(s,null,"Error deleting data",500)}}),e}module.exports={appendParams:appendParams,modelsParams:modelsParams,mongooseRouteName:mongooseRouteName};
{
"name": "mongoose-backpack",
"version": "0.2.6",
"version": "0.2.7",
"description": "",

@@ -24,2 +24,8 @@ "main": "index.js",

"MongoDB",
"Rest-APIs",
"CRUD",
"Database",
"Model",
"append-parameter",
"Response",
"npm",

@@ -26,0 +32,0 @@ "node",

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