GithubHelp home page GithubHelp logo

codex-accounting's Introduction

CodeX Accounting

Microservice for accounting📋

How to run accounting service

  1. Copy and rename file .env.sample to .env.

  2. Generate two UUIDv4 IDs for cashbook and revenue accounts. You can use online generators (see https://www.uuidgenerator.net/version4).

  3. Add information about cashbook and revenue to .env file:

    Example:

    # Accounting Cashbook account identifier
    CASHBOOK_ACCOUNT_ID=#Your UUIDv4 cashbook account ID
    CASHBOOK_ACCOUNT_NAME="Hawk Cashbook account"
    
    # Accounting Revenue account identifier
    REVENUE_ACCOUNT_ID=#Your UUIDv4 revenue account ID
    REVENUE_ACCOUNT_NAME="Hawk Revenue account"
  4. Install dependencies by yarn install.

  5. Run accounting service by yarn dev or yarn docker:up commands.

  6. Run MongoDB migrations by yarn migrate:up.

    You will see a message like this:

    yarn run v1.21.1
    $ migrate-mongo up
    MIGRATED UP: 20200724163828-base-accounts.js
    Done in 1.26s.
    

🎉Now you can use accounting service in your projects🎉

codex-accounting's People

Contributors

dependabot[bot] avatar gohabereg avatar ilyamore88 avatar khaydarov avatar n0str avatar nespecc avatar nikmel2803 avatar ranemihir avatar sunnycapt avatar talyguryn avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

codex-accounting's Issues

Implement database controller

Нужен модуль (класс) для подключения к БД (наверное, удобнее всего через синглтон)
Он будет инициализироваться при старте сервера. Модели и репозитории должны получать соединение с БД через конструктор
Вот пример из АПИ, где настраиваются фабрики (в аккаунтинге это репозитории) и им передаётся коннект к БД: https://github.com/codex-team/hawk.api.nodejs/blob/dea398daead3a457f968e72b6d0b58ee4960f10c/src/index.ts#L125-L140

Вот имплементация контроллера в воркерах: https://github.com/codex-team/hawk.workers/blob/master/lib/db/controller.ts

И тесты к нему: https://github.com/codex-team/hawk.workers/blob/master/lib/db/controller.test.ts

TypeError: Class constructor ApolloError cannot be invoked without 'new' (src/resolvers/deposits.ts:54)

I encountered with this error in the docker container logs. It is related to the ApolloError class not being called with the new keyword. But that doesn't actually seem to be the case.

In src/errors.ts (line 25), NonCriticalError class extends the ApolloError class.
In the src/resolvers/deposit.ts (line 54), calls the extended NonCriticalError class with the new keyword. So it should work fine.

Could be a problem with my setup, thought I should report about this.

TypeError: Class constructor ApolloError cannot be invoked without 'new'
at new NonCriticalError (/usr/src/app/src/errors.ts:25:42)
at /usr/src/app/src/resolvers/deposits.ts:54:13
at step (/usr/src/app/src/resolvers/deposits.ts:52:23)
at Object.next (/usr/src/app/src/resolvers/deposits.ts:33:53)
at /usr/src/app/src/resolvers/deposits.ts:27:71
at new Promise (<anonymous>)
at __awaiter (/usr/src/app/src/resolvers/deposits.ts:23:12)
at deposit (/usr/src/app/src/resolvers/deposits.ts:72:16)
at field.resolve (/usr/src/app/node_modules/graphql-extensions/src/index.ts:274:18)
at field.resolve (/usr/src/app/node_modules/apollo-server-core/src/utils/schemaInstrumentation.ts:103:18)

Создать резолвер для мутации purchase

Для примера см. мутацию deposit.

    ....
    const revenueAccountId = process.env.REVENUE_ACCOUNT_ID as string;

    if (!revenueAccountId) {
      return null;
    }

    const revenue = await accountRepository.find(revenueAccountId);
    const account = await accountRepository.find(accountId);

    if (revenue === null || account === null) {
      return null;
    }

    const transaction = new Transaction({
      type: TransactionType.Purchase,
      description: description,
    });

    transaction
      .debit(account, amount)
      .credit(revenue, amount);

Создать Resolver для мутации Withdraw

Для примера см. мутацию deposit.

    ....
    const cashbookId = process.env.CASHBOOK_ACCOUNT_ID as string;

    if (!cashbookId) {
      return null;
    }

    const cashbook = await accountRepository.find(cashbookId);
    const account = await accountRepository.find(accountId);

    if (cashbook === null || account === null) {
      return null;
    }

    const transaction = new Transaction({
      type: TransactionType.Withdraw,
      description: description,
    });

    transaction
      .debit(account, amount)
      .credit(cashbook, amount);

Создать модель баланса и сервис для его получения

Нужно создать отдельную модель и тип для баланса balance, в котором будут два свойства: значение баланса и валюта. У сервиса должна быть функция, которая получает баланс в промежутке dateStart-dateEnd. Если дата начала не задана, то слева дата не ограничивается, а dateEnd по умолчанию = Date.now().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.