Skip to content

Commit baa71aa

Browse files
committed
refactor(server): streamline property data retrieval and response
1 parent ede06da commit baa71aa

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

server.ts

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -561,32 +561,11 @@ app.get("/api/properties/:id", async (c: Context) => {
561561
`,
562562
});
563563

564-
const propertyData = property.rows[0] as any;
565-
566-
if (query.regenerate_ai_description === "true") {
567-
if (propertyData.ai_generated_description) {
568-
// Reset the ai_generated_description to null if it exists
569-
propertyData.ai_generated_description = null;
570-
}
571-
572-
const aiGeneratedDescription = await openaiAssistant(JSON.stringify(propertyData));
573-
574-
try {
575-
// Verify the aiDescription is valid JSON by parsing it
576-
JSON.parse(aiGeneratedDescription.includes("```json") ? aiGeneratedDescription.replace("```json", "").replace("```", "") : aiGeneratedDescription);
577-
578-
propertyData.ai_generated_description = aiGeneratedDescription;
579-
580-
await client.queryObject({
581-
args: [propertyData.id, JSON.stringify(aiGeneratedDescription)],
582-
text: `UPDATE Property SET ai_generated_description = $2 WHERE id = $1`,
583-
});
584-
} catch (error) {
585-
console.error("Invalid AI description format:", error);
586-
}
564+
if (property.rowCount === 0) {
565+
return c.json({ data: null });
587566
}
588567

589-
return c.json({ data: propertyData });
568+
return c.json({ data: property.rows[0] });
590569
});
591570

592571
app.post("/", async (c: Context) => {

0 commit comments

Comments
 (0)