From 4a96d962bfebbc4e2bf5d7959a2bbd40953f2fb9 Mon Sep 17 00:00:00 2001 From: Aditya Baravkar Date: Mon, 4 Sep 2023 14:48:39 -0700 Subject: [PATCH] Tenant dashboard APIs --- maintenance.py | 22 +++++++++++++++++----- myspace_api.py | 13 ++++++++----- properties.py | 13 ++++++++++++- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/maintenance.py b/maintenance.py index dffbd88..d19a576 100644 --- a/maintenance.py +++ b/maintenance.py @@ -9,9 +9,7 @@ import json from datetime import date, datetime, timedelta from dateutil.relativedelta import relativedelta -import calendar - - +from werkzeug.exceptions import BadRequest # MAINTENANCE BY STATUS @@ -108,7 +106,9 @@ def get(self, property_id): -- MAINTENANCE PROJECTS BY PROPERTY SELECT -- * property_uid, property_address, property_unit, property_city, property_state, property_zip, property_type, property_num_beds, property_num_baths, property_area - , maintenance_request_uid, maintenance_property_id, maintenance_request_status, maintenance_title, maintenance_desc, maintenance_images, maintenance_request_type, maintenance_request_created_by, maintenance_priority, maintenance_can_reschedule, maintenance_assigned_business, maintenance_assigned_worker, maintenance_scheduled_date, maintenance_scheduled_time, maintenance_frequency, maintenance_notes, maintenance_request_created_date, maintenance_request_closed_date, maintenance_request_adjustment_date + , maintenance_request_uid, maintenance_property_id, maintenance_request_status, maintenance_title, maintenance_desc, maintenance_images, maintenance_request_type, maintenance_request_created_by + , maintenance_priority, maintenance_can_reschedule, maintenance_assigned_business, maintenance_assigned_worker, maintenance_scheduled_date, maintenance_scheduled_time, maintenance_frequency + , maintenance_notes, maintenance_request_created_date, maintenance_request_closed_date, maintenance_request_adjustment_date, maintenance_callback_number, maintenance_estimated_cost FROM space.properties LEFT JOIN space.maintenanceRequests ON maintenance_property_id = property_uid WHERE property_uid = \'""" + property_id + """\'; @@ -187,7 +187,7 @@ def get(self, owner_id): SELECT -- * maintenance_request_uid, maintenance_property_id, maintenance_title, maintenance_desc, maintenance_images, maintenance_request_type, maintenance_request_created_by, user_type, user_name, user_phone, user_email , maintenance_priority, maintenance_can_reschedule, maintenance_assigned_business, maintenance_assigned_worker, maintenance_scheduled_date, maintenance_scheduled_time, maintenance_frequency, maintenance_notes, maintenance_request_status - , maintenance_request_created_date, maintenance_request_closed_date, maintenance_request_adjustment_date + , maintenance_request_created_date, maintenance_request_closed_date, maintenance_request_adjustment_date, maintenance_callback_number, maintenance_estimated_cost , maintenance_quote_uid, quote_maintenance_request_id, quote_business_id, quote_services_expenses, quote_earliest_availability, quote_event_type, quote_event_duration, quote_notes, quote_status, quote_created_date, quote_total_estimate, quote_maintenance_images, quote_adjustment_date , property_uid, property_address, property_unit, property_city, property_state, property_zip, property_type , o_details.* @@ -228,6 +228,8 @@ def post(self): , 'maintenance_request_created_date' , 'maintenance_request_closed_date' , 'maintenance_request_adjustment_date' + , 'maintenance_callback_number' + , 'maintenance_estimated_cost' ] newRequest = {} @@ -274,3 +276,13 @@ def post(self): response['images'] = newRequest['maintenance_images'] return response + + def put(self): + response = {} + payload = request.get_json() + if payload.get('maintenance_request_uid') is None: + raise BadRequest("Request failed, no UID in payload.") + key = {'maintenance_request_uid': payload.pop('maintenance_request_uid')} + with connect() as db: + response = db.update('maintenanceRequests', key, payload) + return response diff --git a/myspace_api.py b/myspace_api.py index ee41fbc..33406d1 100644 --- a/myspace_api.py +++ b/myspace_api.py @@ -335,11 +335,15 @@ def get(self, tenant_id): response = {} with connect() as db: property = db.execute(""" - SELECT p.property_uid, p.property_address, p.property_unit + SELECT SUM(pur_amount_due) AS balance, + CAST(MIN(STR_TO_DATE(pur_due_date, '%Y-%m-%d')) AS CHAR) as earliest_due_date, + p.property_uid, p.property_address, p.property_unit FROM space.properties p - INNER JOIN space.leases l ON l.lease_property_id = p.property_uid - INNER JOIN space.lease_tenant lt ON lt.lt_lease_id = l.lease_uid - WHERE lt.lt_tenant_id = \'""" + tenant_id + """\'; + LEFT JOIN space.leases l ON l.lease_property_id = p.property_uid + LEFT JOIN space.lease_tenant lt ON lt.lt_lease_id = l.lease_uid + LEFT JOIN space.purchases pur ON p.property_uid = pur.pur_property_id + WHERE pur.purchase_status = 'UNPAID' AND lt.lt_tenant_id = \'""" + tenant_id + """\' + GROUP BY property_uid; """) response["property"] = property maintenance = db.execute(""" @@ -417,7 +421,6 @@ def get(self, tenant_id): api.add_resource(ContactsBusinessContactsMaintenanceDetails, '/contactsBusinessContactsMaintenanceDetails/') - api.add_resource(Account, '/account') api.add_resource(TenantDashboard, '/tenantDashboard/') diff --git a/properties.py b/properties.py index cc16fc0..6994bdb 100644 --- a/properties.py +++ b/properties.py @@ -11,7 +11,7 @@ import json from datetime import date, datetime, timedelta from dateutil.relativedelta import relativedelta -import calendar +from werkzeug.exceptions import BadRequest # MAINTENANCE BY STATUS @@ -178,6 +178,17 @@ def post(self): response['images'] = newProperty['property_images'] return response + + + def put(self): + response = {} + payload = request.get_json() + if payload.get('property_uid') is None: + raise BadRequest("Request failed, no UID in payload.") + key = {'property_uid': payload.pop('property_uid')} + with connect() as db: + response = db.update('properties', key, payload) + return response def delete(self):