diff options
| author | Dhravya Shah <[email protected]> | 2025-01-29 15:44:27 -0700 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2025-01-29 15:44:27 -0700 |
| commit | f12ba788a4af571f1b4a586ff1de0eea330e8a4f (patch) | |
| tree | 3b77d4f1b8cf6ea758c36392d5b5b686a116783d /apps/backend/src | |
| parent | change embedding model (diff) | |
| download | supermemory-f12ba788a4af571f1b4a586ff1de0eea330e8a4f.tar.xz supermemory-f12ba788a4af571f1b4a586ff1de0eea330e8a4f.zip | |
fix: deleting memories
Diffstat (limited to 'apps/backend/src')
| -rw-r--r-- | apps/backend/src/routes/memories.ts | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/apps/backend/src/routes/memories.ts b/apps/backend/src/routes/memories.ts index 5ab811eb..bc2894e6 100644 --- a/apps/backend/src/routes/memories.ts +++ b/apps/backend/src/routes/memories.ts @@ -8,8 +8,7 @@ import { spaceAccess, contentToSpace, } from "@supermemory/db/schema"; -import { and, database, desc, eq, sql } from "@supermemory/db"; - +import { and, database, desc, eq, or, sql } from "@supermemory/db"; const memories = new Hono<{ Variables: Variables; Bindings: Env }>() .get( @@ -148,26 +147,22 @@ const memories = new Hono<{ Variables: Variables; Bindings: Env }>() }); } ) - .get( - "/:id", - zValidator("param", z.object({ id: z.string() })), - async (c) => { - const { id } = c.req.valid("param"); - const user = c.get("user"); + .get("/:id", zValidator("param", z.object({ id: z.string() })), async (c) => { + const { id } = c.req.valid("param"); + const user = c.get("user"); - if (!user) { - return c.json({ error: "Unauthorized" }, 401); - } + if (!user) { + return c.json({ error: "Unauthorized" }, 401); + } - const memory = await database(c.env.HYPERDRIVE.connectionString) - .select() - .from(documents) - .where(and(eq(documents.uuid, id), eq(documents.userId, user.id))) - .limit(1); + const memory = await database(c.env.HYPERDRIVE.connectionString) + .select() + .from(documents) + .where(and(eq(documents.uuid, id), eq(documents.userId, user.id))) + .limit(1); - return c.json(memory[0]); - } - ) + return c.json(memory[0]); + }) .delete( "/:id", zValidator("param", z.object({ id: z.string() })), @@ -184,7 +179,12 @@ const memories = new Hono<{ Variables: Variables; Bindings: Env }>() const doc = await db .select() .from(documents) - .where(and(eq(documents.uuid, id), eq(documents.userId, user.id))) + .where( + and( + or(eq(documents.uuid, id), eq(documents.id, Number(id))), + eq(documents.userId, user.id) + ) + ) .limit(1); if (!doc[0]) { @@ -192,8 +192,12 @@ const memories = new Hono<{ Variables: Variables; Bindings: Env }>() } const [document, contentToSpacei] = await Promise.all([ - db.delete(documents).where(and(eq(documents.uuid, id), eq(documents.userId, user.id))), - db.delete(contentToSpace).where(eq(contentToSpace.contentId, doc[0].id)), + db + .delete(documents) + .where(and(eq(documents.uuid, id), eq(documents.userId, user.id))), + db + .delete(contentToSpace) + .where(eq(contentToSpace.contentId, doc[0].id)), ]); return c.json({ success: true }); |