From 3b7b81b00560a671071f4cd22aecadd61c912806 Mon Sep 17 00:00:00 2001 From: carlpinto25 Date: Tue, 24 Mar 2026 23:11:08 +0530 Subject: [PATCH 1/3] /progress route (clerk disabled for testing) --- apps/api/src/controllers/progress.Controller.ts | 10 +++++++--- apps/api/src/routes/progress.route.ts | 3 +-- apps/api/src/services/progress.Service.ts | 15 +++++---------- apps/api/src/services/vote.Service.ts | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/apps/api/src/controllers/progress.Controller.ts b/apps/api/src/controllers/progress.Controller.ts index 8cedcf0..e8127d5 100644 --- a/apps/api/src/controllers/progress.Controller.ts +++ b/apps/api/src/controllers/progress.Controller.ts @@ -3,10 +3,14 @@ import type { AppEnv } from '../types' import { fetchProgress } from '../services/progress.Service' export const getProgress = async (c: Context) => { - const userId = c.get('userId') - + const userId = c.req.param('userId') + + if (!userId) { + return c.json({ success: false, message: 'userId is required' }, 400) + } + try { - const data = await fetchProgress(c.env, userId) + const data = await fetchProgress(c.env.DB, userId) return c.json(data) } catch (e: any) { console.error('Progress error:', e) diff --git a/apps/api/src/routes/progress.route.ts b/apps/api/src/routes/progress.route.ts index 63cd280..b5a7b8c 100644 --- a/apps/api/src/routes/progress.route.ts +++ b/apps/api/src/routes/progress.route.ts @@ -1,10 +1,9 @@ import { Hono } from 'hono' import type { AppEnv } from '../types' -import { requireAuth } from '../middleware/auth' import { getProgress } from '../controllers/progress.Controller' const progress = new Hono() -progress.get('/', requireAuth, getProgress) +progress.get('/:userId', getProgress) export default progress diff --git a/apps/api/src/services/progress.Service.ts b/apps/api/src/services/progress.Service.ts index 0c669bf..edfa051 100644 --- a/apps/api/src/services/progress.Service.ts +++ b/apps/api/src/services/progress.Service.ts @@ -1,20 +1,15 @@ import { getDb } from '../db/client' import { ratings, users } from '../db/schema' import { eq, count } from 'drizzle-orm' -import type { AppEnv } from '../types' -import { ensureUserExists } from './user.Service' -export const fetchProgress = async (env: AppEnv['Bindings'], userId: string) => { - const ormDb = getDb(env.DB) - - //ensure the user exists and grab profile data via Clerk - await ensureUserExists(env, userId) +export const fetchProgress = async (db: D1Database, userId: string) => { + const ormDb = getDb(db) - const userRecord = await ormDb.select({ isCompleted: users.isCompleted }).from(users).where(eq(users.id, userId)) - const isCompleted = userRecord[0]?.isCompleted || false + const userRecord = await ormDb.select({ completed: users.completed }).from(users).where(eq(users.id, userId)) + const isCompleted = userRecord[0]?.completed || false const countResult = await ormDb.select({ count: count() }).from(ratings).where(eq(ratings.userId, userId)) const progressCount = countResult[0]?.count || 0 - return { progress: progressCount, isCompleted } + return { userId, progress: progressCount, isCompleted } } diff --git a/apps/api/src/services/vote.Service.ts b/apps/api/src/services/vote.Service.ts index 3b1bc9b..6dafc50 100644 --- a/apps/api/src/services/vote.Service.ts +++ b/apps/api/src/services/vote.Service.ts @@ -38,7 +38,7 @@ export const submitVote = async ( if (progressCount >= 15) { await ormDb .update(users) - .set({ isCompleted: true }) + .set({ completed: true }) .where(eq(users.id, userId)) } From 08d9637e5dd679eda33b42329cbc355506246696 Mon Sep 17 00:00:00 2001 From: carlpinto25 Date: Wed, 25 Mar 2026 00:43:31 +0530 Subject: [PATCH 2/3] updated schema --- apps/api/src/db/schema.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index 1ebc098..6c3e584 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -12,9 +12,12 @@ export const stalls = sqliteTable('stalls', { id: integer('id').primaryKey({ autoIncrement: true }), name: text('name').notNull(), description: text('description'), - logo: text('logo'), // ✅ added + logo: text('logo'), + qrSlug: text('qr_slug').notNull(), // ✅ added createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()), -}); +}, (table) => ({ + qrSlugIdx: uniqueIndex('qr_slug_unique').on(table.qrSlug), // ✅ unique index +})); export const ratings = sqliteTable('ratings', { id: integer('id').primaryKey({ autoIncrement: true }), @@ -24,4 +27,4 @@ export const ratings = sqliteTable('ratings', { createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()), }, (table) => ({ unq: uniqueIndex('unique_vote').on(table.userId, table.stallId), -})); +})); \ No newline at end of file From 72541f84142e10822fe8b456749c87cd4926b3a8 Mon Sep 17 00:00:00 2001 From: carlpinto25 Date: Wed, 25 Mar 2026 00:47:49 +0530 Subject: [PATCH 3/3] updated schema1 --- apps/api/src/db/schema.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index 6c3e584..e9cb58a 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -13,11 +13,9 @@ export const stalls = sqliteTable('stalls', { name: text('name').notNull(), description: text('description'), logo: text('logo'), - qrSlug: text('qr_slug').notNull(), // ✅ added + qrSlug: text('qr_slug').unique().notNull(), // ✅ clean unique createdAt: integer('created_at', { mode: 'timestamp' }).$defaultFn(() => new Date()), -}, (table) => ({ - qrSlugIdx: uniqueIndex('qr_slug_unique').on(table.qrSlug), // ✅ unique index -})); +}); export const ratings = sqliteTable('ratings', { id: integer('id').primaryKey({ autoIncrement: true }),