@@ -16,7 +16,7 @@ router.get('/', async (req, res) => {
1616 console . log ( '[API] api/v1/users' )
1717 } catch ( e ) {
1818 console . error ( '[API Error] api/v1/sessions' , e )
19- res . status ( 500 ) . json ( { status : 'ServerError ' , reason : e . message } )
19+ res . status ( 500 ) . json ( { status : 'error ' , reason : e . message } )
2020 }
2121} )
2222
@@ -26,14 +26,57 @@ router.get('/:id', async (req, res) => {
2626 api . reactMapSecret &&
2727 req . headers [ 'react-map-secret' ] === api . reactMapSecret
2828 ) {
29- res . status ( 200 ) . json ( await User . query ( ) . findById ( req . params . id ) )
29+ const user = await User . query ( ) . findById ( req . params . id )
30+ res
31+ . status ( 200 )
32+ . json ( user || { status : 'error' , reason : 'User Not Found' } )
3033 } else {
3134 throw new Error ( 'Incorrect or missing API secret' )
3235 }
3336 console . log ( `[API] api/v1/users/${ req . params . id } ` )
3437 } catch ( e ) {
3538 console . error ( `[API Error] api/v1/users/${ req . params . id } ` , e )
36- res . status ( 500 ) . json ( { status : 'ServerError' , reason : e . message } )
39+ res . status ( 500 ) . json ( { status : 'error' , reason : e . message } )
40+ }
41+ } )
42+
43+ router . get ( '/discord/:id' , async ( req , res ) => {
44+ try {
45+ if (
46+ api . reactMapSecret &&
47+ req . headers [ 'react-map-secret' ] === api . reactMapSecret
48+ ) {
49+ const user = await User . query ( ) . where ( 'discordId' , req . params . id ) . first ( )
50+ res
51+ . status ( 200 )
52+ . json ( user || { status : 'error' , reason : 'User Not Found' } )
53+ } else {
54+ throw new Error ( 'Incorrect or missing API secret' )
55+ }
56+ console . log ( `[API] api/v1/users/discord/${ req . params . id } ` )
57+ } catch ( e ) {
58+ console . error ( `[API Error] api/v1/users/discord/${ req . params . id } ` , e )
59+ res . status ( 500 ) . json ( { status : 'error' , reason : e . message } )
60+ }
61+ } )
62+
63+ router . get ( '/telegram/:id' , async ( req , res ) => {
64+ try {
65+ if (
66+ api . reactMapSecret &&
67+ req . headers [ 'react-map-secret' ] === api . reactMapSecret
68+ ) {
69+ const user = await User . query ( ) . where ( 'telegramId' , req . params . id ) . first ( )
70+ res
71+ . status ( 200 )
72+ . json ( user || { status : 'error' , reason : 'User Not Found' } )
73+ } else {
74+ throw new Error ( 'Incorrect or missing API secret' )
75+ }
76+ console . log ( `[API] api/v1/users/telegram/${ req . params . id } ` )
77+ } catch ( e ) {
78+ console . error ( `[API Error] api/v1/users/telegram/${ req . params . id } ` , e )
79+ res . status ( 500 ) . json ( { status : 'error' , reason : e . message } )
3780 }
3881} )
3982
0 commit comments