def post(self): data = request.get_json() product_color_validation = product.validate_Product_colour(data) if product_color_validation['isValid']: try: args = { 'ser': 1, 'product_color_code': data['product_color_code'], 'product_color': data['product_color'], 'colour_id': data['colour_id'] } if args['colour_id'] != 0: args['ser'] = 2 run_db_query( 'call spColourInsertUpdateDelete (' '_ser=>%(ser)s, ' '_code=>%(product_color_code)s, ' '_value=>%(product_color)s ,' '_cid=>%(colour_id)s) ', args, 'Admin enter product color DB', False) return {'message': 'Color and code Insert success'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Color and code Insert Error'}, 500 else: return {'message': 'Product field validation error'}, 500
def get(self): try: args = request.args.getlist('productId') if not args: result = run_db_query( 'select prodid ,prodsubcategoryid, prodcategory , prodname, proddesc, qty, trending, latest, imagepath from ' 'fnAdminProductSelect()', args, 'Prod info select select from DB', True, True) return { "message": "product info details select success", 'data': product_list_transformer(result) }, 200 else: result = run_db_query( 'select prodid , prodcategory , prodname, proddesc, inrprice, usdprice, colour, size, proddetailid,' 'qty, subcategoryid, sizeid, colourid, imagename, imagepath, proddatetill from fnsingleproductselect(' + args[0] + ')', args, 'Prod info select select from DB', True, True) return { "message": "product info details select success", 'singleData': single_product_transformer(result)[0] }, 200 except Exception as e: app.logger.debug(e) return {'message': 'product info details select error'}, 500
def post(self): data = request.get_json() return_validation = product.validate_returns(data) if return_validation['isValid']: try: args = { 'ser': 1, 'order_detail_id': data['order_detail_id'], 'return_status': data['return_status'] if 'return_status' in data else None, 'payment_status': data['payment_status'] if 'payment_status' in data else None, 'is_admin_return': data['is_admin_return'] } if args['is_admin_return']: args['ser'] = 2 run_db_query( 'call store.spReturnUpdate (' '_ser=>%(ser)s, ' '_orderdetailid=>%(order_detail_id)s, ' '_returnstatus=>%(return_status)s, ' '_paymentstatus=>%(payment_status)s )', args, 'return flags added or changed in DB', False) return {'message': 'return flags add or change success'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'return flags add or change Error'}, 500 else: return {'message': 'return field validation error'}, 500
def post(self): data = request.get_json() user_validation = register.validate_user(data) if user_validation['isValid']: try: email = data['email'] phone_number = data['mobile'] password = bcrypt.generate_password_hash( data['password']).decode('utf-8') args = { 'ser': 1, 'email': email, 'phone_number': phone_number, "password": password, "typecode": 'c' } result = run_db_query( 'select userid, userpassword from getuseridpassword (' '_email=>%(email)s)', args, 'get userid and password from DB', True) if result == 'error': raise Exception if not result: result = run_db_query( 'call spUserInsertUpdate (' '_ser=>%(ser)s, ' '_email=>%(email)s, ' '_mobileno=>%(phone_number)s, ' '_pwd=>%(password)s,' '_typecode=>%(typecode)s )', args, 'user register in DB', False) if result == 'error': raise Exception send_email(secrets['CUSTOMER_WELCOME_TEMPLATE'], { 'to_email': data['email'], 'variables': {} }) return { 'message': 'Registration success, please login' }, 200 else: return { 'message': 'User already exists, trying login' }, 500 except Exception as e: app.logger.debug(e) return {'message': 'user registration error'}, 500 else: return {'message': 'Error occurred, please try again'}, 500
def post(self): data = request.get_json() user_validation = pswdchng.validate_user(data) if user_validation['isValid']: try: identity = get_jwt_identity() args = {'user_id': identity['id']} result = run_db_query( 'select user_password from userPasswordSelect' '(%(user_id)s)', args, 'user password select from DB', True) if result == 'error': raise Exception if not result: return {"message": "user not found"}, 500 if bcrypt.check_password_hash(result['user_password'], data['currentPassword']): new_password = bcrypt.generate_password_hash( data['newPassword']).decode('utf-8') args1 = { 'ser': 3, 'password': new_password, 'email': identity['email'], 'mobile': '', 'typecode': 'c' } run_db_query( 'call spUserInsertUpdate (' '_ser=>%(ser)s, ' '_email=>%(email)s, ' '_mobileno=>%(mobile)s, ' '_pwd=>%(password)s, ' '_typecode=>%(typecode)s)', args1, 'user register in DB', False) if result == 'error': raise Exception return {'message': 'Password changed successfully.'}, 200 else: return {'message': 'Current password is incorrect'}, 500 except Exception as e: app.logger.debug(e) return {'message': 'Some error occurred, try again.'}, 500 else: return {'message': 'change password validation error'}, 500
def get(self): try: identity = get_jwt_identity() if identity['id']: args = {'user_id': request.args.getlist('userId')[0]} user_clause = '' if args['user_id'] != '0': user_clause = ' where user_id =' + str(args['user_id']) # print(args) result = run_db_query( 'select order_id, order_totalprice, order_paymentdate, ' ' payment_type_name, orderitems, order_number, userdetails, ' 'razorpay_payment_id, paypal_response, standard_shipping, coupon_value, user_discount ' ' from store.customer_order_view ' + user_clause, args, 'get customer orders', True, True) if result == 'error': raise Exception return { "message": "get orders for admin", 'data': admin_orders(result) }, 200 else: return {'message': 'Invalid Auth'}, 401 except Exception as e: app.logger.debug(e) return {'message': 'get productlist for customer error'}, 500
def post(self): data = request.get_json() product_subcategory_validation = product.validate_Product_subcategory( data) if product_subcategory_validation['isValid']: try: args = { 'ser': 1, 'product_category_id': data['product_category_id'], 'product_name': data['product_name'], 'product_desc': data['product_desc'], 'subcategory_id': data['subcategory_id'] } if args['subcategory_id'] != '0': args['ser'] = 2 result = run_db_query( 'call spProdSubCategInsertUpdateDelete (' '_ser=>%(ser)s, ' '_pcid=>%(product_category_id)s, ' '_name=>%(product_name)s, ' '_psid=>%(subcategory_id)s,' '_desc=>%(product_desc)s)', args, 'Admin enter SubCategory type in DB', False) if result == 'error': raise Exception return {'message': 'SubCategory type Insert success'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'SubCategory type insert error'}, 500 else: return {'message': 'SubCategory field validation error'}, 500
def post(self): try: data = request.get_json() args = { 'ser': 4, '_latest': data['latest'], '_trending': data['trending'], '_prod_id': data['productId'], '_subcategid': 0, '_name': '', '_desc': '' } product_update_result = run_db_query( 'call spproductinsertupdatedelete (' '_ser=>%(ser)s, ' '_subcategid=>%(_subcategid)s, ' '_name=>%(_name)s, ' '_latest=>%(_latest)s, ' '_trending=>%(_trending)s, ' '_prod_id=>%(_prod_id)s, ' '_desc=>%(_desc)s ) ', args, 'Update product highlight', False) if product_update_result == 'error': raise Exception return {'message': 'Highlight saved.'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Some error occurred, try again'}, 500
def post(self): try: data = request.get_json() product_related_validation = product.product_related_check(data) if product_related_validation['isValid']: args = { 'subcategory_id': data['subcategoryId'], 'product_id': data['productId'] } result = run_db_query( 'select prodid, prod_categ_name , prodname, prodinrprice ,' 'produsdprice ,productdetailid, prodimgname, prodimgpath' ' from fnRelatedProduct (' '_subcategid=>%(subcategory_id)s, ' '_productid=>%(product_id)s)', args, ' related products returned from DB', True, True) if result == 'error': raise Exception return { "message": "related products return success ", 'data': product_quick_list_transformer(result) }, 200 else: return {'message': 'related product validation error'}, 500 except Exception as e: app.logger.debug(e) return {'message': 'related products return error'}, 500
def post(self): data = request.get_json() discount_validation = userinfo.validate_user_discount(data) if discount_validation['isValid']: try: args = { 'ser': 5, '_email': data['email'], '_discount': data['discount'], '_mobileno': '', '_pwd': '', '_typecode': '' } result = run_db_query( 'call spUserInsertUpdate (' '_ser=>%(ser)s, ' '_email=>%(_email)s, ' '_mobileno=>%(_mobileno)s, ' '_pwd=>%(_pwd)s, ' '_typecode=>%(_typecode)s, ' '_discount=>%(_discount)s )', args, 'user enter details in DB', False) if result == 'error': raise Exception return {'message': 'Discount Update'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Some error occurred'}, 500 else: return {'message': 'User discount schema validation error'}, 500
def post(self): data = request.get_json() product_size_validation = product.validate_Product_size(data) if product_size_validation['isValid']: try: args = { 'ser': 1, 'product_size': data['product_size'], 'product_size_code': data['product_size_code'], 'product_category': data['product_category'], 'size_id': data['size_id'] } if args['size_id'] != '0': args['ser'] = 2 result = run_db_query( 'call spsizeInsertUpdateDelete (' '_ser=>%(ser)s, ' '_code=>%(product_size_code)s, ' '_pcid=>%(product_category)s, ' '_sid=>%(size_id)s, ' '_value=>%(product_size)s )', args, 'Admin enter product size in DB', False) if result == 'error': raise Exception return {'message': 'Size and code Insert success'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Size and code Insert Error'}, 500 else: return {'message': 'Product field validation error'}, 500
def get(self): try: identity = get_jwt_identity() if identity['id']: args = { 'offset': request.args.getlist('offset')[0], 'limit': request.args.getlist('limit')[0], 'user_id': identity['id'] } # print(args) result = run_db_query( 'select order_id, order_totalprice, order_paymentdate, ' ' payment_type_name, orderitems, order_number, standard_shipping,' ' coupon_value, user_discount' ' from store.order_view ' ' where user_id =' + str(args['user_id']) + ' ' ' LIMIT ' + args['limit'] + ' OFFSET ' + args['offset'], args, 'get customer orders', True, True) if result == 'error': raise Exception return { "message": "get productlist for customer", 'data': customer_orders(result) }, 200 else: return {'message': 'Invalid Auth'}, 401 except Exception as e: app.logger.debug(e) return {'message': 'get productlist for customer error'}, 500
def post(self): data = request.get_json() reset_pass = login.validate_reset_password(data) if reset_pass['isValid']: try: args = {'email': data['email']} result = run_db_query( 'select user_id, user_firstname from fncheckifuseremailexists' '(%(email)s)', args, 'user password select from DB', True) if result == 'error': raise Exception if not result: return {"message": "Email is invalid"}, 404 password_length = 8 possible_characters = "@!*&abcdefghijklmnopqrstuvwxyz1234567890" user_name = result['user_firstname'] random_character_list = [ random.choice(possible_characters) for i in range(password_length) ] random_password = "".join(random_character_list) new_password = bcrypt.generate_password_hash( random_password).decode('utf-8') args['new_password'] = new_password result = run_db_query( 'call spresetpassword (' '_email=>%(email)s, ' '_pwd=>%(new_password)s)', args, 'forget password reset', False) if result == 'error': raise Exception send_email( secrets['FORGET_PASSWORD_TEMPLATE'], { 'to_email': data['email'], "variables": { "NAME": user_name, "PASSWORD": random_password } }) return { 'message': 'Password reset steps sent to your email.' }, 200 except Exception as e: app.logger.debug(e) return {'message': 'Please try again.'}, 500
def post(self): data = request.get_json() identity = get_jwt_identity() # order_validation = order.validate_order(data) # if order_validation['isValid']: try: args = {'user_id': identity['id'], 'product_detail_id': data['product_detail_id'], 'order_quantity': data['order_quantity'], 'price_id': data['price_id'], 'orderdetail_id': data['orderdetail_id'], 'delete_flag': data['delete_flag'] } if args['orderdetail_id'] != "0" and not args['delete_flag']: result = run_db_query('call store.order_item_update (' '_qty=>%(order_quantity)s, ' '_odid=>%(orderdetail_id)s)', args, 'order details Update in DB', True) if not result[1]: return {'message': 'order update success', 'data': {}}, 200 else: return {'message': 'order update success', 'data': update_cart_transformer(result[1])}, 200 elif args['delete_flag']: result = run_db_query('call store.order_item_delete (' '_odid=>%(orderdetail_id)s)', args, 'order details Deleted in DB', False) return {'message': 'order delete success', 'message': result}, 200 else: result = run_db_query('select * from store.order_item_add(' '_uid=>%(user_id)s, ' '_pdid=>%(product_detail_id)s, ' '_prid=>%(price_id)s, ' '_qty=>%(order_quantity)s)' , args, 'order details updated in DB', True) return {'message': 'order insert,update,delete success', 'data': add_to_cart_transformer(result[1])}, 200 except Exception as e: app.logger.debug(e) return {'message': ' order insert,update,delete Error'}, 500
def get(self): identity = get_jwt_identity() if identity['id']: args = {'user_id': identity['id']} result = run_db_query('select js from store.fn_get_cart (_userid=>%(user_id)s)', args, 'get cart information', True) if result[0]: return {'message': 'Get customer cart success', 'data': get_cart_transformer(result[0])}, 200 else: return {'message': 'Get customer cart success', 'data': []}, 200 else: return {'message': "Please login"}, 500
def get(self): try: args = '' result = run_db_query( 'select cp_id,cp_code,cp_value ' 'from fnCouponSelect()', args, 'coupon info select from DB', True, True) return { "message": "color select success", 'data': product_coupon_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'color select error'}, 500
def get(self): try: args = '' result = run_db_query( 'select s_id,s_value,s_code,prod_category, prod_categoryname ' 'from fnSizeSelect()', args, 'user info select from DB', True, True) return { "message": "color select success", 'data': product_size_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'color select error'}, 500
def post(self): try: identity = get_jwt_identity() if identity['id']: data = request.get_json() return_validation = customer_returns(data) if return_validation['isValid']: args = { 'ser': 1, 'order_detail_id': data['orderDetailsId'], 'return_reason': data['returnReason'] } result = run_db_query( 'call store.spReturnUpdate (' '_ser=>%(ser)s, ' '_orderdetailid=>%(order_detail_id)s )', args, 'return flags added or changed in DB', False) if result == 'error': raise Exception # send customer email send_email( secrets['CUSTOMER_ORDER_RETURN_CANCEL_EMAIL_TEMPLATE'], { "to_email": identity['email'], "variables": { "NAME": data['userName'], "ORDERNUMBER": "#" + str(data['orderNumber']), "PRODUCTNAME": data['productName'] } }) #send admin email send_email( secrets['ADMIN_ORDER_RETURN_CANCEL_EMAIL_TEMPLATE'], { "to_email": secrets['ADMIN_EMAIL'], "variables": { "ORDERNUMBER": "#" + str(data['orderNumber']), "PRODUCTNAME": data['productName'], "REASON": data['returnReason'] } }) return {'message': 'Return process initialed'}, 200 else: return {'message': 'Payload incorrect'}, 500 else: return {'message': 'User Invalid, login again'}, 401 except Exception as e: app.logger.debug(e) return {'message': 'error while processing return'}, 500
def get(self): try: args = '' result = run_db_query( 'select ps_id ,cat_name, cat_id, ps_name, ps_desc ' 'from fnProdSubCategSelect()', args, 'Prod sub category select select from DB', True, True) return { "message": "product sub category details select success", 'data': product_subcategory_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'SubCategory details select error'}, 500
def get(self): try: result = run_db_query( 'select userid, fname, lname, mobno, dob, gender,emailid,' 'userdiscount, addrid, addrline1, addrline2,' ' addrline3, city, state, pincode ,country from alluserinformation' '()', {}, 'user info select from DB', True, True) if result == 'error': raise Exception data = admin_user_transformer(result) return {"message": "User select success", "data": data}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Some error occurred, retry'}, 500
def get(self): try: args = '' result = run_db_query( 'select col_id , col_code, col_value from fncolourSelect()', args, 'user info select from DB', True, True) if result == 'error': raise Exception return { 'message': 'color select success', 'data': product_colour_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'color select error'}, 500
def post(self): data = request.get_json() try: args = {'_order_detail_ids': data['orderDetailId']} result = run_db_query('select * from store.updatecartquantity (' '_order_detail_ids=>%(_order_detail_ids)s)', args, 'update cart quantities', True) if result == 'error': raise Exception if result['status']: return {'message': 'We updated your cart based on the product availability'}, 203 else: return {'message': 'Cart quantity is valid'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'Some error occurred, retry again'}, 500
def get(self): try: identity = get_jwt_identity() args = {'user_id': identity['id'], 'email': identity['email']} result = run_db_query( 'select userid, fname, lname, mobno, dob, gender,discount, addrid, addrline1, ' 'addrline2, addrline3, city, state, pincode ,country from PersonalInfoSelect' '(%(user_id)s)', args, 'user info select from DB', True) if not result: return {"message": "user not found"}, 500 else: data = login_transformer(result, args['email'], identity['usertype'] == 'a') return {"message": "User select success", "data": data}, 200 except Exception as e: app.logger.debug(e) return {'message': 'user select error'}, 500
def get(self): try: result = run_db_query( 'select orderdetailid, prod_category, prod_name, ' ' addr_state, qty, paymenttype, paymentmode, ' 'originaltotal, userdiscount, coupondiscount, orderreturned ' ' from store.fngetorderdatacsv() ', {}, 'get order data for csv', True, True) if result == 'error': raise Exception return { "message": "success get order data for csv", "data": order_data_csv_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'get order data for csv error'}, 500
def get(self): try: args = {} result = run_db_query( 'select shipr_id, shipr_name, shipr_link ' 'from store.fnshipperSelect()', args, 'shipper info select from DB', True, True) if result == 'error': raise Exception return { "message": "shipper info select success", 'data': shipment_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'shipper select error'}, 500
def get(self): try: data = request.args.getlist('type')[0] if data: args = {"type": int(data)} result = run_db_query( 'select prod_id, prod_categ_name , prod_name, prod_inr_price ,prod_usd_price ,' 'productdetailid, prod_img_name, prod_img_path ' ' from fnGetLatestTrendingProduct(' 'i=>%(type)s)', args, ' trending latest info select select from DB', True, True) return { "message": "trending latest product select success", 'data': product_trending_latest_list(result) }, 200 else: return {"message": "No tye defined"}, 500 except Exception as e: app.logger.debug(e) return {'message': 'trending latest product select error'}, 500
def get(self): try: args = '' result = run_db_query( 'select ps_id ,cat_name' ' from fnProdCategSelect()', args, 'Prod sub category select select from DB', True, True) if result == 'error': raise Exception identity = get_jwt_identity() return { "message": "product category details select success", 'data': product_category_transformer( result, identity['usertype'] == 'a' if identity else False) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'product category details select error'}, 500
def get(self): try: coupon_code = request.args.getlist('couponCode')[0] if coupon_code: args = {'coupon_code': coupon_code} result = run_db_query( 'select cp_code , cp_id , cp_value ' 'from fncheckcoupon(' '_couponcode=>%(coupon_code)s)', args, ' coupon returned from DB', True) if result == 'error': raise Exception return { "message": "coupon code return success ", 'data': coupon_format(result) }, 200 else: return {'message': 'Coupon Invalid'}, 200 except Exception as e: app.logger.debug(e) return {'message': 'coupon code did not matched error'}, 500
def post(self): data = request.get_json() user_login_validation = login.validate_user_login(data) if user_login_validation['isValid']: try: args = {'email': data['email']} result = run_db_query( 'select userid, userpassword, usertype from getuseridpassword (' '_email=>%(email)s)', args, 'get userid and password from DB', True) if result == 'error': raise Exception if not result: return {"message": "User does not exists"}, 500 password = data['password'].encode('utf-8') if bcrypt.check_password_hash(result['userpassword'], password): access_token = create_access_token( identity={ 'email': args['email'], 'id': result['userid'], 'usertype': result['usertype'] }, expires_delta=datetime.timedelta(hours=1)) return { "message": 'Login successful', "access_token": access_token }, 200 else: return {"message": "Invalid credentials"}, 500 except Exception as e: app.logger.debug(e) return {'message': 'user login error'}, 500 else: return {'message': 'login field validation error'}, 500
def get(self): try: args = '' result = run_db_query( 'select prod_subcateg_id,' 'prod_subacateg_name, ' 'prod_colour, ' 'colour_value, ' # 'size_id, ' 'prod_size ' # 'prod_count ' 'from vw_product_counts', args, 'product count view', True, True) return { "message": "product count success", 'data': product_count_transformer(result) }, 200 except Exception as e: app.logger.debug(e) return {'message': 'product count error'}, 500