-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from fac29/Added_Quiz
Added quiz
- Loading branch information
Showing
12 changed files
with
358 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Deploy to Vercel | |
|
||
on: | ||
push: | ||
branches: ['deployed'] | ||
branches: ['main'] | ||
|
||
jobs: | ||
deploy: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["denoland.vscode-deno"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"deno.enablePaths": [ | ||
"supabase/functions" | ||
], | ||
"deno.lint": true, | ||
"deno.unstable": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
id,answer_text,question_id,goal_id,created_at | ||
1,Emergency Savings,1,2,2024-07-31 11:02:32.428066+00 | ||
2,Managing Expenses,1,4,2024-07-31 11:03:14.550314+00 | ||
3,Investing for the Future,1,16,2024-07-31 11:04:54.834584+00 | ||
4,Giving Back,1,22,2024-07-31 11:05:36.106429+00 | ||
5,Student or graduate,2,1,2024-07-31 11:06:25.780938+00 | ||
6,Moved home,2,4,2024-07-31 11:07:00.694809+00 | ||
7,Changed jobs or role,2,14,2024-07-31 11:07:34.794972+00 | ||
8,Been on sabbatical,2,1,2024-07-31 11:07:56.631059+00 | ||
9,Taken maternity leave,2,16,2024-07-31 11:08:33.577078+00 | ||
10,None applicable,2,1,2024-07-31 11:08:54.462665+00 | ||
11,Taxes,3,5,2024-07-31 11:09:23.526468+00 | ||
12,Household bills,3,3,2024-07-31 11:09:57.679285+00 | ||
13,Pensions and employee benefits,3,14,2024-07-31 11:10:21.463339+00 | ||
14,Halal investing,3,16,2024-07-31 11:10:46.983309+00 | ||
15,Student loans,3,11,2024-07-31 11:11:24.339196+00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
id,question,created_at | ||
1,Which areas of your personal finances were you planning to focus on?,2024-07-31 10:57:12.586849+00 | ||
2,In the last two years which of these life events have you experienced?,2024-07-31 10:57:34.65335+00 | ||
3,Which topics below you would like more information on?,2024-07-31 10:57:53.108628+00 | ||
4,Is there any question you have and would like to ask?,2024-07-31 10:58:06.319872+00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
import express from 'express' | ||
import supabase from '../supabaseClient' | ||
|
||
const router = express.Router() | ||
|
||
// Questions Endpoints | ||
router.get('/questions', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase.from('questions').select('*') | ||
if (error) throw new Error(error.message) | ||
res.json(data) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Get question by ID | ||
router.get('/questions/:questionId', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase | ||
.from('questions') | ||
.select('*') | ||
.eq('id', req.params.questionId) | ||
.single() | ||
if (error) throw new Error(error.message) | ||
if (!data) return res.status(404).json({ error: 'Question not found' }) | ||
res.json(data) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Create questionac | ||
router.post('/questions', async (req, res) => { | ||
const { id,...questionData } = req.body | ||
|
||
try { | ||
// Start a transaction | ||
const { data: newQuestion, error: questionError } = await supabase | ||
.from('questions') | ||
.insert([questionData]) | ||
.select() | ||
.single() | ||
|
||
if (questionError) throw new Error(questionError.message) | ||
|
||
res.status(201).json(newQuestion) | ||
} catch (error: unknown) { | ||
res | ||
.status(500) | ||
.json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Edit question | ||
router.put('/questions/:questionId', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase | ||
.from('questions') | ||
.update(req.body) | ||
.eq('id', req.params.questionId) | ||
.select() | ||
if (error) throw new Error(error.message) | ||
if (data.length === 0) | ||
return res.status(404).json({ error: 'Question not found' }) | ||
res.json(data[0]) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Delete question | ||
router.delete('/questions/:questionId', async (req, res) => { | ||
try { | ||
const { error } = await supabase | ||
.from('questions') | ||
.delete() | ||
.eq('id', req.params.questionId) | ||
if (error) throw new Error(error.message) | ||
res.status(204).send() | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Answers Endpoints | ||
// Get all answers | ||
router.get('/answers', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase.from('answers').select('*') | ||
if (error) throw new Error(error.message) | ||
res.json(data) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Get answer by ID | ||
router.get('/answers/:answerId', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase | ||
.from('answers') | ||
.select('*') | ||
.eq('id', req.params.answerId) | ||
.single() | ||
if (error) throw new Error(error.message) | ||
if (!data) return res.status(404).json({ error: 'Answer not found' }) | ||
res.json(data) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Create Answer | ||
router.post('/answers', async (req, res) => { | ||
const { id, ...answerData } = req.body | ||
|
||
try { | ||
// Start a transaction | ||
const { data: newAnswer, error: answerError } = await supabase | ||
.from('answers') | ||
.insert([answerData]) | ||
.select() | ||
.single() | ||
|
||
if (answerError) throw new Error(answerError.message) | ||
|
||
res.status(201).json(newAnswer) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Edit answer | ||
router.put('/answers/:answerId', async (req, res) => { | ||
try { | ||
const { data, error } = await supabase | ||
.from('answers') | ||
.update(req.body) | ||
.eq('id', req.params.answerId) | ||
.select() | ||
if (error) throw new Error(error.message) | ||
if (data.length === 0) | ||
return res.status(404).json({ error: 'Answer not found' }) | ||
res.json(data[0]) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
//Delete Answer | ||
router.delete('/answers/:answerId', async (req, res) => { | ||
try { | ||
const { error } = await supabase | ||
.from('answers') | ||
.delete() | ||
.eq('id', req.params.answerId) | ||
if (error) throw new Error(error.message) | ||
res.status(204).send() | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Get all questions with their answers | ||
router.get('/questions-with-answers', async (req, res) => { | ||
try { | ||
const { data: questions, error: questionsError } = await supabase | ||
.from('questions') | ||
.select('*') | ||
|
||
if (questionsError) throw new Error(questionsError.message) | ||
|
||
if (!questions || questions.length === 0) { | ||
return res.status(404).json({ error: 'No questions found' }) | ||
} | ||
|
||
const questionsWithAnswers = await Promise.all(questions.map(async (question) => { | ||
const { data: answers, error: answersError } = await supabase | ||
.from('answers') | ||
.select('*') | ||
.eq('question_id', question.id) | ||
|
||
if (answersError) throw new Error(answersError.message) | ||
|
||
return { | ||
...question, | ||
answers: answers || [] | ||
} | ||
})) | ||
|
||
res.json(questionsWithAnswers) | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}) | ||
} | ||
}) | ||
|
||
// Get goals associated with a list of answers | ||
router.post('/goals-for-answers', async (req, res) => { | ||
const { answerIds } = req.body; | ||
|
||
if (!answerIds || !Array.isArray(answerIds) || answerIds.length === 0) { | ||
return res.status(400).json({ error: 'Invalid or missing answerIds in request body' }); | ||
} | ||
|
||
try { | ||
// First, get all answers with the given IDs | ||
const { data: answers, error: answersError } = await supabase | ||
.from('answers') | ||
.select('id, goal_id') | ||
.in('id', answerIds); | ||
|
||
if (answersError) throw new Error(answersError.message); | ||
|
||
// Extract unique goal IDs from the answers | ||
const goalIds = [...new Set(answers.map(answer => answer.goal_id))]; | ||
|
||
// Then, get all goals associated with these goal IDs | ||
const { data: goals, error: goalsError } = await supabase | ||
.from('goals') | ||
.select('*') | ||
.in('id', goalIds); | ||
|
||
if (goalsError) throw new Error(goalsError.message); | ||
|
||
res.json(goals); | ||
} catch (error: unknown) { | ||
res.status(500).json({ | ||
error: | ||
error instanceof Error ? error.message : 'An unknown error occurred', | ||
}); | ||
} | ||
}); | ||
|
||
export default router |
5 changes: 1 addition & 4 deletions
5
...grations/20240729142954_remote_schema.sql → ...ase/20240729142954_remote_schema.sql.nore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
create type "public"."recurrence_type" as enum ('day', 'week', 'month', 'year'); | ||
|
||
create type "public"."status" as enum ('not_done', 'in_progress', 'completed'); | ||
|
||
|
||
create type "public"."status" as enum ('not_done', 'in_progress', 'completed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
\i ../seed.sql |
Oops, something went wrong.