Skip to content

Commit

Permalink
Final Push
Browse files Browse the repository at this point in the history
  • Loading branch information
kbansal77 committed Oct 31, 2021
1 parent cc6d356 commit 698401d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 110 deletions.
14 changes: 0 additions & 14 deletions server/routes/landlords_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,13 @@
landlord_api_router = APIRouter()


# retrieve
# @landlord_api_router.get("/")
# async def get_landlords():
# try:
# landlords = landlords_serializer(collection_name.find())
# return {"status": "ok", "data": landlords}
# except Exception as e:
# print(e)
# raise HTTPException(status_code=400, detail=str(e))

# get landlord details


@landlord_api_router.get("/{Landlord_uid}")
async def get_landlord(Landlord_uid):
try:
uid = encrypt(Landlord_uid)
landlordDetails = {}
landlord = collection_name.find_one({"uid": uid})
landlordDetails["id"] = str(ObjectId(landlord["_id"]))
print(str(ObjectId(landlord["_id"])))
landlordDetails["address"] = landlord["address"]
landlordDetails["fcm"] = landlord["fcm"]
landlordDetails["uid"] = landlord["uid"]
Expand Down
76 changes: 0 additions & 76 deletions server/routes/requests_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

dir = os.path.dirname(__file__)
filename = os.path.join(dir, "serviceaccountkey.json")
print(filename)
cred = credentials.Certificate(filename)
firebase_admin.initialize_app(cred)

Expand All @@ -56,71 +55,6 @@ def sendPush(title, msg, registration_token, dataObject=None):
print("Successfully sent message:", response)


# @request_api_router.get("/")
# async def get_requests():
# try:
# request = requests_serializer(db["requests"].find())
# return {"status":"ok","data": request}
# except Exception as e:
# print(e)
# raise HTTPException(status_code=400, detail=str(e))


# @request_api_router.post("/")
# async def create_request(request: Request):
# try:
# uid = ""
# phone = ""
# tenant_uid = encrypt(request.tenant_uid)
# tenant_id =db["tenant"].find_one({uid: tenant_uid})
# if request.landlord_uid:
# if request.landlord_uid == request.tenant_uid:
# description = "Fraudulent Case - Tenant (id: " + str(ObjectId(
# tenant_id["_id"]))+" ) made falls attempt to Create Request, Tenant and landlord are same. "
# pushAudit("Danger", description)
# return {"status": "400", "data": "tenant and landlord cannot be same."}
# uid = encrypt(request.landlord_uid)
# land = db["landlord"].find_one({"uid": uid})
# if land:
# print("landlord exists")
# sendPush(
# "Tenant is requesting for address update.",
# "Do you agree and would like to give authoriy to update address?",
# [land['fcm']],
# )
# elif request.landlord_no:
# phone = request.landlord_no
# land = db["landlord"].find_one({"phone": phone})
# if decrypt(land["uid"]) == request.tenant_uid:
# return {"status": "400", "data": "tenant and landlord cannot be same."}
# if land:
# print("landlord exists")
# sendPush(
# "Tenant is requesting for address update.",
# "Do you agree and would like to give authoriy to update address?",
# [land['fcm']],
# )
# else:
# landlord = {
# "address": "",
# "phone": phone,
# "fcm": "",
# "uid": uid
# }
# db["landlord"].insert_one(landlord)

# request.landlord_address = dict(request.landlord_address)
# request.tenant_uid = encrypt(request.tenant_uid)
# request.landlord_uid = uid
# db["requests"].insert_one(dict(request))

# return {"status": "ok", "data": request}

# except Exception as e:
# print(e)
# raise HTTPException(status_code=400, detail=str(e))


@request_api_router.post("/")
async def create_request(request: Request):
try:
Expand All @@ -138,23 +72,19 @@ async def create_request(request: Request):
if request.landlord_uid:
uid = encrypt(request.landlord_uid)
land = db["landlord"].find_one({"uid": uid})
print(land)
if land:
if request.landlord_uid == request.tenant_uid:
description = "Fraudulent Case - Tenant (id: " + str(ObjectId(
tenant_id["_id"]))+" ) made falls attempt to Create Request, Tenant and landlord are same. "
pushAudit("Danger", description)
return {"status": "400", "data": "tenant and landlord cannot be same."}
print(land["fcm"])
print("1")
if land["fcm"] != "":
sendPush(
"Tenant is requesting for address update.",
"Do you agree and would like to give authoriy to update address?",
[land['fcm']],
)
else:
print("created new")
landlord = {
"address": "",
"phone": int(phone),
Expand All @@ -175,8 +105,6 @@ async def create_request(request: Request):
pushAudit("Danger", description)
return {"status": "400", "data": "tenant and landlord cannot be same."}
else :
print(land["fcm"])
print("2")
if land["fcm"] != "":
sendPush(
"Tenant is requesting for address update.",
Expand All @@ -197,7 +125,6 @@ async def create_request(request: Request):
}
db["landlord"].insert_one(landlord)
land = db["landlord"].find_one({"phone": int(phone)})
print(land)
description = "Landlord (id: "+str(ObjectId(land["_id"]))+") Created"
pushAudit("succesful", description)
else:
Expand Down Expand Up @@ -234,7 +161,6 @@ async def status_update(status: Status):
landlord_id = db["landlord"].find_one({
"phone":landlord_no
})
print(landlord_id)
if request_id is None:
description = "Fraudulent Case - Landlord (id: "+str(ObjectId(landlord_id["_id"]))+") make falls attempt to change status of Request (id: "+ status.id+ ")"
pushAudit("Danger", description)
Expand All @@ -246,7 +172,6 @@ async def status_update(status: Status):

if status.approval_status:
landlord = db["landlord"].find_one({"_id": landlord_id["_id"]})
print(landlord)
if landlord is None:
return {"status": "400", "data": "No landlord found"}

Expand Down Expand Up @@ -422,7 +347,6 @@ async def delete_request(Requestdelete: Requestdelete):
async def addressvalidation(landlordaddress: str = Body(...), updatedaddress : str = Body(...)):
try:
my_dist = gmaps.distance_matrix(landlordaddress,updatedaddress)['rows'][0]['elements'][0]
print(my_dist)
if (my_dist["distance"]["value"] > 100):
return False
else:
Expand Down
20 changes: 0 additions & 20 deletions server/routes/tenants_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ async def get_tenant(tenant_uid: str):
async def create_tenant(tenant: Tenant):
try:
tenantDetails = {}
print(tenant)
uid = encrypt(tenant.uid)
if(db["tenant"].find_one({"uid": uid})):
db["tenant"].update_one({"uid": uid}, {
Expand All @@ -73,7 +72,6 @@ async def create_tenant(tenant: Tenant):
tenant.uid = encrypt(tenant.uid)
db["tenant"].insert_one(dict(tenant))
tenants = db["tenant"].find_one({"phone": int(tenant.phone)})
print(tenants)
tenantDetails["id"] = str(ObjectId(tenants["_id"]))
tenantDetails["address"] = tenants["address"]
tenantDetails["fcm"] = tenants["fcm"]
Expand Down Expand Up @@ -102,9 +100,7 @@ async def update_tenant_address(UpdateAddress: UpdateAddress):
pushAudit("Danger", description)
return {"status": "400", "data": "No Address Update Permited"}
res = await addressvalidation(UpdateAddress.landlordaddress, UpdateAddress.updatedaddress)
print(res)
if res:
print("updated")
db["requests"].update_one({"_id": request_id["_id"]}, {
"$set": {
"status": 3,
Expand All @@ -129,23 +125,7 @@ async def update_tenant_address(UpdateAddress: UpdateAddress):
tenant_id["_id"]))+" ) updated address Request (id: "+str(ObjectId(request_id["_id"]))+" )"
pushAudit("succesful", description)
return {"status": "200", "data": UpdateAddress.address}
# if UpdateAddress.address.house and request_id["landlord_address"]["country"] == UpdateAddress.address.country and request_id["landlord_address"]["dist"] == UpdateAddress.address.dist and request_id["landlord_address"]["loc"] == UpdateAddress.address.loc and request_id["landlord_address"]["pc"] == UpdateAddress.address.pc and request_id["landlord_address"]["state"] == UpdateAddress.address.state and request_id["landlord_address"]["vtc"] == UpdateAddress.address.vtc and request_id["landlord_address"]["street"] == UpdateAddress.address.street:
# db["tenant"].update_one({"uid": uid}, {"$set": {
# "address": dict(UpdateAddress.address),
# }})
# updateStatus = db["requests"].update_one({"_id": request_id["_id"]}, {
# "$set": {
# "status": 3,
# "landlord_address": dict(UpdateAddress.address),
# "updated": ""
# }
# })
# description = "Tenant (id: "+str(ObjectId(
# tenant_id["_id"]))+" ) updated address Request (id: "+str(ObjectId(request_id["_id"]))+" )"
# pushAudit("succesful",description)
# return {"status": "200", "data": UpdateAddress.address}
else:
print("failed")
description = "Tenant (id: "+str(ObjectId(
tenant_id["_id"]))+" ) update address Request (id: "+str(ObjectId(request_id["_id"]))+" ) denied due to to many changes in the address"
pushAudit("Error", description)
Expand Down

0 comments on commit 698401d

Please sign in to comment.