Skip to content

25th-floor/ttrack-server

Repository files navigation

TTrack Server

Build Status

A node Time Tracking application server. Needs a Postgres Database and a client.

Dockerhub: https://hub.docker.com/r/25thfloor/ttrack-server/

Working

Makefile

Our setups always include a Makefile which helps with the setup. Needs Docker!

To see all possible targets just enter make to your cli.

Targets:

  • up: Starts the whole development stack

  • start: Start the stack in detached mode

  • rm: remove the development stack

  • yarn: to call yarn commands in the running development stack like for example make yarn test to run the tests.

  • shell: get a shell within the server container

  • postgres: get a shell within the postgres container

Development

Just call make up and it will start the node server in development mode and a postgres database instance with some basic database setup.

The node server will expose port 8000 and 8001 while postgres will expose 5432 for development purposes.

Testing

To test the server code you need a running development environment, therefor you need to call make up prior to the tests.

Then just calling make yarn test will run the tests using yarn in the server container.

Production

The Docker Image is located at https://hub.docker.com/r/25thfloor/ttrack-server.

It needs a running Database and can be configured using environment variables.

The needed variables are:

  • DB_HOST: your database hostname
  • DB_DATABASE: your database name
  • DB_USER: your database user
  • DB_PASSWORD: your password

Additional there are some optional ones too:

  • NODE_ENV: production
  • HOST: 0.0.0.0
  • PORT: 8000
  • DB_DRIVER: pg
  • DB_PORT: 5432
  • DB_SCHEMA: public

One more thing, Sentry has been prepared so if you want to use it you just need to add your token as environment variable. If you don't use sentry then just ignore the environment variable.

  • SENTRY_TOKEN: your sentry token

Documentation

API

The hapi server uses the swagger plugin to show the rest api documentation.

You can access it while the server is running using http://localhost:8000/docs.

Database functions

There are several functions implemented which do much of the work.

Functions for administration that are not used by the code
  • create_user(firstname text, lastname text, email text, employment_start date, target interval): create a new user and it corresponding target time
  • user_add_new_target_time(id integer, startdate date, target interval): change target time for a user and also update days and periods.
  • user_get_periods_for_type(id integer, start_date date, period_type character varying DEFAULT 'Vacation'::character varying): get vacations for given user starting with start_date
  • user_worktime(id INTEGER, due_date DATE): helper function to analyze the carry calculations in the database for given user
Functions used by the code
  • user_calculate_carry_time(id INTEGER, due_date DATE): calculates carry time for given user
  • user_get_day_periods(id INTEGER, date_from TIMESTAMP, date_to TIMESTAMP): Return days between the interval for the user including the periods for that time
  • user_get_start_date(id integer): get first date for a user relevant for ttrack
  • user_get_target_time(id INTEGER, day_date DATE): get the calculated target time for a user on a given date.
  • ttrack_get_all_vacations(): get all vacations of all users from now to the beginning of ttrack
Helper Functions used by other Functions
  • user_get_average_day_time(id integer, day_date date): get the average day time of a user, does not check for workdays. (used by user_get_target_time)

Administration

To setup the users you need to be comfortable using the psql shell and working with the database as there is no Administration Interface, everything is done using pure sql. The user table is your main starting point.

Add a User

You can use the database function create_user to add a user with a target time.

Change Target Time

Users change their target time for whatever reason. TTrack is able to handle this. You can always change the target time at a specific point in time using the user_add_new_target_time database function.

Contributors

Since because of security concerns we needed to purge the git commit history, here are the contributors of the project.

History

It all started as a fun project and never majored of it. It is strictly a tool for tracking our times with our needs. (f.e. Austrian Holidays, no Administration, ...)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published