{"id":13624542,"url":"https://github.com/Unitech/angular-bridge","last_synced_at":"2025-04-16T00:32:35.914Z","repository":{"id":5676408,"uuid":"6886318","full_name":"Unitech/angular-bridge","owner":"Unitech","description":"Link models easily via a REST interface between Mongoose/Node-Express/Angular.js ","archived":false,"fork":false,"pushed_at":"2018-04-11T07:23:44.000Z","size":240,"stargazers_count":208,"open_issues_count":9,"forks_count":22,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-04-15T12:19:12.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Unitech.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":"2012-11-27T16:05:00.000Z","updated_at":"2024-02-21T09:37:40.000Z","dependencies_parsed_at":"2022-09-14T02:31:12.546Z","dependency_job_id":null,"html_url":"https://github.com/Unitech/angular-bridge","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unitech%2Fangular-bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unitech%2Fangular-bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unitech%2Fangular-bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Unitech%2Fangular-bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Unitech","download_url":"https://codeload.github.com/Unitech/angular-bridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223691647,"owners_count":17186862,"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":[],"created_at":"2024-08-01T21:01:43.612Z","updated_at":"2024-11-08T13:30:39.513Z","avatar_url":"https://github.com/Unitech.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Angular Bridge\n\n[![Build Status](https://david-dm.org/Unitech/angular-bridge.png)](https://david-dm.org/Unitech/angular-bridge)\n[![NPM version](https://badge.fury.io/js/angular-bridge.png)](http://badge.fury.io/js/angular-bridge)\n\nCreate, read, update, delete MongoDB collections via AngularJS.\n\nIt uses : \n\n- Mongoose for accessing to Mongodb\n- Express for the routing\n- AngularJS (with the [$resource](http://docs.angularjs.org/api/ngResource.$resource) method)\n\nBtw don't forget to include [angular-resource.js](http://code.angularjs.org/1.1.5/angular-resource.js)\n\n## Sample code\n\n### Backend code\n\nIn you db.js backend : \n\n```javascript\nvar mongoose = require('mongoose');\nvar db = mongoose.connect('mongodb://localhost/pizza');\nvar Schema = mongoose.Schema;\nvar ObjectId = Schema.ObjectId;\n\nvar PizzaSchema = new Schema({\n    author : {\n\t    type : String,\n    },\n    color : {\n\t    type : String\n    },\n    size : {\n            type : Number\n    },  \n    password : {   // You can hide it from read and write ! (cf after)\n            type : String \n    }\n});\n\n// You can optionally add a method to schema.methods that is executed based\n// on the type of HTTP request with the names \"query\", \"get\", \"put\", \"post\", and \"delete\"\n// The callback receives the affected entities as it's parameter.\nPizzaSchema.methods.query = function(entities) {\n  console.log(\"Queried:\");\n  console.log(entities);\n};\n\nPizzaSchema.methods.get = function(entity) {\n  console.log(\"Got:\")\n  console.log(entity);\n};\n\nPizzaSchema.methods.put = function(entity) {\n  console.log(\"Put:\")\n  console.log(entity);\n};\n\nPizzaSchema.methods.post = function(entity) {\n  console.log(\"Posted:\")\n  console.log(entity);\n};\n\nPizzaSchema.methods.delete = function(entity) {\n  console.log(\"Deleted:\")\n  console.log(entity);\n};\n\nexports.Pizza = mongoose.model('pizzas', PizzaSchema);\n```\n\nIn your backend app.js :\n\n```javascript\nvar db = require('./db.js');\n\n// Mount all the resource on /api prefix\nvar angularBridge = new (require('angular-bridge'))(app, {\n    urlPrefix : '/api/'\n});\n\n// With express you can password protect a url prefix :\napp.use('/api', express.basicAuth('admin', 'my_password'));\n\n// Expose the pizzas collection via REST\nangularBridge.addResource('pizzas', db.Pizza);\n\n// Hiding fields\nangularBridge.addResource('toppings', db.Toppings, { hide : ['_id', 'password']});\n\n// Read-only fields (sent to client, but will not write to database)\nangularBridge.addResource('jaboodies', db.Jaboody, { readOnly: ['_id', 'cantChangeMe']});\n\n// Force a mongoose query (to restrict access to certain items only)\nangularBridge.addResource('projects', db.Project, { query: '{_user: String(req.user._id)}'});\n// Note:  This can be passed as an object, but you can also pass it as a string\n//        in cases where the object you're looking for is only accessible within\n//        the HTTP-verb callback (in this example, 'req' will give an error if it\n//        is not passed as a string)\n\n// Force a particular value regardless of what the client sends\nangularBridge.addResource('clients', db.Client, { force: {_user: 'req.user._id' }});\n\n// Enable population for the given fields\nangularBridge.addResource('projects', db.Project, { populate: \"_ref1\" });\n```\n\n**BE CAREFUL!  `force` AND `query` BOTH USE `eval()`**\n\n### Front end code\nThat's all for the backend, now in Angular :\n\n```javascript\nvar HomeCtrl = function($scope, $routeParams, $location, $resource) {\n    var PizzaDb = $resource('/api/pizzas/:id', { id: '@_id' }); \n   \n   // Magic, you are ready now !\n   \n   var new_pizza = new PizzaDb({\n     author : 'agoodpizayolo',\n     color : 'blue',\n     size : 999\n   });\n   \n   new_pizza.$save(function(save_the_pizza) {\n      console.log('Success pizza - ', save_the_pizza);\n   });\n   \n   PizzaDb.get({id : '50b40dd6ed3f055a27000001'}, function(pizza) {\n    \tpizza.color = 'UV';\n    \tpizza.$save();\n    });\n};\n```\n\n# License\n\n(The MIT License)\n\nCopyright (c) 2013 Alexandre Strzelewicz \u003cstrzelewicz.alexandre@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnitech%2Fangular-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUnitech%2Fangular-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnitech%2Fangular-bridge/lists"}