Refactor user ID validation and optimize city search results. Updated user ID check to use Number.isNaN for better clarity. Added a comment indicating that city results are capped at 50 in the database query to reduce latency.
This commit is contained in:
@@ -30,7 +30,7 @@ export const handler = safeHandler(
|
||||
const userInfo = await verifyUserToken(token);
|
||||
const userId = Number(userInfo.id);
|
||||
|
||||
if (!userId || isNaN(userId)) {
|
||||
if (!userId || Number.isNaN(userId)) {
|
||||
throw new ApiError(400, 'Invalid user ID');
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ export const handler = safeHandler(
|
||||
body: JSON.stringify({
|
||||
success: true,
|
||||
message: 'Cities found successfully',
|
||||
data: results,
|
||||
data: results, // already capped at 50 in DB query
|
||||
count: results.length,
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1932,9 +1932,11 @@ export class UserService {
|
||||
id: true,
|
||||
cityName: true,
|
||||
stateXid: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
},
|
||||
orderBy: {
|
||||
cityName: 'asc',
|
||||
},
|
||||
take: 50, // reduce latency by limiting results at DB level
|
||||
});
|
||||
|
||||
return results;
|
||||
|
||||
Reference in New Issue
Block a user