fix date issue for upload
Browse files
backend/app/db/database_mongodb.py
CHANGED
@@ -95,7 +95,7 @@ async def save_file(username: str, records: any, filename: str) -> bool:
|
|
95 |
upsert=True
|
96 |
)
|
97 |
|
98 |
-
|
99 |
opportunity = Opportunity(
|
100 |
opportunityId=content["Opportunity ID"],
|
101 |
opportunityName=content["Opportunity Name"],
|
@@ -107,7 +107,7 @@ async def save_file(username: str, records: any, filename: str) -> bool:
|
|
107 |
nextSteps=content["Next Steps"],
|
108 |
opportunityDescription=content["Opportunity Description"],
|
109 |
activity=content["Activity"],
|
110 |
-
closeDate=content
|
111 |
created_at=current_time,
|
112 |
updated_at=current_time,
|
113 |
username=username
|
@@ -244,6 +244,31 @@ async def create_indexes():
|
|
244 |
print(f"Error creating indexes: {e}")
|
245 |
return False
|
246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
# Optional: Add these to your requirements.txt
|
249 |
# motor==3.3.1
|
|
|
95 |
upsert=True
|
96 |
)
|
97 |
|
98 |
+
for content in records: #assume csv is the same format for all files
|
99 |
opportunity = Opportunity(
|
100 |
opportunityId=content["Opportunity ID"],
|
101 |
opportunityName=content["Opportunity Name"],
|
|
|
107 |
nextSteps=content["Next Steps"],
|
108 |
opportunityDescription=content["Opportunity Description"],
|
109 |
activity=content["Activity"],
|
110 |
+
closeDate=parse_date_string(content.get("Close Date")),
|
111 |
created_at=current_time,
|
112 |
updated_at=current_time,
|
113 |
username=username
|
|
|
244 |
print(f"Error creating indexes: {e}")
|
245 |
return False
|
246 |
|
247 |
+
def parse_date_string(value: str) -> datetime:
|
248 |
+
"""
|
249 |
+
Parse different date string formats into datetime object
|
250 |
+
"""
|
251 |
+
if not value:
|
252 |
+
return None
|
253 |
+
|
254 |
+
# List of possible date formats
|
255 |
+
date_formats = [
|
256 |
+
"%m/%d/%Y", # 11/30/2024
|
257 |
+
"%m/%d/%Y %H:%M:%S", # 11/30/2024 14:30:00
|
258 |
+
"%Y-%m-%d", # 2024-11-30
|
259 |
+
"%Y-%m-%dT%H:%M:%S", # 2024-11-30T14:30:00
|
260 |
+
"%Y-%m-%d %H:%M:%S", # 2024-11-30 14:30:00
|
261 |
+
"%Y-%m-%dT%H:%M:%S.%fZ", # 2024-11-30T14:30:00.000Z
|
262 |
+
"%Y-%m-%dT%H:%M:%S.%f", # 2024-11-30T14:30:00.000
|
263 |
+
]
|
264 |
+
|
265 |
+
for date_format in date_formats:
|
266 |
+
try:
|
267 |
+
return datetime.datetime.strptime(value, date_format)
|
268 |
+
except ValueError:
|
269 |
+
continue
|
270 |
+
|
271 |
+
raise ValueError(f"Date string '{value}' does not match any expected format")
|
272 |
|
273 |
# Optional: Add these to your requirements.txt
|
274 |
# motor==3.3.1
|
backend/app/db/models.py
CHANGED
@@ -24,7 +24,7 @@ class FileUpload(BaseModel):
|
|
24 |
class Opportunity(BaseModel):
|
25 |
username:str
|
26 |
activity: str
|
27 |
-
closeDate: datetime
|
28 |
customerContact: str
|
29 |
customerContactRole: str
|
30 |
customerName: str
|
|
|
24 |
class Opportunity(BaseModel):
|
25 |
username:str
|
26 |
activity: str
|
27 |
+
closeDate: Optional[datetime] = None
|
28 |
customerContact: str
|
29 |
customerContactRole: str
|
30 |
customerName: str
|
frontend/src/components/Opportunities.jsx
CHANGED
@@ -62,7 +62,7 @@ const Opportunities = () => {
|
|
62 |
<ChatApi />
|
63 |
<div className="flex flex-col h-[calc(89vh-7px)]">
|
64 |
{opportunities.map((opportunity, id) => (
|
65 |
-
<Button key={id} onClick={() => setSelectedOpportunity(opportunity)}>{opportunity.opportunityName}</Button>
|
66 |
))}
|
67 |
<div className="flex-1 overflow-y-auto p-4 space-y-4 h-[80vh]">
|
68 |
{Object.keys(selectedOpportunity || {}).map((key, index) => (
|
|
|
62 |
<ChatApi />
|
63 |
<div className="flex flex-col h-[calc(89vh-7px)]">
|
64 |
{opportunities.map((opportunity, id) => (
|
65 |
+
<Button key={id} onClick={() => setSelectedOpportunity(opportunity)} style={{'margin':'5px'}}>{opportunity.opportunityName}</Button>
|
66 |
))}
|
67 |
<div className="flex-1 overflow-y-auto p-4 space-y-4 h-[80vh]">
|
68 |
{Object.keys(selectedOpportunity || {}).map((key, index) => (
|