Code Monkey home page Code Monkey logo

backend's Introduction

Wallfair. Playmoney V1 Server-Side

Usage

Step 1: Download repo and install modules

git clone https://github.com/wallfair-organization/backend
cd backend
npm install

Step 2: Start the docker containers needed

docker-compose -f docker/docker-compose.yml up -d

Step 3: Configure the mongo container for replication

docker exec -it mongodb-wall bash

mongo -u wallfair -p wallfair admin
use wallfair

rs.initiate( {
   _id : "rs0",
   members: [
      { _id: 0, host: "localhost:27017" },
   ]
});

Step 4: Run the postgresql config

docker exec -it docker_postgres_1 bash
psql -U postgres testdb

CREATE TABLE IF NOT EXISTS token_transactions (ID SERIAL PRIMARY KEY, sender varchar(255) not null, receiver varchar(255) not null, amount bigint not null, symbol varchar(255) not null, trx_timestamp timestamp not null);
CREATE TABLE IF NOT EXISTS token_balances (owner varchar(255) not null, balance bigint not null, symbol varchar(255) not null, last_update timestamp not null, PRIMARY KEY(owner, symbol));
CREATE TABLE IF NOT EXISTS bet_reports (bet_id varchar(255) not null PRIMARY KEY, reporter varchar(255) not null, outcome smallint not null, report_timestamp timestamp not null);
CREATE TABLE IF NOT EXISTS amm_interactions (ID SERIAL PRIMARY KEY, buyer varchar(255) NOT NULL, bet varchar(255) NOT NULL, outcome smallint NOT NULL, direction varchar(10) NOT NULL, investmentAmount bigint NOT NULL, feeAmount bigint NOT NULL, outcomeTokensBought bigint NOT NULL, trx_timestamp timestamp NOT NULL);
CREATE TABLE IF NOT EXISTS casino_trades (ID SERIAL PRIMARY KEY, userId varchar(255) NOT NULL, crashFactor decimal NOT NULL, stakedAmount bigint NOT NULL, state smallint NOT NULL, gameId varchar(255), created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP);

Step 5: Create a .env file (see .env.example) and start the server with:

# copy .env file from email
npm run start

Api-Endpoints

Auth

Header: "Authorization: Bearer jwtToken"

User Endpoints

Request:

{
  "phone": "+49123123123"
}

Successful Result:

{
  "phone": "+49123123123",
  "smsStatus": "pending"
}

Request:

{
  "phone": "+49123123123",
  "smsToken": "013416"
}

Successful Result:

{
  "userId": "608ae87f8e78eb0224ad3e28",
  "phone": "+49123123123",
  "name*": "Max",
  "email*": "[email protected]",
  "session": "jwtToken"
}

*Optional only if provided

Successful Result:

{
  "userId": "608ae87f8e78eb0224ad3e28",
  "name*": "Max",
  "profilePictureUrl*": "https://previewImageUrl.asd",
  "balance": 900
}

Successful Result:

[
    {
        "id": 1,
        "buyer": "60cf4588bf102d5fc4c1b475",
        "bet": "60cf46a61ef95168648364ab",
        "outcome": "yes",
        "direction": "BUY",
        "investmentamount": "100000",
        "feeamount": "1000",
        "outcometokensbought": "197902",
        "trx_timestamp": "2021-06-20T13:47:38.937Z"
    },
    {
        "id": 2,
        "buyer": "60cf4588bf102d5fc4c1b475",
        "bet": "60cf46a61ef95168648364ab",
        "outcome": "yes",
        "direction": "SELL",
        "investmentamount": "49541",
        "feeamount": "1000",
        "outcometokensbought": "100000",
        "trx_timestamp": "2021-06-20T19:20:08.487Z"
    }
]

Successful Result:

{
  "userId": "60b50d820619b44617959d43",
  "refList": [
    {
      "id": "60b50d820619b44617959d43",
      "name": "Nicholas",
      "email": "[email protected]"
    }
  ]
}

*Optional only if provided

Event Endpoints

Successful Result:

{
  "_id": "6091c24cae92745024088c74",
  "title": "test",
  "liveMode": true,
  "liveStreamUrl": "https://www.google.de/",
  "endDate": "1999-12-31T23:00:00.000Z",
  "date": "2021-05-04T21:53:16.734Z",
  "__v": 0
}

Successful Result:

[
  {
    "bets": [
      {
        "_id": "60a7ff5364dee4f956660797",
        "marketQuestion": "Wer gewinnt Redbull",
        "hot": true,
        "outcomes": [
          {
            "index": 0,
            "name": "Jonas"
          },
          {
            "index": 0,
            "name": "Jörn"
          }
        ],
        "event": "60a7f9bdc0a1a7f8913b4a23",
        "creator": "60a35b31bbb1f700155f2066",
        "date": "2021-05-21T18:43:31.908Z",
        "__v": 0
      },
      {
        "_id": "60a7ffb464dee4f956660799",
        "marketQuestion": "Wer gewinnt Redbull2",
        "hot": true,
        "outcomes": [
          {
            "index": 0,
            "name": "Jonas"
          },
          {
            "index": 0,
            "name": "Jörn"
          }
        ],
        "event": "60a7f9bdc0a1a7f8913b4a23",
        "creator": "60a35b31bbb1f700155f2066",
        "date": "2021-05-21T18:45:08.324Z",
        "__v": 0
      }
    ],
    "_id": "60a7f9bdc0a1a7f8913b4a23",
    "name": "Redbull",
    "tags": [
      {
        "_id": "60a7f9bdc0a1a7f8913b4a24",
        "name": "jo"
      },
      {
        "_id": "60a7f9bdc0a1a7f8913b4a25",
        "name": "joooo"
      }
    ],
    "previewImageUrl": "https://previewImageUrl.asd",
    "streamUrl": "https://google.com",
    "date": "2021-05-21T18:19:41.671Z",
    "__v": 2
  }
]
  • :type can be 'all', 'streamed', 'non-streamed', 'game'
  • :category can be 'all', 'streamed-esports', 'streamed-shooter', 'streamed-mmorpg', 'streamed-other', 'sports', 'politics', 'crypto', 'celebrities', 'other'
  • :searchQuery is optional
  • :page is 1-based
  • :sortby is an Event property to be used in mongoose syntax (ex: name (asc), -name (desc))

Successful Result:

[
    {
        "_id": "6107e58bf0a40958ecaab7f3",
        "bets": [
            "6107e5c9f0a40958ecaab932",
            "6107e704f0a40958ecaac05a"
        ],
        "name": "FIFA Match CyrusTwo",
        "streamUrl": "...",
        "previewImageUrl": "...",
        "tags": [
            {
                "_id": "6107e58bf0a40958ecaab7f4",
                "name": "fifa"
            },
            {
                "_id": "6107e58bf0a40958ecaab7f5",
                "name": "soccer"
            }
        ],
        "date": "2021-08-02T22:00:00.000Z",
        "__v": 2,
        "category": "Esports",
        "type": "streamed"
    }
]

Request:

{
  "name": "Redbull",
  "tags": [
    { "name": "jo" },
    { "name": "joooo" }
  ],
  "streamUrl": "https://google.com",
  "previewImageUrl": "https://previewImageUrl.asd"
}

Successful Result:

{
  "_id": "60a7f9bdc0a1a7f8913b4a23",
  "name": "Redbull",
  "tags": [
    {
      "_id": "60a7f9bdc0a1a7f8913b4a24",
      "name": "jo"
    },
    {
      "_id": "60a7f9bdc0a1a7f8913b4a25",
      "name": "joooo"
    }
  ],
  "previewImageUrl": "https://previewImageUrl.asd",
  "streamUrl": "https://google.com",
  "bets": [],
  "date": "2021-05-21T18:19:41.671Z",
  "__v": 0
}

Bet Endpoints

Request:

{
  "eventId": "60a7f9bdc0a1a7f8913b4a23",
  "marketQuestion": "Wer gewinnt Redbull",
  "hot": true,
  "outcomes": [
    {
      "index": 0,
      "name": "Jonas"
    },
    {
      "index": 0,
      "name": "Jörn"
    }
  ],
  "endDate": "1621622318001"
}

Successful Result:

{
  "bets": [
    {
      "_id": "60a7ff5364dee4f956660797",
      "marketQuestion": "Wer gewinnt Redbull",
      "hot": true,
      "outcomes": [
        {
          "index": 0,
          "name": "Jonas"
        },
        {
          "index": 0,
          "name": "Jörn"
        }
      ],
      "event": "60a7f9bdc0a1a7f8913b4a23",
      "creator": "60a35b31bbb1f700155f2066",
      "date": "2021-05-21T18:43:31.908Z",
      "__v": 0
    },
    {
      "_id": "60a7ffb464dee4f956660799",
      "marketQuestion": "Wer gewinnt Redbull2",
      "hot": true,
      "outcomes": [
        {
          "index": 0,
          "name": "Jonas"
        },
        {
          "index": 0,
          "name": "Jörn"
        }
      ],
      "event": "60a7f9bdc0a1a7f8913b4a23",
      "creator": "60a35b31bbb1f700155f2066",
      "date": "2021-05-21T18:45:08.324Z",
      "__v": 0
    }
  ],
  "_id": "60a7f9bdc0a1a7f8913b4a23",
  "name": "Redbull",
  "tags": [
    {
      "_id": "60a7f9bdc0a1a7f8913b4a24",
      "name": "jo"
    },
    {
      "_id": "60a7f9bdc0a1a7f8913b4a25",
      "name": "joooo"
    }
  ],
  "previewImageUrl": "https://previewImageUrl.asd",
  "streamUrl": "https://google.com",
  "date": "2021-05-21T18:19:41.671Z",
  "__v": 2
}

Request:

{
  "amount": 10,
  "outcome": 1,
  "minOutcomeTokens*": 400
}

*Optional

Successful Result:

{
  "_id": "60a7ff5364dee4f956660797",
  "marketQuestion": "Wer gewinnt Redbull",
  "hot": true,
  "outcomes": [
    {
      "index": 0,
      "name": "Jonas"
    },
    {
      "index": 0,
      "name": "Jörn"
    }
  ],
  "event": "60a7f9bdc0a1a7f8913b4a23",
  "creator": "60a35b31bbb1f700155f2066",
  "date": "2021-05-21T18:43:31.908Z",
  "__v": 0
}

Request:

{
  "amount": 10,
  "outcome": 1,
  "minReturnAmount*": 400
}

*Optional

Successful Result:

{
  "_id": "60a7ff5364dee4f956660797",
  "marketQuestion": "Wer gewinnt Redbull",
  "hot": true,
  "outcomes": [
    {
      "index": 0,
      "name": "Jonas"
    },
    {
      "index": 0,
      "name": "Jörn"
    }
  ],
  "event": "60a7f9bdc0a1a7f8913b4a23",
  "creator": "60a35b31bbb1f700155f2066",
  "date": "2021-05-21T18:43:31.908Z",
  "__v": 0
}

Request:

{
  "amount": 10
}

Der "amount" ist in WFAIR andgegeben

Successful Result:

[
  {
    "index": 0,
    "outcome": 9.10
  },
  {
    "index": 1,
    "outcome": 9.21
  }
]

Request:

{
  "amount": 10
}

Der "amount" ist in Outcome-Token (Potential Winnings) andgegeben

Successful Result:

[
  {
    "index": 0,
    "outcome": 9.10
  },
  {
    "index": 1,
    "outcome": 9.21
  }
]

Successful Result:

{
  "_id": "60a7ff5364dee4f956660797",
  "marketQuestion": "Wer gewinnt Redbull",
  "hot": true,
  "outcomes": [
    {
      "index": 0,
      "name": "Jonas"
    },
    {
      "index": 1,
      "name": "Jörn"
    }
  ],
  "event": "60a7f9bdc0a1a7f8913b4a23",
  "creator": "60a35b31bbb1f700155f2066",
  "date": "2021-05-21T18:43:31.908Z",
  "__v": 0
}

Successful Result:

{"status":"OK"}

Error Results:

{
  "errors": [
    {
      "msg": "Invalid value",
      "param": "userId",
      "location": "body"
    },
    {
      "msg": "Invalid value",
      "param": "code",
      "location": "body"
    }
  ]
}
{
  "error": "EMAIL_ALREADY_CONFIRMED",
  "message": "The email has already been confirmed!"
}
{
  "error": "INVALID_EMAIL_CODE",
  "message": "The email code is invalid!"
}

Successful Result:

{"status":"OK"}
{
    "streamUrl": "https://www.twitch.tv/chess"
}

Successful Result:

{
    "name": "Chess",
    "previewImageUrl": "https://static-cdn.jtvnw.net/jtv_user_pictures/6eb1c704-e4b4-4269-9e26-ec762668fb79-channel_offline_image-1920x1080.png",
    "streamUrl": "https://www.twitch.tv/chess",
    "tags": [
        {
            "name": "Esports"
        },
        {
            "name": "English"
        }
    ],
    "date": 1629448490358,
    "type": "streamed",
    "category": "Chess"
}

Successful Result:

[
  {
    "closed": false,
    "_id": "613efc97cbad81c04dbf7198",
    "title": "Do you like wallfair?",
    "questions": [
      {
        "index": 0,
        "name": "Yes",
        "imageUrl": "https://photostorage.mock/457y8hurbge8h79j2w8"
      },
      {
        "index": 1,
        "name": "No",
        "imageUrl": "https://photostorage.mock/457f87h7n4789fh3nw8"
      }
    ],
    "createdAt": "1631517847345",
    "closedAt": "1631517847345"
  }
]
{
  "answerId": 1,
  "questionId": "613efc97cbad81c04dbf7198",
}

Successful Result: Lottery Ticket ID

{
  "id":"613f0bc91612edc558d0e5c9"
}

Successful Result: Lottery Ticket ID

[{
  "_id": "613f0bc91612edc558d0e5c9",
  "marketQuestion": "Who will win?",
  "name": "winner template",
  "category": "counter-strike",
  "outcomes": [
    {
      "index": 0,
      "name": "Team A",
    },
    {
      "index": 1,
      "name": "Team B",
    }
  ]
}]

Auth Endpoints

{
  "username": "foo",
  "password": "bar",
}

Successful Result:

[
  {
    "userId": "613efc97cbad81c04dbf7198",
    "session": ""
  }
]
{
  "username": "foo",
  "password": "bar",
  "passwordConfirm": "bar",
}

Successful Result:

[
  {
    "userId": "613efc97cbad81c04dbf7198",
    "email": "[email protected]"
  }
]
{
  "email": "[email protected]"
}
{
  "email": "[email protected]"
}

backend's People

Contributors

gmussi avatar crepyx avatar bke-daniel avatar bastianplatz avatar samirhodzic avatar joerndyherrn avatar konstantinullrich avatar haris-bravo-klika avatar fernandotimm avatar jodergraf avatar wallfair avatar vandskii avatar pixelmord avatar rostikhr111 avatar kinglouie1994 avatar fx1dev avatar sebastiangajek avatar rudolfix avatar

Watchers

 avatar

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.