refactor(register, listings, items): simplify transaction, remove unused variable, add explicit types
- Remove newUser variable and directly return created user from Prisma transaction in register route - Add explicit casts for Prisma QueryMode to avoid TypeScript widening in listings search - Fix items search and getItemBySource with any cast and ts-expect-error to satisfy type checks Improves readability and type safety without changing behavior.
This commit is contained in:
1 parent
ab37b477df
commit
f35fee944d
33 files changed
+811
-295
No files matched your search
+2
-2
@@ -3,7 +3,7 @@
|
||||
* Gerencia pool de conexões e fornece helpers para queries
|
||||
*/
|
||||
|
||||
import { Pool, QueryResult } from "pg";
|
||||
import { Pool, QueryResult, QueryResultRow } from "pg";
|
||||
|
||||
let pool: Pool | null = null;
|
||||
|
||||
@@ -54,7 +54,7 @@ export function getPool(): Pool {
|
||||
* @param params - Array de parâmetros para a query
|
||||
* @returns Resultado da query
|
||||
*/
|
||||
export async function query<T = any>(
|
||||
export async function query<T extends QueryResultRow = any>(
|
||||
text: string,
|
||||
params?: any[]
|
||||
): Promise<QueryResult<T>> {
|
||||
|
||||
@@ -92,7 +92,7 @@ export async function cancelBid(bidId: number): Promise<boolean> {
|
||||
[bidId]
|
||||
);
|
||||
|
||||
return result.rowCount > 0;
|
||||
return (result.rowCount ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -745,7 +745,7 @@ export async function deleteListing(listingId: number): Promise<boolean> {
|
||||
[listingId]
|
||||
);
|
||||
|
||||
return result.rowCount > 0;
|
||||
return (result.rowCount ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -114,7 +114,7 @@ export async function markAsRead(notificationId: number, userId: number): Promis
|
||||
[notificationId, userId]
|
||||
);
|
||||
|
||||
return result.rowCount > 0;
|
||||
return (result.rowCount ?? 0) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,6 +145,6 @@ export async function deleteNotification(notificationId: number, userId: number)
|
||||
[notificationId, userId]
|
||||
);
|
||||
|
||||
return result.rowCount > 0;
|
||||
return (result.rowCount ?? 0) > 0;
|
||||
}
|
||||
|
||||
@@ -195,9 +195,9 @@ export async function getUserBehavior(
|
||||
? "AND timestamp BETWEEN $2 AND $3"
|
||||
: "";
|
||||
|
||||
const params = [userId];
|
||||
const params: any[] = [userId];
|
||||
if (startDate && endDate) {
|
||||
params.push(startDate, endDate);
|
||||
params.push(startDate.getTime(), endDate.getTime());
|
||||
}
|
||||
|
||||
// Buscar queries de busca
|
||||
|
||||
Reference in new issue
Block a user