diff --git a/src/routes/goals.ts b/src/routes/goals.ts index 7872157..2c62342 100644 --- a/src/routes/goals.ts +++ b/src/routes/goals.ts @@ -100,6 +100,39 @@ router.put('/user-goal/:userId/:goalId', async (req, res) => { } }); +// Focus a goal manually by the user +router.put('/user-goal/focus/:userId/:goalId', async (req, res) => { + try { + const { data: updatedUserGoal, error } = await supabase + .from('user_goals') + .update({ + status: 'focus', + focus_origin: 'user' + }) + .eq('user_id', req.params.userId) + .eq('goal_id', req.params.goalId) + .select(` + id, + user_id, + goal_id, + assigned_at, + due_date, + status, + completed_at, + focus_origin, + goals (*) + `) + .single(); + + if (error) throw new Error(error.message); + if (!updatedUserGoal) return res.status(404).json({ error: 'User goal not found' }); + + res.json(updatedUserGoal); + } catch (error: unknown) { + res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); + } +}); + // Delete goal and its user assignments router.delete('/:id', async (req, res) => { try { diff --git a/tests/goals.http b/tests/goals.http index 50b7915..f3ba2c8 100644 --- a/tests/goals.http +++ b/tests/goals.http @@ -147,7 +147,7 @@ Content-Type: application/json DELETE https://nisa-invest-tfb-be.vercel.app/goals/21 -### Set all the goals passed on the body to true. If the user_goal does not exist +### Set all the goals passed on the body to focused and focus_origin to quiz. If the user_goal does not exist # it will create it POST https://nisa-invest-tfb-be.vercel.app/goals/update-quiz-selected Content-Type: application/json