mongoose-backpack
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -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,catchError}=require("rest-api-response-npm"),fs=require("fs");function appendParams(e,r){if(e&&r)try{for(var s in r)e.virtual(s).get(r[s]);e.set("toJSON",{virtuals:!0,transform:(e,r)=>{}})}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 r=e.paths,s=[],o=[],a=[],n=[];for(const l in r){var t=!!r[l]?.options?.required;s.push({field:l,is_required:t}),(t?a:n).push(l),o.push(l)}const i=["_id","createdAt","updatedAt","__v"];e=o.filter(e=>!i.includes(e));return{parameters:s,allFields:o,requiredFields:a,optionalFields:n,filteredFormFields:e}}function mongooseRouteName(a,s){var e=express.Router(),r=multer.diskStorage({destination:function(e,r,s){var o="./uploads/"+a;fs.existsSync(o)||fs.mkdirSync(o,{recursive:!0}),s(null,o)},filename:function(e,r,s){r=path.extname(r.originalname);s(null,a+"-"+Date.now()+r)}}),r=(multer({storage:r}),modelsParams(s.schema)),o=[];if(r&&r?.filteredFormFields&&r?.filteredFormFields.length){var n,t=r?.filteredFormFields;for(n in t)t[n]&&o.push({name:t[n]});r?.filteredFormFields}return e.delete(`/${a}/:id`,async(e,r)=>{try{await s.findByIdAndDelete(e.params.id).then(e=>{successResponse(r,e,"Deleted successfully!")}).catch(e=>errorResponse(r,null,"Opps something went wrong!",500))}catch(e){console.error(e),errorResponse(r,null,"Error deleting data",500)}}),e}module.exports={appendParams:appendParams,modelsParams:modelsParams,mongooseRouteName:mongooseRouteName}; |
{ | ||
"name": "mongoose-backpack", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
5497