{"id":15040578,"url":"https://github.com/cristianuser/agradon","last_synced_at":"2025-04-14T18:33:45.125Z","repository":{"id":57174671,"uuid":"237826472","full_name":"CristianUser/agradon","owner":"CristianUser","description":"Agradon is a Express Middleware for Automatize CRUD proccess and query system","archived":false,"fork":false,"pushed_at":"2022-05-30T15:05:37.000Z","size":204,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T01:32:34.326Z","etag":null,"topics":["backend","crud-generator","express","midd","nodejs","query"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CristianUser.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-02T19:45:40.000Z","updated_at":"2021-08-26T02:23:01.000Z","dependencies_parsed_at":"2022-08-28T20:52:22.949Z","dependency_job_id":null,"html_url":"https://github.com/CristianUser/agradon","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CristianUser%2Fagradon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CristianUser%2Fagradon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CristianUser%2Fagradon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CristianUser%2Fagradon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CristianUser","download_url":"https://codeload.github.com/CristianUser/agradon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248937131,"owners_count":21186168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","crud-generator","express","midd","nodejs","query"],"created_at":"2024-09-24T20:44:45.667Z","updated_at":"2025-04-14T18:33:45.081Z","avatar_url":"https://github.com/CristianUser.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Agradon\n\n[![Coverage Status](https://coveralls.io/repos/github/CristianUser/agradon/badge.svg?branch=master)](https://coveralls.io/github/CristianUser/agradon?branch=master)\n\nExtensible Express middleware for automatic generation of the models, controllers, and routes with MongoDB.\n\n## Getting started\n\n### How to install\n\nInstall the package\n\n```bash\nnpm install agradon\n```\n\nInitialize **Agradon**\n\nSet `MONGODB_URI` environment variable and import `agradon` in your app index.\n\n```javascript\nconst express = require('express');\nconst agradon = require('agradon');\nconst app = express();\n\nagradon.init(app);\n\napp.listen(process.env.PORT, () =\u003e console.log(`Server is listening on port ${process.env.PORT}`));\n\nmodule.exports = app;\n```\n\nAgradon also support plugins for increase functionality.\n\nPlugin Example:\n\n```javascript\nfunction customPlugin(router, mongoose, schemas) {\n  // Code live here\n  ...\n}\n\n\nconst config = {\n  app,\n  plugins: [customPlugin]\n}\n```\n\n## Entities\n\nAgrandon entities are composed by three different files. Entities by default are located in entities folder, Example: `entities/\u003centitity-name\u003e/schema.yml` You can also change this setting path in `ENTITIES_PATH` environment variable.\n\n-schema.yml (Required)\n-model.js (Optional)\n-controller.js (Optional)\n\n### schema.yml \\*\n\nSchema file defines documents structure as `Mongoose.Schema` .\n\n```yaml\n_schema:\n  name:\n    first:\n      type: String\n      default: John\n    last: String\n  phone: String\n  age:\n    type: Number\n    required: true\n_options:\n  timestamps: true\n```\n\n### model.js\n\nModel file used to set `virtual`, `hooks`, etc. You also can register middlewares to default routes or to be used in controller file.\n\n```javascript\nmodule.exports.schema = schema =\u003e {\n  // Code live here\n  return schema;\n};\n\nmodule.exports.middleware = [];\n```\n\n### controller.js\n\nController file is used to create custom endpoints or add middlewares to the default endpoints.\n\n```javascript\nmodule.exports = (router, model, middleware) =\u003e {\n  router.get('/', (req, res) =\u003e {\n    return model.find({}).then(result =\u003e {\n      res.send(result);\n    });\n  });\n  return router;\n};\n```\n\n## Authentication Module\n\nAgradon includes a configurable authentication plugin\n\n### How to setup\n\nTo enable authetication module follow the example bellow. This module is configurable, so you can pass your own strategies to interact with db.\n\n```javascript\nagradon.init({\n  app,\n  rootPath: '/api',\n  plugins: [\n    require('agradon/auth')()\n  ]\n});\n```\n\nBy default we set `/auth/local` with a local strategy\n\n### Auth Guards\n\nThe guards are created to protect the crud routes. guards are set in `schema.yml` by http method/action in db.\n\n```yaml\n...\n_auth:\n  get: true\n  post: true\n  put: true\n  delete: true\n```\n\n## Routing\n\nAgradon creates the routes based in the entity name.\n\n- GET: `/:collection`\n- GET: `/:collection/:id`\n- POST: `/:collection/`\n- PUT: `/:collection/:id`\n- DELETE: `/:collection/:id`\n\nYou can set a prefix as `/api` in the config object\nExample:\n\n```javascript\nagradon.init({\n  app,\n  rootPath: '/api'\n});\n```\n\n## Query System\n\nAgradon includes a powerful query system for `GET` requests\n\n- Match\n- Compare\n- Pick\n- Omit\n- Pagination\n- Limit\n- Populate\n\nThose Matchers are passed as query in get request, example `/user?match=name:john`\n\n### Match\n\nMatch filter the results matching key:value in documents.\n**Use**: `match=key:value`\n\n### Compare\n\nCompare documents with.\n**Use**: `compare=key:operator:value`\nIn case of multiple matching can be send it as array.\nOperators:\n\n- ==\n- \\\u003e\n- \u003c\n- \\\u003e=\n- \u003c=\n- !=\n\n### Pick\n\nSelect which fields you need from each document.\n**Use**: `pick=field1,field2,field4.field4A` or `pick=field1\u0026pick=field2\u0026pick=field3`\nCan be a string separated by comma or an array.\n\n### Omit\n\nOmit is the oposite of `pick`.\n**Use**: `omit=field1,field2,field4.field4A` or `omit=field1\u0026omit=field2`\nCan be a string separated by comma or an array.\n\n### Limit\n\nYou are able to limit the results.\n**Use**: `limit=20`\n\n### Pagination\n\nWe also included pagination\n**Use**: `page=1\u0026perPage=10`\n\n\u003e Hint: `perPage` is an alias for `limit`.\n\n### Populate\n\nIf you have some experience with MongoDB maybe you know about populate, if not read [this](https://mongoosejs.com/docs/populate.html).\n**Use**: `populate=field1(subField1,subField1)`\n**Example**: `populate=user(name,lastname)`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianuser%2Fagradon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcristianuser%2Fagradon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianuser%2Fagradon/lists"}