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
@@ -26,7 +26,7 @@ export interface CreateBidData {
|
||||
* Cria um novo lance
|
||||
*/
|
||||
export async function createBid(data: CreateBidData): Promise<Bid> {
|
||||
return await prisma.bid.create({
|
||||
const bid = await prisma.bid.create({
|
||||
data: {
|
||||
listing_id: data.listing_id,
|
||||
bidder_id: data.bidder_id,
|
||||
@@ -34,6 +34,11 @@ export async function createBid(data: CreateBidData): Promise<Bid> {
|
||||
bid_type: data.bid_type || null,
|
||||
},
|
||||
});
|
||||
return {
|
||||
...bid,
|
||||
bid_amount: Number(bid.bid_amount),
|
||||
bid_type: (bid.bid_type as "pix" | "tibia_coins" | "gold_coins" | null),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +48,7 @@ export async function getBidsByListing(
|
||||
listingId: number,
|
||||
activeOnly: boolean = true
|
||||
): Promise<Bid[]> {
|
||||
return await prisma.bid.findMany({
|
||||
const bids = await prisma.bid.findMany({
|
||||
where: {
|
||||
listing_id: listingId,
|
||||
...(activeOnly ? { is_active: true } : {}),
|
||||
@@ -53,13 +58,18 @@ export async function getBidsByListing(
|
||||
{ created_at: "desc" },
|
||||
],
|
||||
});
|
||||
return bids.map(bid => ({
|
||||
...bid,
|
||||
bid_amount: Number(bid.bid_amount),
|
||||
bid_type: (bid.bid_type as "pix" | "tibia_coins" | "gold_coins" | null),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Busca o maior lance de um anúncio
|
||||
*/
|
||||
export async function getHighestBid(listingId: number): Promise<Bid | null> {
|
||||
return await prisma.bid.findFirst({
|
||||
const bid = await prisma.bid.findFirst({
|
||||
where: {
|
||||
listing_id: listingId,
|
||||
is_active: true,
|
||||
@@ -69,6 +79,12 @@ export async function getHighestBid(listingId: number): Promise<Bid | null> {
|
||||
{ created_at: "desc" },
|
||||
],
|
||||
});
|
||||
if (!bid) return null;
|
||||
return {
|
||||
...bid,
|
||||
bid_amount: Number(bid.bid_amount),
|
||||
bid_type: (bid.bid_type as "pix" | "tibia_coins" | "gold_coins" | null),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +103,14 @@ export async function cancelBid(bidId: number): Promise<boolean> {
|
||||
* Busca lance por ID
|
||||
*/
|
||||
export async function getBidById(bidId: number): Promise<Bid | null> {
|
||||
return await prisma.bid.findUnique({
|
||||
const bid = await prisma.bid.findUnique({
|
||||
where: { bid_id: bidId },
|
||||
});
|
||||
if (!bid) return null;
|
||||
return {
|
||||
...bid,
|
||||
bid_amount: Number(bid.bid_amount),
|
||||
bid_type: (bid.bid_type as "pix" | "tibia_coins" | "gold_coins" | null),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user