Giter VIP home page Giter VIP logo

everlife-token-sale-model's Introduction

everlife-token-sale-model

The common model against which token sale services work

Rationale

The Token Sale App uses MongoDB to store its state. The application is modularised into different parts with their own responsibilities. Since all parts use the database as their means of affecting and persisting the application state we have created this module the document schemas for all other modules in the application.

The model module exposes the Mongoose models directly. Several utility methods have been added to the models to reduce complexity of using the models. Exposing the raw models with added methods aims at striking a balance between freedom and convenience for the callers.

Overview

The diagram below shows the datamodel, represented by this module, in the center, with the webb service/app and other services using it.

Token Sale App Overview Diagram

Models

Lock

Can be used to prevent inadvertent concurrent execution of scripts against the database by registering a "lock" document in the database.

User

Model represeting the "User", purchases and the crediting of these purchases against the Payment model. The User model uses an array of purchases which in turn uses an array of credited payments to keep track of the overall state. A status flag is used to keep track of the state for each purchase (AWAITING_PAYMENT -> PAYMENT_CREDITED -> ISSUING_PENDING -> ISSUED).

user = {
    name,
    email,
    ...
    purchases: [
        {
            status,
            ...
            creditet_payments: [
                paymentId.
                ever
                ever_bonus
            ]
        }
    
    ]
}

Payment

Registry of received payments.

Typical Usage in a service module

const model = require('everlife-token-sale-model');
const { Lock, User, Payment } = model;

const dbUrl = 'mongodb://localhost';
const serviceName = 'myTokenSaleService'

model.connectDb(dbUrl)
    .then(() => Lock.acquireLock(serviceName))
    .then(() => performWorkReturnPromise())
    .finally(() => Lock.releaseLock(serviceName))
    .finally(() => model.closeDb())
    .catch(err => {
        log('Unexpected error:', err);
        process.exit(-1);
    });

Here the method performWorkReturnPromise() uses the model and its methods to interact with the database. It must return a Promise which is resolved when processing is completed.

everlife-token-sale-model's People

Contributors

mindshade avatar michielmulders avatar theproductiveprogrammer avatar shahul786 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.