W
Wasp-lang5mo ago
Kbk

GetPaginatedTransactions problem with query with decimals

Hello I made simple object entity Transaction {=psl id Int @id @default(autoincrement()) type String fiatCurrency String cryptoCurrency String amountFiat Decimal exchangeRate Decimal commission Decimal amountCrypto Decimal createdAt DateTime @default(now()) status String user User @relation(fields: [userId], references: [id]) userId Int psl=} How to make query on this and display it in table? I have problem also with decimals do i need to convert them do strings? its sounds not good at all. I was trying to get those transaction based on GetPaginatedUsers quesry but always gettting errors
3 Replies
kapa.ai
kapa.ai5mo ago
Hi @Kbk. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. The knowledge sources provided do not contain information about handling decimals or creating a query for the Transaction entity in the context of Wasp. However, in general, to display data in a table, you would need to create a query to fetch the data from the Transaction entity and then use this data to populate the table. If you're having issues with decimals, it might be due to how the data is being handled in your query or table. For more specific guidance, I would recommend checking the Wasp documentation (https://wasp-lang.dev/docs) or asking for help in the Wasp community. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Kbk, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Kbk
Kbk5mo ago
I have this query in queries.ts to handle it ... export type GetPaginatedTransactionsInput = { skip: number; limit: number; typeFilter?: string; statusFilter?: string[]; }; export type GetPaginatedTransactionsOutput = { transactions: { id: number; type: string; fiatCurrency: string; cryptoCurrency: string; amountFiat: string; // Convert Decimal to string exchangeRate: string; // Convert Decimal to string commission: string; // Convert Decimal to string amountCrypto: string; // Convert Decimal to string createdAt: Date; status: string; userId: number; }[]; totalPages: number; }; export const getPaginatedTransactions: GetPaginatedTransactions<GetPaginatedTransactionsInput, GetPaginatedTransactionsOutput> = async ( args, context ) => { if (!context.user) { throw new HttpError(401, "User must be logged in to access their transactions."); } const whereClause: any = { userId: context.user.id }; if (args.typeFilter) whereClause.type = args.typeFilter; if (args.statusFilter) whereClause.status = { in: args.statusFilter }; const transactions = await context.entities.Transaction.findMany({ skip: args.skip, take: args.limit, where: whereClause, orderBy: { createdAt: 'desc' } }); const totalTransactionsCount = await context.entities.Transaction.count({ where: whereClause }); const totalPages = Math.ceil(totalTransactionsCount / args.limit); return { transactions: transactions.map(tran => ({ ...tran, amountFiat: tran.amountFiat.toString(), // Convert Decimal to string for safe JSON transmission exchangeRate: tran.exchangeRate.toString(), commission: tran.commission.toString(), amountCrypto: tran.amountCrypto.toString(), createdAt: tran.createdAt, status: tran.status, userId: tran.userId })), totalPages }; }; ... okay i got it works
martinsos
martinsos5mo ago
Hey @Kbk , glad to hear that! What was the issue? Anything we can improve on our side (docs, API, ...) to help others avoid making the same mistke?
Want results from more Discord servers?
Add your server