def post(self): tenant = request.args.get("tenant") data = request.get_json() user_id = data['userId'] report_name = data['reportName'] report_body = data['reportBody'] report_model = ReportTemplateModel(tenant) report_model.insert({ "user_id": user_id, "report_date": datetime.now(), "report_name": report_name, "report_body": report_body }) return create_response( "Monthly Report Saved Successfully"), Status.HTTP_201_CREATED
def get(self): tenant = request.args.get("tenant") report_model = ReportTemplateModel(tenant) default_template = list( report_model.filter_by(report_type="default").exec({ "_id": 1, "user_id": 1, "report_date": { '$dateToString': { 'format': '%Y-%m-%dT%H:%M:%S%z', 'date': '$time', 'timezone': 'Africa/Kampala' }, }, "report_type": 1, "report_name": 1, "report_body": 1 })) report = default_template[0] if default_template else {} return create_response("default report successfully fetched", data={'report': report}), Status.HTTP_200_OK