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

+31 -23
View File
@@ -2,10 +2,15 @@
* Queries de Purchase Intentions usando Prisma
*/
import { prisma } from "../app";
import { Prisma } from "@prisma/client";
import { prisma } from "../app";
export type PurchaseIntentionStatus = "pending" | "accepted" | "rejected" | "expired" | "completed";
export type PurchaseIntentionStatus =
| "pending"
| "accepted"
| "rejected"
| "expired"
| "completed";
export type PaymentMethod = "pix" | "tibia_coins" | "gold_coins" | "trade";
export interface CreatePurchaseIntentionData {
@@ -54,7 +59,8 @@ function serializePurchaseIntention(intention: any): PurchaseIntention {
return {
...intention,
custom_offer_amount:
intention.custom_offer_amount !== null && intention.custom_offer_amount !== undefined
intention.custom_offer_amount !== null &&
intention.custom_offer_amount !== undefined
? Number(intention.custom_offer_amount)
: null,
custom_offer_currency: intention.custom_offer_currency ?? null,
@@ -66,7 +72,7 @@ function serializePurchaseIntention(intention: any): PurchaseIntention {
* Cria uma nova intenção de compra
*/
export async function createPurchaseIntention(
data: CreatePurchaseIntentionData
data: CreatePurchaseIntentionData,
): Promise<PurchaseIntention> {
const result = await prisma.purchaseIntention.create({
data: {
@@ -77,12 +83,14 @@ export async function createPurchaseIntention(
expires_at: data.expires_at || null,
status: "pending",
custom_offer_amount:
data.custom_offer_amount !== undefined && data.custom_offer_amount !== null
data.custom_offer_amount !== undefined &&
data.custom_offer_amount !== null
? new Prisma.Decimal(data.custom_offer_amount)
: null,
custom_offer_currency: data.custom_offer_currency || null,
custom_offer_created_at:
data.custom_offer_amount !== undefined && data.custom_offer_amount !== null
data.custom_offer_amount !== undefined &&
data.custom_offer_amount !== null
? new Date()
: null,
},
@@ -112,7 +120,7 @@ export async function createPurchaseIntention(
*/
export async function getPurchaseIntentionsByListing(
listingId: number,
filters: { status?: PurchaseIntentionStatus; limit?: number } = {}
filters: { status?: PurchaseIntentionStatus; limit?: number } = {},
): Promise<PurchaseIntention[]> {
const { status, limit = 50 } = filters;
@@ -151,7 +159,7 @@ export async function getPurchaseIntentionsByListing(
*/
export async function getPurchaseIntentionsByBuyer(
buyerId: number,
filters: { status?: PurchaseIntentionStatus; limit?: number } = {}
filters: { status?: PurchaseIntentionStatus; limit?: number } = {},
): Promise<PurchaseIntention[]> {
const { status, limit = 50 } = filters;
@@ -189,7 +197,7 @@ export async function getPurchaseIntentionsByBuyer(
* Busca uma intenção específica por ID
*/
export async function getPurchaseIntentionById(
intentionId: number
intentionId: number,
): Promise<PurchaseIntention | null> {
const intention = await prisma.purchaseIntention.findUnique({
where: { intention_id: intentionId },
@@ -220,7 +228,7 @@ export async function getPurchaseIntentionById(
export async function updatePurchaseIntentionStatus(
intentionId: number,
status: PurchaseIntentionStatus,
sellerResponse?: string
sellerResponse?: string,
): Promise<PurchaseIntention> {
const updateData: any = {
status,
@@ -264,7 +272,9 @@ export async function updatePurchaseIntentionStatus(
/**
* Conta intenções pendentes de um anúncio
*/
export async function getPendingIntentionsCount(listingId: number): Promise<number> {
export async function getPendingIntentionsCount(
listingId: number,
): Promise<number> {
return await prisma.purchaseIntention.count({
where: {
listing_id: listingId,
@@ -278,7 +288,7 @@ export async function getPendingIntentionsCount(listingId: number): Promise<numb
*/
export async function hasPendingIntention(
listingId: number,
buyerId: number
buyerId: number,
): Promise<boolean> {
const count = await prisma.purchaseIntention.count({
where: {
@@ -296,7 +306,7 @@ export async function hasPendingIntention(
*/
export async function getPendingIntentionByBuyerAndListing(
listingId: number,
buyerId: number
buyerId: number,
): Promise<PurchaseIntention | null> {
const intention = await prisma.purchaseIntention.findFirst({
where: {
@@ -333,7 +343,7 @@ export async function getPendingIntentionByBuyerAndListing(
*/
export async function updatePurchaseIntentionPaymentMethod(
intentionId: number,
newPaymentMethod: PaymentMethod
newPaymentMethod: PaymentMethod,
): Promise<PurchaseIntention> {
// Buscar intenção atual
const intention = await prisma.purchaseIntention.findUnique({
@@ -346,7 +356,9 @@ export async function updatePurchaseIntentionPaymentMethod(
// Verificar se pode trocar (máximo 1 troca)
if (intention.payment_method_change_count >= 1) {
throw new Error("Você já atingiu o limite de trocas de método de pagamento");
throw new Error(
"Você já atingiu o limite de trocas de método de pagamento",
);
}
// Verificar se o novo método é diferente
@@ -388,7 +400,7 @@ export async function updatePurchaseIntentionPaymentMethod(
*/
export async function getPendingIntentionListingIdsForBuyer(
buyerId: number,
listingIds: number[]
listingIds: number[],
): Promise<number[]> {
if (listingIds.length === 0) {
return [];
@@ -416,7 +428,7 @@ export async function getPendingIntentionListingIdsForBuyer(
}
export async function getHighestCustomOfferForListing(
listingId: number
listingId: number,
): Promise<{ amount: number; currency: string } | null> {
const offer = await prisma.purchaseIntention.findFirst({
where: {
@@ -443,7 +455,7 @@ export async function getHighestCustomOfferForListing(
}
export async function getHighestCustomOffersForListings(
listingIds: number[]
listingIds: number[],
): Promise<Map<number, { amount: number; currency: string }>> {
if (listingIds.length === 0) {
return new Map();
@@ -461,10 +473,7 @@ export async function getHighestCustomOffersForListings(
custom_offer_amount: true,
custom_offer_currency: true,
},
orderBy: [
{ listing_id: "asc" },
{ custom_offer_amount: "desc" },
],
orderBy: [{ listing_id: "asc" }, { custom_offer_amount: "desc" }],
});
const result = new Map<number, { amount: number; currency: string }>();
@@ -479,4 +488,3 @@ export async function getHighestCustomOffersForListings(
return result;
}