From cc92665424a621867218f7893db8f5b75ab2554f Mon Sep 17 00:00:00 2001 From: Jubayer Date: Tue, 26 Nov 2024 18:56:23 +0600 Subject: [PATCH] refactor: demo Signed-off-by: Jubayer --- apps/api/src/routes/admin.ts | 30 +++++++++++++++--------------- apps/api/wrangler.toml | 2 +- apps/web/wrangler.toml | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/api/src/routes/admin.ts b/apps/api/src/routes/admin.ts index f64779e..01e0a5e 100644 --- a/apps/api/src/routes/admin.ts +++ b/apps/api/src/routes/admin.ts @@ -34,11 +34,11 @@ const UpdateLinkSchema = NewLinkSchema.partial(); // New link route admin.post('/new', zValidator('json', NewLinkSchema), async (c) => { const { destination, shortLink } = c.req.valid('json'); - const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); - const db = drizzle(client, { schema }); + // const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); + // const db = drizzle(client, { schema }); const testLink = await findByShortLink(c, shortLink); if (testLink) throw new HTTPException(409); - await db.insert(schema.links).values({ dest: destination, slug: shortLink }).execute(); + // await db.insert(schema.links).values({ dest: destination, slug: shortLink }).execute(); return c.json({ status: 'Created Successfully' }, 201); }); @@ -168,8 +168,8 @@ admin.patch('/change-password', zValidator('json', changePasswordSchema), async if (!user) throw new HTTPException(404); const isMatch = await verifyPassword(user.hash, oldPassword); if (!isMatch) throw new HTTPException(401); - const newHash = await hashPassword(confirmNewPassword); - await db.update(schema.users).set({ hash: newHash }).where(eq(schema.users.id, 1)).execute(); + // const newHash = await hashPassword(confirmNewPassword); + // await db.update(schema.users).set({ hash: newHash }).where(eq(schema.users.id, 1)).execute(); return c.json({ status: 'Password Changed Successfully' }); }); @@ -190,29 +190,29 @@ admin.get('/link/:id', async (c) => { // Update a link route admin.patch('/link/:id', zValidator('json', UpdateLinkSchema), async (c) => { - const { destination, shortLink } = c.req.valid('json'); + // const { destination, shortLink } = c.req.valid('json'); const id = c.req.param('id'); - const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); - const db = drizzle(client, { schema }); - const kv = env(c).KV; + // const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); + // const db = drizzle(client, { schema }); + // const kv = env(c).KV; const targetLink = await findById(c, +id); if (!targetLink) throw new HTTPException(404); - await kv.delete(targetLink.slug); - await db.update(schema.links).set({ dest: destination, slug: shortLink }).where(eq(schema.links.id, +id)).execute(); + // await kv.delete(targetLink.slug); + // await db.update(schema.links).set({ dest: destination, slug: shortLink }).where(eq(schema.links.id, +id)).execute(); return c.json({ status: 'Updated Successfully' }); }); // Delete a link route admin.delete('/link/:id', async (c) => { const id = c.req.param('id'); - const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); - const db = drizzle(client, { schema }); + // const client = new Pool({ connectionString: c.env.NEON_DATABASE_URL }); + // const db = drizzle(client, { schema }); const kv = env(c).KV; const targetLink = await findById(c, +id); if (!targetLink) throw new HTTPException(404); await kv.delete(targetLink.slug); - await db.delete(schema.stats).where(eq(schema.stats.linkId, targetLink.slug)).execute(); - await db.delete(schema.links).where(eq(schema.links.id, +id)).execute(); + // await db.delete(schema.stats).where(eq(schema.stats.linkId, targetLink.slug)).execute(); + // await db.delete(schema.links).where(eq(schema.links.id, +id)).execute(); return c.json({ status: 'Deleted Successfully' }); }); diff --git a/apps/api/wrangler.toml b/apps/api/wrangler.toml index 4e85e3c..b6c892b 100644 --- a/apps/api/wrangler.toml +++ b/apps/api/wrangler.toml @@ -1,4 +1,4 @@ -name = "dash-api" +name = "dash-api-demo" main = "src/index.ts" compatibility_date = "2024-11-06" #route = { pattern = "{{CUSTOM_DOMAIN}}" , custom_domain = true } diff --git a/apps/web/wrangler.toml b/apps/web/wrangler.toml index f107f78..77d251b 100644 --- a/apps/web/wrangler.toml +++ b/apps/web/wrangler.toml @@ -1,4 +1,4 @@ -name = "dash-web" +name = "dash-web-demo" compatibility_date = "2024-11-06" compatibility_flags = ["nodejs_compat"] pages_build_output_dir = ".vercel/output/static" \ No newline at end of file