@@ -13,7 +13,7 @@ function createServer(db) {
1313
1414 function reply ( fn ) {
1515 return function ( req , res , next ) {
16- fn . call ( db , req . params . id , req . body )
16+ fn ( req . params , req . body , req . query )
1717 . then (
1818 handleSuccess . bind ( null , req , res ) ,
1919 handleError . bind ( null , req , res )
@@ -22,15 +22,22 @@ function createServer(db) {
2222 }
2323 }
2424
25- function replyNoParams ( fn ) {
26- return function ( req , res , next ) {
27- fn . call ( db , req . body , req . query )
28- . then (
29- handleSuccess . bind ( null , req , res ) ,
30- handleError . bind ( null , req , res )
31- )
32- . done ( next , next )
33- }
25+ function withIdAndBody ( fn ) {
26+ return reply ( function ( params , body , query ) {
27+ return fn . call ( db , params . id , body )
28+ } )
29+ }
30+
31+ function withBodyAndQuery ( fn ) {
32+ return reply ( function ( params , body , query ) {
33+ return fn . call ( db , body , query )
34+ } )
35+ }
36+
37+ function withParams ( fn ) {
38+ return reply ( function ( params , body , query ) {
39+ return fn . call ( db , params )
40+ } )
3441 }
3542
3643 var api = restify . createServer ( )
@@ -44,54 +51,54 @@ function createServer(db) {
4451 'uaDeviceType'
4552 ] ) )
4653
47- api . get ( '/account/:id' , reply ( db . account ) )
48- api . del ( '/account/:id' , reply ( db . deleteAccount ) )
49- api . put ( '/account/:id' , reply ( db . createAccount ) )
50- api . get ( '/account/:id/devices' , reply ( db . accountDevices ) )
51- api . post ( '/account/:id/checkPassword' , reply ( db . checkPassword ) )
52- api . post ( '/account/:id/reset' , reply ( db . resetAccount ) )
53- api . post ( '/account/:id/verifyEmail' , reply ( db . verifyEmail ) )
54- api . post ( '/account/:id/locale' , reply ( db . updateLocale ) )
55- api . get ( '/account/:id/sessions' , reply ( db . sessions ) )
56-
57- api . get ( '/sessionToken/:id' , reply ( db . sessionToken ) )
58- api . del ( '/sessionToken/:id' , reply ( db . deleteSessionToken ) )
59- api . put ( '/sessionToken/:id' , reply ( db . createSessionToken ) )
60- api . post ( '/sessionToken/:id/update' , reply ( db . updateSessionToken ) )
61- api . get ( '/sessionToken/:id/device' , reply ( db . sessionWithDevice ) )
62-
63- api . get ( '/keyFetchToken/:id' , reply ( db . keyFetchToken ) )
64- api . del ( '/keyFetchToken/:id' , reply ( db . deleteKeyFetchToken ) )
65- api . put ( '/keyFetchToken/:id' , reply ( db . createKeyFetchToken ) )
66-
67- api . get ( '/sessionToken/:id/verified' , reply ( db . sessionTokenWithVerificationStatus ) )
68- api . get ( '/keyFetchToken/:id/verified' , reply ( db . keyFetchTokenWithVerificationStatus ) )
69- api . post ( '/tokens/:id/verify' , reply ( db . verifyTokens ) )
70-
71- api . get ( '/accountResetToken/:id' , reply ( db . accountResetToken ) )
72- api . del ( '/accountResetToken/:id' , reply ( db . deleteAccountResetToken ) )
73-
74- api . get ( '/passwordChangeToken/:id' , reply ( db . passwordChangeToken ) )
75- api . del ( '/passwordChangeToken/:id' , reply ( db . deletePasswordChangeToken ) )
76- api . put ( '/passwordChangeToken/:id' , reply ( db . createPasswordChangeToken ) )
77-
78- api . get ( '/passwordForgotToken/:id' , reply ( db . passwordForgotToken ) )
79- api . del ( '/passwordForgotToken/:id' , reply ( db . deletePasswordForgotToken ) )
80- api . put ( '/passwordForgotToken/:id' , reply ( db . createPasswordForgotToken ) )
81- api . post ( '/passwordForgotToken/:id/update' , reply ( db . updatePasswordForgotToken ) )
82- api . post ( '/passwordForgotToken/:id/verified' , reply ( db . forgotPasswordVerified ) )
83-
84- api . get ( '/verificationReminders' , replyNoParams ( db . fetchReminders ) )
85- api . post ( '/verificationReminders' , replyNoParams ( db . createVerificationReminder ) )
86- api . del ( '/verificationReminders' , replyNoParams ( db . deleteReminder ) )
87-
88- api . get ( '/securityEvents' , reply ( db . securityEvents ) )
89- api . post ( '/securityEvents' , reply ( db . createSecurityEvent ) )
90-
91- api . get ( '/emailRecord/:id' , reply ( db . emailRecord ) )
92- api . head ( '/emailRecord/:id' , reply ( db . accountExists ) )
93-
94- api . get ( '/__heartbeat__' , reply ( db . ping ) )
54+ api . get ( '/account/:id' , withIdAndBody ( db . account ) )
55+ api . del ( '/account/:id' , withIdAndBody ( db . deleteAccount ) )
56+ api . put ( '/account/:id' , withIdAndBody ( db . createAccount ) )
57+ api . get ( '/account/:id/devices' , withIdAndBody ( db . accountDevices ) )
58+ api . post ( '/account/:id/checkPassword' , withIdAndBody ( db . checkPassword ) )
59+ api . post ( '/account/:id/reset' , withIdAndBody ( db . resetAccount ) )
60+ api . post ( '/account/:id/verifyEmail' , withIdAndBody ( db . verifyEmail ) )
61+ api . post ( '/account/:id/locale' , withIdAndBody ( db . updateLocale ) )
62+ api . get ( '/account/:id/sessions' , withIdAndBody ( db . sessions ) )
63+
64+ api . get ( '/sessionToken/:id' , withIdAndBody ( db . sessionToken ) )
65+ api . del ( '/sessionToken/:id' , withIdAndBody ( db . deleteSessionToken ) )
66+ api . put ( '/sessionToken/:id' , withIdAndBody ( db . createSessionToken ) )
67+ api . post ( '/sessionToken/:id/update' , withIdAndBody ( db . updateSessionToken ) )
68+ api . get ( '/sessionToken/:id/device' , withIdAndBody ( db . sessionWithDevice ) )
69+
70+ api . get ( '/keyFetchToken/:id' , withIdAndBody ( db . keyFetchToken ) )
71+ api . del ( '/keyFetchToken/:id' , withIdAndBody ( db . deleteKeyFetchToken ) )
72+ api . put ( '/keyFetchToken/:id' , withIdAndBody ( db . createKeyFetchToken ) )
73+
74+ api . get ( '/sessionToken/:id/verified' , withIdAndBody ( db . sessionTokenWithVerificationStatus ) )
75+ api . get ( '/keyFetchToken/:id/verified' , withIdAndBody ( db . keyFetchTokenWithVerificationStatus ) )
76+ api . post ( '/tokens/:id/verify' , withIdAndBody ( db . verifyTokens ) )
77+
78+ api . get ( '/accountResetToken/:id' , withIdAndBody ( db . accountResetToken ) )
79+ api . del ( '/accountResetToken/:id' , withIdAndBody ( db . deleteAccountResetToken ) )
80+
81+ api . get ( '/passwordChangeToken/:id' , withIdAndBody ( db . passwordChangeToken ) )
82+ api . del ( '/passwordChangeToken/:id' , withIdAndBody ( db . deletePasswordChangeToken ) )
83+ api . put ( '/passwordChangeToken/:id' , withIdAndBody ( db . createPasswordChangeToken ) )
84+
85+ api . get ( '/passwordForgotToken/:id' , withIdAndBody ( db . passwordForgotToken ) )
86+ api . del ( '/passwordForgotToken/:id' , withIdAndBody ( db . deletePasswordForgotToken ) )
87+ api . put ( '/passwordForgotToken/:id' , withIdAndBody ( db . createPasswordForgotToken ) )
88+ api . post ( '/passwordForgotToken/:id/update' , withIdAndBody ( db . updatePasswordForgotToken ) )
89+ api . post ( '/passwordForgotToken/:id/verified' , withIdAndBody ( db . forgotPasswordVerified ) )
90+
91+ api . get ( '/verificationReminders' , withBodyAndQuery ( db . fetchReminders ) )
92+ api . post ( '/verificationReminders' , withBodyAndQuery ( db . createVerificationReminder ) )
93+ api . del ( '/verificationReminders' , withBodyAndQuery ( db . deleteReminder ) )
94+
95+ api . get ( '/securityEvents/:id/ip/:ipAddr ' , withParams ( db . securityEvents ) )
96+ api . post ( '/securityEvents' , withBodyAndQuery ( db . createSecurityEvent ) )
97+
98+ api . get ( '/emailRecord/:id' , withIdAndBody ( db . emailRecord ) )
99+ api . head ( '/emailRecord/:id' , withIdAndBody ( db . accountExists ) )
100+
101+ api . get ( '/__heartbeat__' , withIdAndBody ( db . ping ) )
95102
96103 api . put (
97104 '/account/:uid/device/:deviceId' ,
0 commit comments