def get_movements(username): username_query = {"username": username} username_information = collection.find_one(username_query) account_list = username_information['account'] solved_list = [] for i in range(len(username_information['account'])): for j in range(len( username_information['account'][i]["movements"])): solved_list.append({ "id": account_list[i]["id"], "date": account_list[i]["movements"][j]["date"], "name": account_list[i]["movements"][j]["name"], "location": account_list[i]["movements"][j]["location"], "amount": account_list[i]["movements"][j]["amount"], "currency": account_list[i]["movements"][j]["currency"], "movementType": account_list[i]["movements"][j]["movementType"] }) # print(account_list) return solved_list
def add_card(self, account_number, card_number, cvv, expiration_date, account_type, brand, username): username_query = {"username": username} username_information = collection.find_one(username_query) account_list_len = len(username_information['account']) document_values = { "account_number": account_number, "card_number": card_number, "cvv": cvv, "expiration_date": expiration_date, "account_type": account_type, "brand": brand } if account_list_len == 0: new_values = self.set_new_values(0, 1, document_values) print("es : " + str(account_list_len)) collection.update_one(username_information, new_values) return "Inserted" else: new_id = account_list_len + 1 new_values = self.set_new_values(account_list_len, new_id, document_values) print("es : " + str(account_list_len)) collection.update_one(username_information, new_values) return "Inserted"
def modify_user(self, username, name, last_name, telephone, address, birthday, gender): username_query = {"username": username} print(username_query) username_exits = collection.find_one(username_query) print(username_exits) if username_exits is not None: document_values = { "name": name, "last_name": last_name, "telephone": telephone, "address": address, "birthday": birthday, "gender": gender } new_values = self.set_new_values(document_values) collection.update_one(username_exits, new_values) user_information = { "name": username_exits["name"], "last_name": username_exits["last_name"], "telephone": username_exits["telephone"], "address": username_exits["address"], "birthday": username_exits["birthday"], "gender": username_exits["gender"] } return user_information else: return False
def delete_card(self, username, id): username_query = {"username": username} username_information = collection.find_one(username_query) account_list = username_information['account'] if account_list is not None: account_query = \ { "$pull": { "account": {"id": id} } } collection.update(username_query, account_query) return "Deleted" else: return "False"
def get_user_information(username): username_query = {"username": username} username_exits = collection.find_one(username_query) print(username_exits) if username_exits is not None: user_information = { "username": username_exits["username"], "name": username_exits["name"], "last_name": username_exits["last_name"], "telephone": username_exits["telephone"], "address": username_exits["address"], "birthday": username_exits["birthday"], "gender": username_exits["gender"] } return user_information else: return False
def add_preference(self, category, amount, term, username): print(self.username) username_query = {"username": username} username_information = collection.find_one(username_query) preferences_list_len = len(username_information['preferences']) print(preferences_list_len) document_values = { "category": category, "amount": amount, "term": term } if preferences_list_len == 0: new_values = self.set_new_values(0, 1, document_values) collection.update_one(username_information, new_values) return "Inserted" else: new_id = preferences_list_len + 1 new_values = self.set_new_values(preferences_list_len, new_id, document_values) collection.update_one(username_information, new_values) return "Inserted"
def modify_preference(self, category, amount, term, username, id): username_query = {"username": username} username_information = collection.find_one(username_query) account_list_len = len(username_information['account']) document_values = { "category": category, "amount": amount, "term": term } if account_list_len is not None: print(self.username) username_values = {"username": username, "preferences.id": id} new_values = { "$set": { "preferences.$.amount": document_values["amount"], "preferences.$.category": document_values["category"], "preferences.$.term": document_values["term"] } } insert_user = collection.update_one(username_values, new_values) return "Modificado" else: return False
def modify_card(self, account_number, card_number, cvv, expiration_date, account_type, brand, username, id): username_query = {"username": username} username_information = collection.find_one(username_query) account_list_len = len(username_information['account']) document_values = { "account_number": account_number, "card_number": card_number, "cvv": cvv, "expiration_date": expiration_date, "account_type": account_type, "brand": brand } if account_list_len is not None: print(self.username) username_values = {"username": username, "account.id": id} new_values = { "$set": { "account.$.account_number": cisco_type7.hash(document_values["account_number"]), "account.$.account_type": cisco_type7.hash(document_values["account_type"]), "account.$.brand": cisco_type7.hash(document_values["brand"]), "account.$.card_number": cisco_type7.hash(document_values["card_number"]), "account.$.cvv": cisco_type7.hash(document_values["cvv"]), "account.$.expiration_date": cisco_type7.hash(document_values["expiration_date"]) } } insert_user = collection.update_one(username_values, new_values) return "Modificado" else: return "nada"
def get_cards(username): username_query = {"username": username} username_information = collection.find_one(username_query) account_list = username_information['account'] solved_list = [] for i in range(len(username_information['account'])): solved_list.append({ "id": account_list[i]["id"], "account_number": cisco_type7.decode(account_list[i]["account_number"]), "account_type": cisco_type7.decode(account_list[i]["account_type"]), "brand": cisco_type7.decode(account_list[i]["brand"]), "card_number": cisco_type7.decode(account_list[i]["card_number"]), "cvv": cisco_type7.decode(account_list[i]["cvv"]), "expiration_date": cisco_type7.decode(account_list[i]["expiration_date"]) }) # print(account_list) return solved_list
def find_user(username): username_query = {"username": username} username_exits = collection.find_one(username_query) return username_exits
def get_preferences(self, username): username_query = {"username": username} username_information = collection.find_one(username_query) preferences_list = username_information['preferences'] print(preferences_list) return preferences_list