@@ -2,12 +2,7 @@ const passport = require("passport");
2
2
const users = require ( "../models/users" ) ;
3
3
const QrCodeAuthModel = require ( "../models/qrCodeAuth" ) ;
4
4
const authService = require ( "../services/authService" ) ;
5
- const {
6
- SOMETHING_WENT_WRONG ,
7
- DATA_ADDED_SUCCESSFULLY ,
8
- BAD_REQUEST ,
9
- INVALID_QUERY_PARAM ,
10
- } = require ( "../constants/errorMessages" ) ;
5
+ const { SOMETHING_WENT_WRONG , DATA_ADDED_SUCCESSFULLY , BAD_REQUEST } = require ( "../constants/errorMessages" ) ;
11
6
12
7
/**
13
8
* Fetches the user info from GitHub and authenticates User
@@ -129,20 +124,15 @@ const updateAuthStatus = async (req, res) => {
129
124
130
125
const fetchUserDeviceInfo = async ( req , res ) => {
131
126
try {
132
- const queryParamArray = Object . keys ( req . query ) ;
133
- if ( queryParamArray . length === 1 && queryParamArray [ 0 ] === "device_id" ) {
134
- const deviceId = req . query . device_id ;
135
- const userDeviceInfoData = await QrCodeAuthModel . retrieveUserDeviceInfo ( deviceId ) ;
136
- if ( ! userDeviceInfoData . userExists ) {
137
- return res . boom . notFound ( "No Authentication found!" ) ;
138
- }
139
- return res . json ( {
140
- message : "Authentication document retrieved successfully." ,
141
- data : { ...userDeviceInfoData . data } ,
142
- } ) ;
143
- } else {
144
- return res . boom . badRequest ( INVALID_QUERY_PARAM ) ;
127
+ const deviceId = req . query . device_id ;
128
+ const userDeviceInfoData = await QrCodeAuthModel . retrieveUserDeviceInfo ( deviceId ) ;
129
+ if ( ! userDeviceInfoData . userExists ) {
130
+ return res . boom . notFound ( `User with id ${ deviceId } does not exist.` ) ;
145
131
}
132
+ return res . json ( {
133
+ message : "Authentication document retrieved successfully." ,
134
+ data : { ...userDeviceInfoData . data } ,
135
+ } ) ;
146
136
} catch ( error ) {
147
137
logger . error ( `Error while fetching user: ${ error } ` ) ;
148
138
return res . boom . badImplementation ( SOMETHING_WENT_WRONG ) ;
0 commit comments