File tree Expand file tree Collapse file tree 2 files changed +58
-5
lines changed
Expand file tree Collapse file tree 2 files changed +58
-5
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,53 @@ var api = {};
33
44var model = mongoose . model ( 'User' ) ;
55
6+ api . list = function ( req , res ) {
7+ model . find ( { } , function ( error , list ) {
8+ if ( error ) {
9+ res . status ( 500 ) . json ( error ) ;
10+ }
11+ res . json ( list ) ;
12+ } ) ;
13+
14+ } ;
15+
16+ api . create = function ( req , res ) {
17+ model
18+ . create ( req . body ) . then ( function ( dados ) {
19+ res . json ( dados ) ;
20+ } , function ( error ) {
21+ console . log ( error ) ;
22+ res . status ( 404 ) . json ( error ) ;
23+ } ) ;
24+
25+ } ;
26+
27+ api . searchById = function ( req , res ) {
28+
29+ model
30+ . findById ( req . params . id )
31+ . then ( function ( id ) {
32+
33+ res . json ( id ) ;
34+
35+ } , function ( error ) {
36+ console . log ( error ) ;
37+ res . status ( 404 ) . json ( error ) ;
38+ } ) ;
39+
40+ } ;
41+
42+ api . deleteById = function ( req , res ) {
43+ model . remove ( { _id : req . params . id } )
44+ . then ( function ( ) {
45+ res . sendStatus ( 200 ) ;
46+ } , function ( error ) {
47+ console . log ( error ) ;
48+ res . status ( 404 ) . json ( error ) ;
49+ } ) ;
50+
51+ } ;
52+
653api . update = function ( req , res ) {
754 console . log ( req . body ) ;
855 model
@@ -15,9 +62,7 @@ api.update = function(req,res){
1562 console . log ( error ) ;
1663 res . status ( 404 ) . json ( error ) ;
1764 } ) ;
18- } ;
19-
20-
2165
66+ } ;
2267
2368module . exports = api ;
Original file line number Diff line number Diff line change 11module . exports = function ( app ) {
2-
2+
33 var api = app . app . api . user ;
44
5- app . put ( '/update/user/:id' , api . update ) ;
5+ app . get ( '/list/users' , api . list ) ;
6+
7+ app . post ( '/create/users' , api . create ) ;
8+
9+ app . put ( '/update/users/:id' , api . update ) ;
10+
11+ app . get ( '/select/users/:id' , api . searchById ) ;
12+
13+ app . delete ( '/delete/users/:id' , api . deleteById ) ;
614} ;
You can’t perform that action at this time.
0 commit comments