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)
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)
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)
def delArticle(articleId): try: security.validateAdminRole(flask.request.headers.get("Authorization")) crud.delArticle(articleId) return "" except Exception as err: return errors.handleError(err)
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)
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)
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)
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)
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)
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)
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)