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 | |
| parent | change embedding model (diff) | |
| download | supermemory-f12ba788a4af571f1b4a586ff1de0eea330e8a4f.tar.xz supermemory-f12ba788a4af571f1b4a586ff1de0eea330e8a4f.zip | |
fix: deleting memories
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/backend/src/routes/memories.ts | 48 | ||||
| -rw-r--r-- | apps/backend/wrangler.toml | 2 | ||||
| -rw-r--r-- | apps/web/wrangler.toml | 2 |
3 files changed, 28 insertions, 24 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 }); diff --git a/apps/backend/wrangler.toml b/apps/backend/wrangler.toml index 0aa36a1f..36832053 100644 --- a/apps/backend/wrangler.toml +++ b/apps/backend/wrangler.toml @@ -36,7 +36,7 @@ preview_id = "a1f048ee14644468ad63b817b5648a31" [[hyperdrive]] binding = "HYPERDRIVE" id = "3a377d1b9c084e698ee201f10dfa8131" -localConnectionString = "postgres://postgres:postgres@localhost:5432/supermemorydhravya?sslmode=require" +localConnectionString = "postgres://postgres:postgres@localhost:5432/supermemorylocal?sslmode=require" [[unsafe.bindings]] name = "EMAIL_LIMITER" diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index 401e9b33..1ad14d06 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -21,7 +21,7 @@ bucket_name = "supermemory-images" [[hyperdrive]] binding = "HYPERDRIVE" id = "3a377d1b9c084e698ee201f10dfa8131" -localConnectionString = "postgres://postgres:postgres@localhost:5432/supermemorydhravya?sslmode=require" +localConnectionString = "postgres://postgres:postgres@localhost:5432/supermemorylocal?sslmode=require" [placement] mode = "smart" |