adrianhajdin / banking

Horizon is a modern banking platform for everyone.
https://banking-jet.vercel.app
MIT License
1.9k stars 574 forks source link

transaction list #18

Closed akashkumar23 closed 4 months ago

akashkumar23 commented 4 months ago

I am not getting the list of sample transactions ? Do any one facing the same issue ?

ArthurDias01 commented 4 months ago

yep. I'm getting this error:

AppwriteException [Error]: Invalid query: Attribute not found in schema: senderBankId
    at Client.call (webpack-internal:///(rsc)/./node_modules/node-appwrite/lib/client.js:206:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Databases.listDocuments (webpack-internal:///(rsc)/./node_modules/node-appwrite/lib/services/databases.js:1658:16)
    at async $$ACTION_1 (webpack-internal:///(rsc)/./src/lib/actions/transaction.actions.ts:40:36)
    at async $$ACTION_1 (webpack-internal:///(rsc)/./src/lib/actions/bank.action.ts:88:42)
    at async Home (webpack-internal:///(rsc)/./app/(root)/page.tsx:39:21) {
  code: 400,
  type: 'general_query_invalid',
  response: {
    message: 'Invalid query: Attribute not found in schema: senderBankId',
    code: 400,
    type: 'general_query_invalid',
    version: '1.5.7'
  }
}
akashkumar23 commented 4 months ago

I am getting account: undefined

ArthurDias01 commented 4 months ago

I've got a fix for it.

On transactions.acton.ts:


"use server";

import { ID } from "node-appwrite";
import { createAdminClient } from "../appwrite";
import { parseStringify } from "../utils";

const {
  APPWRITE_DATABASE_ID: DATABASE_ID,
  APPWRITE_TRANSACTION_COLLECTION_ID: TRANSACTION_COLLECTION_ID,
} = process.env;

export const createTransaction = async (
  transaction: CreateTransactionProps
) => {
  try {
    const { database } = await createAdminClient();

    const newTransaction = await database.createDocument(
      DATABASE_ID!,
      TRANSACTION_COLLECTION_ID,
      ID.unique(),
      {
        channel: "online",
        category: "Transfer",
        ...transaction,
      }
    );

    return parseStringify(newTransaction);
  } catch (error) {
    console.error(error)
  }
};

export const getTransactionsByBankId = async ({
  bankId,
}: getTransactionsByBankIdProps) => {
  try {
    const { database } = await createAdminClient();

    const senderTransactions = await database.listDocuments(
      DATABASE_ID,
      TRANSACTION_COLLECTION_ID
      // [Query.equal("senderBankId", bankId)]
    );

    const receiverTransactions = await database.listDocuments(
      DATABASE_ID!,
      TRANSACTION_COLLECTION_ID!
      // [Query.equal("receiverBankId", bankId)]
    );

    const transactions = {
      total: senderTransactions.total + receiverTransactions.total,
      documents: [
        ...senderTransactions.documents,
        ...receiverTransactions.documents,
      ],
    };

    return parseStringify(transactions);
  } catch (error) {
    console.error(error)
  }
};
akashkumar23 commented 4 months ago

Screenshot 2024-06-02 045546 @ArthurDias01 do you get account: undefined , like this ?

ArthurDias01 commented 4 months ago

Screenshot 2024-06-02 045546 @ArthurDias01 do you get account: undefined , like this ?

I was, just change the file like I showed in the last msg and it all worked afterwards

akashkumar23 commented 4 months ago

It worked for me!! thanks @ArthurDias01

akashkumar23 commented 4 months ago

Hi @ArthurDias01 , I can see that you removed the query from the appwrite database and the problem solved. Can you explain why / how did it work? I can also see that those sample transactions are not the part of my appwrite transactions

shefcodev commented 3 months ago

thanks @ArthurDias01 I was getting the same error. your solution worked.

bustillos83 commented 2 months ago

I copied the code and i get this,

code: 404, type: 'collection_not_found', response: { message: 'Collection with the requested ID could not be found.', code: 404, type: 'collection_not_found', version: '1.5.8' } } An error occurred while getting the account: TypeError: Cannot read properties of undefined (reading 'documents')
at $$ACTION_1 (webpack-internal:///(rsc)/./lib/actions/bank.actions.ts:89:63) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Home (webpack-internal:///(rsc)/./app/(root)/page.tsx:46:5) GET /?_rsc=3rnhc 200 in 2810ms

dedane commented 1 month ago

Hi @ArthurDias01 , I can see that you removed the query from the appwrite database and the problem solved. Can you explain why / how did it work? I can also see that those sample transactions are not the part of my appwrite transactions

did you get the reasion why it worked after doing this???

AJ-DEVS99 commented 3 weeks ago

I've got a fix for it.

On transactions.acton.ts:

"use server";

import { ID } from "node-appwrite";
import { createAdminClient } from "../appwrite";
import { parseStringify } from "../utils";

const {
  APPWRITE_DATABASE_ID: DATABASE_ID,
  APPWRITE_TRANSACTION_COLLECTION_ID: TRANSACTION_COLLECTION_ID,
} = process.env;

export const createTransaction = async (
  transaction: CreateTransactionProps
) => {
  try {
    const { database } = await createAdminClient();

    const newTransaction = await database.createDocument(
      DATABASE_ID!,
      TRANSACTION_COLLECTION_ID,
      ID.unique(),
      {
        channel: "online",
        category: "Transfer",
        ...transaction,
      }
    );

    return parseStringify(newTransaction);
  } catch (error) {
    console.error(error)
  }
};

export const getTransactionsByBankId = async ({
  bankId,
}: getTransactionsByBankIdProps) => {
  try {
    const { database } = await createAdminClient();

    const senderTransactions = await database.listDocuments(
      DATABASE_ID,
      TRANSACTION_COLLECTION_ID
      // [Query.equal("senderBankId", bankId)]
    );

    const receiverTransactions = await database.listDocuments(
      DATABASE_ID!,
      TRANSACTION_COLLECTION_ID!
      // [Query.equal("receiverBankId", bankId)]
    );

    const transactions = {
      total: senderTransactions.total + receiverTransactions.total,
      documents: [
        ...senderTransactions.documents,
        ...receiverTransactions.documents,
      ],
    };

    return parseStringify(transactions);
  } catch (error) {
    console.error(error)
  }
};

I assume that worked because we have no bank information yet, but not sure and just thank u for providing this code