コード例 #1
0
    def updateStock(articleId):
        try:
            security.validateAdminRole(flask.request.headers.get("Authorization"))

            params = json.body_to_dic(flask.request.data)

            params = restValidator.validateAddStockParams(params)

            base = "http://127.0.0.1:3002/v1/articles/"
            consumir = get(base+articleId).json()

            if consumir["_id"]:
                #result = crud.addStock(params)
                articleId = consumir["_id"]
                nombreProducto = consumir["name"]
                result = crud.updateStock(articleId,nombreProducto,params)
            
                return json.dic_to_json({
                    "articleId": articleId,
                    #"cantStock": params["cantStock"],
                    "resultado" : result
                }) 
            else:
                error = "el _id no pertenece a un articulo del catalogo"
                return error
        except Exception as err:
            return errors.handleError(err)
コード例 #2
0
    def addPrice():
        print("Petición para agregar precio")
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            token = flask.request.headers.get("Authorization")

            params = json.body_to_dic(flask.request.data)

            # print(params)

            responses = []

            for price in params:

                # print("price", price)
                pri = restValidator.validateAddPriceParams(price)
                # print("pri",pri)
                result = crud.addPrice(pri)
                # print("result: ",result)
                # resp = {}
                # # resp['fechaDesde'] = result['fechaDesde']
                # resp['price'] = result['price']
                # resp['article_id'] = result['article_id']
                responses.append(result.copy())

            print(responses)
            # return json.dic_to_json(result)
            return json.dic_to_json(responses)
        except Exception as err:
            return errors.handleError(err)
コード例 #3
0
    def addPrice(articleId):
        print("Petición para agregar precio")
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            token = flask.request.headers.get("Authorization")

            security.validateArticle(articleId, token)

            params = json.body_to_dic(flask.request.data)

            # print(params)

            responses = []

            # print("price", price)
            pri = restValidator.validateAddPriceParams(params)
            # print("pri",pri)
            result = crud.addPrice(pri)

            responses.append(result.copy())

            print(responses)
            # return json.dic_to_json(result)
            return json.dic_to_json(result)
        except Exception as err:
            return errors.handleError(err)
コード例 #4
0
ファイル: route.py プロジェクト: rolox05/ecommerce
 def delArticle(articleId):
     try:
         security.validateAdminRole(flask.request.headers.get("Authorization"))
         crud.delArticle(articleId)
         return ""
     except Exception as err:
         return errors.handleError(err)
コード例 #5
0
    def getFunds(user_id):
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            result = find.getFundsWallet(user_id)
            return json.dic_to_json({"user_id": user_id, "balance": result})
        except Exception as err:
            return errors.handleError(err)
コード例 #6
0
    def getHistory(user_id):
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            params = json.body_to_dic(flask.request.data)

            result = find.getHistoryWallet(params, user_id)

            return json.dic_to_json(result)
        except Exception as err:
            return errors.handleError(err)
コード例 #7
0
    def sendFunds(user_id):
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            params = json.body_to_dic(flask.request.data)

            result = crud.addSend(params, user_id)

            return json.dic_to_json(result)
        except Exception as err:
            return errors.handleError(err)
コード例 #8
0
ファイル: route.py プロジェクト: rolox05/ecommerce
    def updateArticle(articleId):
        try:
            security.validateAdminRole(flask.request.headers.get("Authorization"))

            params = json.body_to_dic(flask.request.data)

            params = restValidator.validateEditArticleParams(articleId, params)

            result = crud.updateArticle(articleId, params)

            return json.dic_to_json(result)
        except Exception as err:
            return errors.handleError(err)
コード例 #9
0
    def updateDiscount(discountCode):
        try:
            security.validateAdminRole(flask.request.headers.get("Authorization"))

            token = flask.request.headers.get("Authorization")


            # print("now "+ datetime.datetime.utcnow())

            print("articleID "+discountCode)

            params = json.body_to_dic(flask.request.data)

            params = restValidator.validateEditDiscountParams(discountCode, params)

            result = crud.updateDiscount(discountCode, params)

            return json.dic_to_json(result)
        except Exception as err:
            print("error")
            return errors.handleError(err)
コード例 #10
0
    def addDiscount(articleId):
        print("Petición para agregar descuento")
        try:
            security.validateAdminRole(flask.request.headers.get("Authorization"))

            token = flask.request.headers.get("Authorization")
            
            security.validateArticle(articleId, token)

            params = json.body_to_dic(flask.request.data)
            
            responses = []
            dis = restValidator.validateAddPriceParams(params)
            result = crud.addDiscount(dis)
            responses.append(result.copy())


            # return "Hola para el post con el token: "+token
            return json.dic_to_json(result)

        except Exception as err:
            return errors.handleError(err)
コード例 #11
0
    def updatePrice(articleId):
        try:
            security.validateAdminRole(
                flask.request.headers.get("Authorization"))

            print('entro')
            token = flask.request.headers.get("Authorization")

            security.validateArticle(articleId, token)

            # print("now "+ datetime.datetime.utcnow())

            print("articleID " + articleId)

            params = json.body_to_dic(flask.request.data)

            params = restValidator.validateEditPriceParams(articleId, params)

            result = crud.updatePrice(articleId, params)

            return json.dic_to_json(result)
        except Exception as err:
            print("error")
            return errors.handleError(err)