def update_bank(self, bnk): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if 'bank_id' not in bnk: return common.make_response_packet(5, 'Bank id is required', None) bank = Bankaccount.query.filter( Bankaccount.id == bnk['bank_id']).first() if (not bank): return common.make_response_packet(6, 'Bank_id is not valid', None) keys = bank.__table__.columns updated = False for k in keys: updated |= common.check_and_update(bank, bnk, k.name) if (updated): if (not bank.acount_no or not bank.acount_holder_name or not bank.bank_name): return common.make_response_packet(3, "data is not valid", None) db_session.commit() return common.make_response_packet( 0, "Bank Information updated successfully", bank.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', bank.toDict())
def update_order(self, ord): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if 'order_id' not in ord: return common.make_response_packet(5, 'order id is required', None) orde = Orders.query.filter(Orders.id == ord['order_id']).first() if (not orde): return common.make_response_packet(6, 'order_id is not valid', None) keys = orde.__table__.columns updated = False for k in keys: updated |= common.check_and_update(orde, ord, k.name) if (updated): if (not orde.transported_point): db_session.refresh(orde) return common.make_response_packet(3, "data is not valid", None) db_session.commit() return common.make_response_packet(0, "order updated successfully", orde.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', orde.toDict())
def update_shopkeeper(self,s): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if (not s['shopkeeper_id']): return common.make_response_packet(5,'shopkeeper id is required',None) shop = ShopKeepers.query.filter(ShopKeepers.id== s['shopkeeper_id']).first() if (not shop): return common.make_response_packet(6,'shopkeeper_id is not valid',None) keys = shop.__table__.columns updated =False for k in keys: updated |= common.check_and_update(shop,s,k.name) if(updated): if(not shop.user_name or not shop.owner_name or not shop.shop_name or not shop.owner_phone_no or not shop.password or not shop.address): return common.make_response_packet(6, "Data is not valid", None) is_user_exist = ShopKeepers.query.filter(and_(ShopKeepers.user_name == shop.user_name,ShopKeepers.id != shop.id)).first() != None if (is_user_exist): return common.make_response_packet(7, "User name already in use", None) #is_shop_name_exist = ShopKeepers.query.filter(and_(ShopKeepers.shop_name == shop.shop_name,ShopKeepers.id != shop.id)).first() != None #if (is_shop_name_exist): # return common.make_response_packet(7, "shop name already in use", None) db_session.commit() return common.make_response_packet(0, "Shopkeeper updated successfully", shop.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', shop.toDict())
def update_product(self, a): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if (not a['product_id']): return common.make_response_packet(14, "product id is required", None) prod = Products.query.filter(Products.id == a['product_id']).first() if (not prod): return common.make_response_packet(13, "Product Id not valid", None) keys = prod.__table__.columns updated = False for k in keys: updated |= common.check_and_update(prod, a, k.name) if updated: validated = self.validate_product(prod) if (validated != True): db_session.refresh(prod) return validated if ('image1' in a): prod.image1 = bytes(prod.image1, 'utf-8') if ('image2' in a): prod.image2 = bytes(prod.image2, 'utf-8') if ('image3' in a): prod.image3 = bytes(prod.image3, 'utf-8') db_session.commit() return common.make_response_packet(0, "product updated successfully", prod.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', prod.toDict())
def update_brand(self, br): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if 'id' not in br: return common.make_response_packet(5, 'brand id is required', None) if br.get('brand_name'): select_shop_keeper = Brands.query.filter( Brands.shopkeeper_id == br['shopkeeper_id']).all() if select_shop_keeper: for i in range(len(select_shop_keeper)): if br['brand_name'] == select_shop_keeper[i].brand_name: return common.make_response_packet( 7, "Brand Name already exists", None) brn = Brands.query.filter( Brands.id == br['id'] and Brands.shopkeeper_id == br['shopkeeper_id']).first() if (not brn): return common.make_response_packet(6, 'Brand_id is not valid', None) keys = brn.__table__.columns updated = False for k in keys: updated |= common.check_and_update(brn, br, k.name) if (updated): if (not common.is_shopkeeper()): return common.make_response_packet( 6, "You are not authorize to update brands", None) db_session.commit() return common.make_response_packet(0, "Brand successfully updated", brn.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', brn.toDict())
def update_customer(self,c): authentic = common.is_user_authenticated() if (not authentic): return common.make_response_packet(4, "User is not authenticated", None) if (not 'customer_id' in c): return common.make_response_packet(5, 'customer id is required', None) cus = Customers.query.filter(Customers.id == c['customer_id']).first() if (not cus): return common.make_response_packet(6,'customer_id is not valid',None) keys = cus.__table__.columns updated = False for k in keys: updated |= common.check_and_update(cus,c, k.name) if (updated): if (not cus.user_name or not cus.customer_name or not cus.image or not cus.cnic_no or not cus.password or not cus.customer_phone_no): return common.make_response_packet(6, "Data is not valid", None) is_user_exist = Customers.query.filter(and_(Customers.user_name == cus.user_name, Customers.id != cus.id)).first() != None if (is_user_exist): db_session.refresh(cus) return common.make_response_packet(7, "User name already in use", None) db_session.commit() return common.make_response_packet(0, "customer updated successfully", cus.toDict()) else: return common.make_response_packet(1, 'Nothing Updated', cus.toDict())