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:
paritosh18
2026-02-23 18:56:08 +05:30
parent 1fbcf1dddc
commit 5ec07d4480
2 changed files with 6 additions and 4 deletions

View File

@@ -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,
}),
};

View File

@@ -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;