mongoose-backpack
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -12,3 +12,3 @@ ``` | ||
.connect( | ||
"mongodb+srv://fluxe0074:fluxe0074@cluster1.48j1fuf.mongodb.net/test", | ||
"mongodb+srv://jaykumargohil:#####@jkgmongo.9bdgpey.mongodb.net/demo", | ||
{ | ||
@@ -37,6 +37,6 @@ useNewUrlParser: true, | ||
app.use("/", mongooseRouteName("people", Message)); | ||
app.use("/api", mongooseRouteName("people", Message)); | ||
// Start the Express app | ||
const port = process.env.PORT || 3000; | ||
const port = process.env.PORT || 3002; | ||
app.listen(port, () => { | ||
@@ -46,2 +46,3 @@ console.log(`Server started on port ${port}`); | ||
``` |
@@ -1,1 +0,1 @@ | ||
const express=require("express"),multer=require("multer"),{successResponse,errorResponse}=require("rest-api-response-npm"),fs=require("fs");function appendParams(s,e){if(s&&e){console.log("sssssssssssssssssssssssssssssssssssssssssssssss");try{for(var r in e)s.virtual(r).get(e[r]);s.set("toJSON",{virtuals:!0,transform:(s,e)=>{}})}catch(s){console.log("appendParams() Failed! Something went wrong"),console.log(s)}}else console.log("ERROR! Schema and Data parameter's are missing")}function modelsParams(s){console.log(s);var e=s.paths,r=[],o=[],a=[],t=[];for(const i in e){var n=!!e[i]?.options?.required;r.push({field:i,is_required:n}),(n?a:t).push(i),o.push(i)}const l=["_id","createdAt","updatedAt"];s=o.filter(s=>!l.includes(s));return{parameters:r,allFields:o,requiredFields:a,optionalFields:t,filteredFormFields:s}}function mongooseRouteName(a,o){var s=express.Router(),e=multer.diskStorage({destination:function(s,e,r){var o="./uploads/"+a;fs.existsSync(o)||fs.mkdirSync(o,{recursive:!0}),r(null,o)},filename:function(s,e,r){r(null,a+"-"+Date.now())}}),e=multer({storage:e}),r=modelsParams(o.schema),t=[];if(r&&r?.filteredFormFields&&r?.filteredFormFields.length){var n,l=r?.filteredFormFields;for(n in l)l[n]&&t.push({name:l[n]})}return console.log(t),s.get(a+"/",async(s,e)=>{var r=await o.find();successResponse(e,r,"List fetched successfully!",200)}),s.get(a+"/:id",async(s,e)=>{s=await o.findById(s.params.id);successResponse(e,s,"Detail fetched successfully!")}),s.post(a+"/",e.fields(t),async(r,e)=>{console.log(t);try{r.files&&0<Object.keys(r.files).length&&Object.keys(r.files).forEach(function(s){var e;0<r.files[s].length&&(e=r.files[s][0],r.body[s]=e?.path)}),r.body&&0<Object.keys(r.body).length&&Object.keys(r.body).forEach(function(s){});new o(r.body);successResponse(e,r.body,"Created successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error adding data",500)}}),s.put(a+"/:id",async(s,e)=>{try{var r=await o.findByIdAndUpdate(s.params.id,s.body,{new:!0});successResponse(e,r,"Updated successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error updating data",500)}}),s.delete(a+"/:id",async(s,e)=>{try{var r=await o.findByIdAndDelete(s.params.id);successResponse(e,r,"Deleted successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error deleting data",500)}}),s}module.exports={appendParams:appendParams,modelsParams:modelsParams,mongooseRouteName:mongooseRouteName}; | ||
const express=require("express"),multer=require("multer"),{successResponse,errorResponse}=require("rest-api-response-npm"),fs=require("fs");function appendParams(s,e){if(s&&e){console.log("sssssssssssssssssssssssssssssssssssssssssssssss");try{for(var r in e)s.virtual(r).get(e[r]);s.set("toJSON",{virtuals:!0,transform:(s,e)=>{}})}catch(s){console.log("appendParams() Failed! Something went wrong"),console.log(s)}}else console.log("ERROR! Schema and Data parameter's are missing")}function modelsParams(s){console.log(s);var e=s.paths,r=[],o=[],a=[],t=[];for(const i in e){var n=!!e[i]?.options?.required;r.push({field:i,is_required:n}),(n?a:t).push(i),o.push(i)}const l=["_id","createdAt","updatedAt"];s=o.filter(s=>!l.includes(s));return{parameters:r,allFields:o,requiredFields:a,optionalFields:t,filteredFormFields:s}}function mongooseRouteName(a,o){var s=express.Router(),e=multer.diskStorage({destination:function(s,e,r){var o="./uploads/"+a;fs.existsSync(o)||fs.mkdirSync(o,{recursive:!0}),r(null,o)},filename:function(s,e,r){r(null,a+"-"+Date.now())}}),e=multer({storage:e}),r=modelsParams(o.schema),t=[];if(r&&r?.filteredFormFields&&r?.filteredFormFields.length){var n,l=r?.filteredFormFields;for(n in l)l[n]&&t.push({name:l[n]})}return console.log(t),s.get(`/${a}/`,async(s,e)=>{var r=await o.find();successResponse(e,r,"List fetched successfully!",200)}),s.get(`/${a}/:id`,async(s,e)=>{s=await o.findById(s.params.id);successResponse(e,s,"Detail fetched successfully!")}),s.post(`/${a}/`,e.fields(t),async(r,e)=>{console.log(t);try{r.files&&0<Object.keys(r.files).length&&Object.keys(r.files).forEach(function(s){var e;0<r.files[s].length&&(e=r.files[s][0],r.body[s]=e?.path)}),r.body&&0<Object.keys(r.body).length&&Object.keys(r.body).forEach(function(s){});new o(r.body);successResponse(e,r.body,"Created successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error adding data",500)}}),s.put(`/${a}/:id`,async(s,e)=>{try{var r=await o.findByIdAndUpdate(s.params.id,s.body,{new:!0});successResponse(e,r,"Updated successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error updating data",500)}}),s.delete(`/${a}/:id`,async(s,e)=>{try{var r=await o.findByIdAndDelete(s.params.id);successResponse(e,r,"Deleted successfully!")}catch(s){console.error(s),errorResponse(e,s,"Error deleting data",500)}}),s}module.exports={appendParams:appendParams,modelsParams:modelsParams,mongooseRouteName:mongooseRouteName}; |
{ | ||
"name": "mongoose-backpack", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -62,3 +62,3 @@ ``` | ||
.connect( | ||
"mongodb+srv://fluxe0074:fluxe0074@cluster1.48j1fuf.mongodb.net/test", | ||
"mongodb+srv://jaykumargohil:#####@jkgmongo.9bdgpey.mongodb.net/demo", | ||
{ | ||
@@ -87,6 +87,6 @@ useNewUrlParser: true, | ||
app.use("/", mongooseRouteName("people", Message)); | ||
app.use("/api", mongooseRouteName("people", Message)); | ||
// Start the Express app | ||
const port = process.env.PORT || 3000; | ||
const port = process.env.PORT || 3002; | ||
app.listen(port, () => { | ||
@@ -93,0 +93,0 @@ console.log(`Server started on port ${port}`); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6307