fixed issues
Browse files
App/Messages/MessagesRoute.py
CHANGED
@@ -13,14 +13,15 @@ from App.Users.Model import User
|
|
13 |
from App.Payments.Schema import PaymentMethod
|
14 |
from App.Payments.Model import Payment
|
15 |
from App.Plans.Model import Plan
|
|
|
16 |
|
17 |
message_router = APIRouter(tags=["Messages"], prefix="/messages")
|
18 |
|
19 |
|
20 |
@message_router.post("/sms_received", response_model=MessageResponse)
|
21 |
async def receive_message(message_data: MessageCreate):
|
22 |
-
message = Message.get_or_none(message_id=message_data.id)
|
23 |
-
|
24 |
try:
|
25 |
# Extract data from the message content using regex
|
26 |
text = message_data.payload.message
|
@@ -59,8 +60,10 @@ async def receive_message(message_data: MessageCreate):
|
|
59 |
sim_number=message_data.payload.simNumber,
|
60 |
parsed_data=parsed_data,
|
61 |
)
|
62 |
-
|
63 |
-
|
|
|
|
|
64 |
|
65 |
return data
|
66 |
except Exception as e:
|
|
|
13 |
from App.Payments.Schema import PaymentMethod
|
14 |
from App.Payments.Model import Payment
|
15 |
from App.Plans.Model import Plan
|
16 |
+
from tortoise.contrib.pydantic import pydantic_model_creator
|
17 |
|
18 |
message_router = APIRouter(tags=["Messages"], prefix="/messages")
|
19 |
|
20 |
|
21 |
@message_router.post("/sms_received", response_model=MessageResponse)
|
22 |
async def receive_message(message_data: MessageCreate):
|
23 |
+
message: Message = Message.get_or_none(message_id=message_data.id)
|
24 |
+
Message_Pydantic = pydantic_model_creator(Message)
|
25 |
try:
|
26 |
# Extract data from the message content using regex
|
27 |
text = message_data.payload.message
|
|
|
60 |
sim_number=message_data.payload.simNumber,
|
61 |
parsed_data=parsed_data,
|
62 |
)
|
63 |
+
if type(message) == Message:
|
64 |
+
data = Message_Pydantic.from_tortoise_orm(message)
|
65 |
+
else:
|
66 |
+
data = Message_Pydantic.from_queryset_single(message)
|
67 |
|
68 |
return data
|
69 |
except Exception as e:
|