Example #1
0
class User(db.Model):
    __tablename__ = "user_v2"
    id = db.Column(db.String(), primary_key=True)
    username = db.Column(db.String())
    password = db.Column(db.String())
    role = db.Column(db.String())

    __table_args__ = (
        UniqueConstraint('username', name='unique_username'),
    )

    orders = db.relationship(
        'Order',
        backref='user'
    )

    def __init__(self, **kwargs):
        super(User, self).__init__(**kwargs)
        self.password = pwd_context.hash(kwargs.get('password'))

    def update_password(self, password):
        self.password = pwd_context.hash(password)

    @staticmethod
    def get(user_id):
        return User.query.filter_by(id=user_id).first()

    @staticmethod
    def find_user_by_username(username):
        return User.query.filter(User.username == username).first()
Example #2
0
class Product(db.Model):
    id = db.Column(db.String(), primary_key=True)
    name = db.Column(db.String())
    price = db.Column(db.Float(precision=2))
    merchant = db.Column(db.String(length=255))
    expiry = db.Column(db.Integer())

    inventory = db.relationship(
        'Inventory',
        uselist=False,
        back_populates='product'
    )

    order_details = db.relationship(
        'OrderDetail',
        backref='product'
    )

    stock_ins = db.relationship(
        'StockIn',
        backref='product'
    )

    def __init__(self, **kwargs):
        super(Product, self).__init__(**kwargs)
class OrderDetail(db.Model):
    id = db.Column(db.String(), primary_key=True)
    order_id = db.Column(db.String(), ForeignKey('order.id', ondelete='CASCADE'))
    product_id = db.Column(db.String(), ForeignKey('product.id', ondelete='CASCADE'))
    quantity = db.Column(db.Integer())

    def __init__(self, **kwargs):
        super(OrderDetail, self).__init__(**kwargs)
Example #4
0
class StockIn(db.Model):
    id = db.Column(db.String(), primary_key=True)
    product_id = db.Column(db.String(),
                           ForeignKey('product.id', ondelete='CASCADE'))
    quantity = db.Column(db.Integer())
    created_at = db.Column(db.Integer())

    def __init__(self, **kwargs):
        super(StockIn, self).__init__(**kwargs)
        self.created_at = int(time.time())
Example #5
0
class ResetToken(db.Model):
    user_id = db.Column(db.String(),
                        ForeignKey('user_v2.id'),
                        primary_key=True)
    token_str = db.Column(db.String())
    expiration_date = db.Column(db.String())

    def __init__(self, user_id, token_str):
        self.user_id = user_id
        self.token_str = token_str
        expiration_date = datetime.datetime.utcnow() + datetime.timedelta(
            minutes=EXPIRATION_MINUTES)
        self.expiration_date = expiration_date.isoformat()
Example #6
0
class Inventory(db.Model):
    id = db.Column(db.String(), primary_key=True)
    product_id = db.Column(db.String(),
                           ForeignKey('product.id', ondelete='CASCADE'))
    stock = db.Column(db.Integer())

    product = db.relationship('Product', back_populates='inventory')

    __table_args__ = (UniqueConstraint('product_id',
                                       name='unique_product_id'), )

    def __init__(self, **kwargs):
        super(Inventory, self).__init__(**kwargs)