style: clean up code formatting and remove trailing whitespace

refactor: reorganize imports and fix type imports
This commit is contained in:
Evandro Fonseca Junior committed 2025-11-11 03:08:36 -03:00
1 parent d3704602fd
commit 47c04de6fe
232 files changed
+7140 -4798

No files matched your search

+25 -13
View File
@@ -8,7 +8,13 @@ import { query } from "../index";
export interface Notification {
notification_id: number;
user_id: number;
notification_type: "bid" | "sale" | "purchase" | "escrow" | "dispute" | "system";
notification_type:
| "bid"
| "sale"
| "purchase"
| "escrow"
| "dispute"
| "system";
title: string;
message: string;
related_id: number | null;
@@ -31,7 +37,7 @@ export interface CreateNotificationData {
* Cria uma nova notificação
*/
export async function createNotification(
data: CreateNotificationData
data: CreateNotificationData,
): Promise<Notification> {
const result = await query<Notification>(
`
@@ -46,7 +52,7 @@ export async function createNotification(
data.message,
data.related_id || null,
data.send_whatsapp || false,
]
],
);
return result.rows[0];
@@ -57,7 +63,7 @@ export async function createNotification(
*/
export async function getUserNotifications(
userId: number,
filters: { is_read?: boolean; limit?: number } = {}
filters: { is_read?: boolean; limit?: number } = {},
): Promise<Notification[]> {
const { is_read, limit = 50 } = filters;
@@ -71,7 +77,8 @@ export async function getUserNotifications(
paramIndex++;
}
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
const whereClause =
conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
const result = await query<Notification>(
`
@@ -80,7 +87,7 @@ export async function getUserNotifications(
ORDER BY created_at DESC
LIMIT $${paramIndex}
`,
[...params, limit]
[...params, limit],
);
return result.rows;
@@ -95,7 +102,7 @@ export async function getUnreadCount(userId: number): Promise<number> {
SELECT COUNT(*) as count FROM notifications
WHERE user_id = $1 AND is_read = FALSE
`,
[userId]
[userId],
);
return parseInt(result.rows[0].count, 10);
@@ -104,14 +111,17 @@ export async function getUnreadCount(userId: number): Promise<number> {
/**
* Marca notificação como lida
*/
export async function markAsRead(notificationId: number, userId: number): Promise<boolean> {
export async function markAsRead(
notificationId: number,
userId: number,
): Promise<boolean> {
const result = await query(
`
UPDATE notifications
SET is_read = TRUE
WHERE notification_id = $1 AND user_id = $2
`,
[notificationId, userId]
[notificationId, userId],
);
return (result.rowCount ?? 0) > 0;
@@ -127,7 +137,7 @@ export async function markAllAsRead(userId: number): Promise<number> {
SET is_read = TRUE
WHERE user_id = $1 AND is_read = FALSE
`,
[userId]
[userId],
);
return result.rowCount || 0;
@@ -136,15 +146,17 @@ export async function markAllAsRead(userId: number): Promise<number> {
/**
* Remove notificação
*/
export async function deleteNotification(notificationId: number, userId: number): Promise<boolean> {
export async function deleteNotification(
notificationId: number,
userId: number,
): Promise<boolean> {
const result = await query(
`
DELETE FROM notifications
WHERE notification_id = $1 AND user_id = $2
`,
[notificationId, userId]
[notificationId, userId],
);
return (result.rowCount ?? 0) > 0;
}