Giter VIP home page Giter VIP logo

strichliste's Introduction

strichliste

Build Status Dependency Status devDependency Status

DEPRECATED

strichliste1 has been replaced by strichliste2. See https://github.com/strichliste for the new version!

This module is the API for the strichliste app. Arbitrary clients can be implemented using this API

Clients:

TOC

First Steps

Setup

Steps

Grab the latest release
install dependencies
$ npm i
run tests
$ npm run test
initialize database

creates the tables in the sqlitefile

$ npm run setup:database

everything at once

For your convenience the following npm script does all of the above steps at once:

$ npm run setup

start api server

Consider editing the configuration before starting the api server (see the configuration section).

$ npm run start

Configuration

The API server brings with it a default configuration which can be found in /configuration/default.js. This default can be used to setup your own configuration. The server utilizes the configurations module from npm which does a staged modification of configurations. Initially the default config is loaded and then subsequent modifications are applied.

You can add your own environment specific configuration by adding e.g. a production.js to the configurations folder. When the server is started with the node environment NODE_ENV set to production, the default config is enhanced by your production config. You don't have to specify each and every key from default.js, the defaults are retained.

You also can specify an external configuration sitting on an arbitrary place in your system by assigning it via a command line parameter:

$ node server.js --externalconfig=/etc/opt/strichliste/myconfig.js

Configuration details

This section explains the content of the default.json which can be modified by you as you wish

module.exports = {
    //the server runs on this port
    port: 8080,

    //details to the database
    database: {
        //the engine that should be used, until now only sqlite is supported
        type: 'SQLITE',

        //(arbitrary) options to the database engine
        options: {
            filename: 'data.sqlite'
        }
    },

    //strichliste announces actions via mqtt if desired
    mqtt: {
        //enable mqtt broadcasting
        enabled: false,

        //the mqtt service host
        host: 'localhost',

        // the mqtt service port
        port: 1883,

        //a list of topics that are broadcasted
        topics: {
            //gets broadcasted when someone adds a new transaction
            transactionValue: 'strichliste/transactionValue'
        }
    },

    //boundaries define values the apply to a user account or the transactions of auser
    boundaries: {
        account: {
            //the maximum amount that can be stored in a user's account (99999999 is equvalent to Inifinity)
            upper: 99999999,

            //the maximum dept a user can have
            lower: -50
        },
        transaction: {
            //the biggest transaction a user can do
            upper: 150,

            //the biggest money withdrawal a user can do
            lower: -20
        }
    },

    //logging
    logging: {
        //specifies if the api should log api access to the console
        active: true
    }
}

API Documentation

Every API answer has the Content-Type application/json. Data that is posted to the API is always JSON as well.

Pagination

At some endpoints the following queryparameters can be used to control the pagination of lists:

  • limit: the number of items to show
  • offset: the number of the first item in the list

Each of the paginated lists are of the following data structure:

{
  overallCount: <int>,
  limit: <int>,
  offset: <int>,
  entries: [<entry]
}

Endpoints

GET /user

Returns the complete list of all users. Each user is described via the following data structure:

{
  "id": <int>,
  "name": <string>,
  "mailAddress": <string>,
  "balance": <float>,
  "lastTransaction": <dateTime>,
  "countOfTransactions": <int>,
  "weightedCountOfPurchases": <int>,
  "activeDays": <int>
}

The parameters and the list structure of the Pagination section are used in this endpoint.

POST /user

Creates a new user. To create a new user a name and an optional mailAddress has to be assigned via the following data structure.

{
    "name": <string>,
    "mailAddress": <string>
}

Returns the status code 201 and the created user if the creation was successfull.

Errors
  • 409: If a user already exists

GET /transaction

Lists the latest transactions. Each transaction has the following data structure:

{
  id: <int>,
  userId: <int>,
  createDate: <DateTime>,
  value: <float>,
  comment: <string>
}

Use the parameters and the list structure of the Pagination section to specify the list's structure.

GET /user/:userId

Returns one specific user. The returned data structure correlates with the /user endpoint, additionally a list of the five last transactions is sent. (See the /user/transaction section for a reference to the transaction data structure)

Errors
  • 404: If the user could not be found

GET /user/:userId/transaction

Returns a list of transactions belonging to the user with the id :userId. The structure of the transactions object corresponds to the definiton of the '/transaction' route

The parameters and the list structure of the Pagination section are used in this endpoint.

Errors
  • 404: If the user could not be found

POST /user/:userId/transaction

Creates a new transaction for the user with the id :userId. The following data structure describes the transaction:

{
  value: <float>,
  comment: <string>,
  toUserId: <int>
}

Returns the status code 201 if a transaction was successfully created.

Errors
  • 400: If a transaction value is not a number or is zero.
  • 403: If a transaction value is above or below a certain border (configurable) or the resulting user balance would exceed a certain border (configurable).
  • 404: If the user has not been found

GET /user/:userId/transaction/:transactionId

Returns a certain transaction. The data structure corresponds to that of the /user/:userId/transaction section.

Errors
  • 404: If the user or the transaction could not be found

GET /settings

Returns the configured settings:

{
  boundaries: {
    upper: <int>
    lower: <int>
  }
}

For more details on the configuration see the configuration section.

GET /metrics

Returns metrics concerning the registered users and their transactions. Data structure:

{
  overallBalance: <float>,
  countTransactions: <int>,
  contUsers: <int>,
  avgBalance: <float>,
  days: [
    {
      date: <Date>,
      overallNumber: <int>,
      distinctUsers: <int>,
      dayBalance: <float>,
      dayBalancePositive: <float>,
      dayBalanceNegative: <float>
    }
  ]
}

strichliste's People

Contributors

bbbsnowball avatar greenkeeperio-bot avatar k00mi avatar nicohood avatar schinken avatar seriousmanual avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

strichliste's Issues

mqtt events

MQTT events for transactions. Make events configurable

mqtt: {
    host: 'mqtt.core.bckspc.de',
    port: 1883,
    topics: {
        transactionCreated: 'strichliste/transaction/create',
        userCreated: 'strichliste/user/create'
    }
}

something like dat.

datetime format is UTC

Currently I retrieve dates in UTC, which is not a problem but it's weird if you do an transaction at 20:00 and the displayed time is 18:00.

I'm not sure where the solution should be: frontend or backend? I think both. We need a different output date format with time zone to handle it correctly in the frontend

Extend /settings endpoint

Please return not just the accound boundaries, but also the transaction boundaries. Needed by strichliste-web for handling custom transactions

debug mqtt binding

after enabling the mqtt binding, the server does not start anymore (hangs?).

Server crash on missing field in POST /user/<userId>/transaction

TypeError: Cannot call method 'toString' of undefined
    at ServerResponse.writeHead (http.js:1178:45)
    at ServerResponse._implicitHeader (http.js:1129:8)
    at ServerResponse.OutgoingMessage.end (http.js:918:10)
    at ServerResponse.send (/opt/strichliste/node_modules/express/lib/response.js:189:8)
    at ServerResponse.json (/opt/strichliste/node_modules/express/lib/response.js:233:15)
    at ServerResponse.send (/opt/strichliste/node_modules/express/lib/response.js:132:21)
    at errorHandler (/opt/strichliste/lib/result/errorHandler.js:4:10)
    at Layer.handle_error (/opt/strichliste/node_modules/express/lib/router/layer.js:52:5)
    at trim_prefix (/opt/strichliste/node_modules/express/lib/router/index.js:261:13)
    at /opt/strichliste/node_modules/express/lib/router/index.js:230:9

Trying to reproduce. POC coming

Pin protection

Make it possible to protect a user by pin/password/callItWhatYouWant

cannot call method 'toString' of undefined

TypeError: Cannot call method 'toString' of undefined
    at ServerResponse.writeHead (http.js:1180:45)
    at ServerResponse._implicitHeader (http.js:1131:8)
    at ServerResponse.OutgoingMessage.end (http.js:920:10)
    at ServerResponse.send (/home/schinken/strichliste/strichliste/node_modules/express/lib/response.js:189:8)
    at /home/schinken/strichliste/strichliste/lib/bootstrap.js:32:17
    at Layer.handle_error (/home/schinken/strichliste/strichliste/node_modules/express/lib/router/layer.js:52:5)
    at trim_prefix (/home/schinken/strichliste/strichliste/node_modules/express/lib/router/index.js:261:13)
    at /home/schinken/strichliste/strichliste/node_modules/express/lib/router/index.js:230:9
    at Function.proto.process_params (/home/schinken/strichliste/strichliste/node_modules/express/lib/router/index.js:305:12)
    at /home/schinken/strichliste/strichliste/node_modules/express/lib/router/index.js:221:12

Rename to strichliste-api

Rename to strichliste-api, so that we can later create a strichliste package that contains the api and a ready-to-use build of the frontend.

@schinken thoughts on this?

Add API call to query transactions per user per day

We want to implement a script which sends a mail per user with all transactions of the past day. Unfortunately there's no API call to filter the transactions per date, so I'd have to query all transactions and filter the result in the script.

An API call which returns a structure with all users and their transactions of the date specified would be very handy to simplify this. Users with no transactions should be hidden in this result.

Of course the local timezone should be considered.

Add e-mail address to user

Add e-mail address to user table and provide a migrate script which is automatically executed if it's missing for the specific version.

Add e-mail address to api response, too

Configurable database backend

Maybe it would be nice to have other database backends and introduce a query builder like squel.js with this step.

The reason is: I think it would be nice that one can use mysql if there's already a running instance, because multiple applications an query the database - not just one using the sqlite database

transaction boundary

I'd propose 150€+ and 20€- (14 Club Mate à 1,50€ on credit, should be enough IMO).

Limit a single transaction. these could be the defaults as proposed by else in #21

Add product database

Add possibility to store EAN Codes, Product Names and Price

POST /user/:userId/transaction should also support { eanCode: "....." }

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.