Skip to content

Commit

Permalink
Focus a goal manually by the user
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVOiceover committed Aug 7, 2024
1 parent 3b24a85 commit c804c67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/routes/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/goals.http
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c804c67

Please sign in to comment.