From 6a923b3500542c67addceca8f88714624c6f18bd Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 7 Aug 2024 09:29:26 +0100 Subject: [PATCH] recovery branch --- .github/workflows/deployVercel.yml | 56 ++-- API_endpoints.md | 478 ++++++++++++++--------------- README.md | 82 ++--- src/config/config.ts | 60 ++-- src/routes/users.ts | 188 ++++++------ src/supabaseClient.ts | 26 +- supabase/seed.sql | 256 +++++++-------- tests/users.http | 60 ++-- tsconfig.json | 22 +- 9 files changed, 614 insertions(+), 614 deletions(-) diff --git a/.github/workflows/deployVercel.yml b/.github/workflows/deployVercel.yml index e7d018d..1487188 100644 --- a/.github/workflows/deployVercel.yml +++ b/.github/workflows/deployVercel.yml @@ -1,28 +1,28 @@ -name: Deploy to Vercel - -on: - push: - branches: ['main'] - -jobs: - deploy: - environment: 'Production' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js - uses: actions/setup-node@v3 - with: - node-version: '20' # or whatever version you're using. - - - name: Install dependencies - run: npm ci - - - name: Deploy to Vercel - run: npx vercel --prod --token ${{ secrets.VERCEL_TOKEN }} - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} +name: Deploy to Vercel + +on: + push: + branches: ['main'] + +jobs: + deploy: + environment: 'Production' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' # or whatever version you're using. + + - name: Install dependencies + run: npm ci + + - name: Deploy to Vercel + run: npx vercel --prod --token ${{ secrets.VERCEL_TOKEN }} + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} diff --git a/API_endpoints.md b/API_endpoints.md index 4d94b97..7662fee 100644 --- a/API_endpoints.md +++ b/API_endpoints.md @@ -1,240 +1,240 @@ -# API Endpoints Documentation - -## Contact Nisa - -### Get all contacts -GET https://nisa-invest-tfb-be.vercel.app/contactnisa/all - -### Create contact request -POST https://nisa-invest-tfb-be.vercel.app/contactnisa -Content-Type: application/json - -{ - "email": "john@example.com", - "first_name": "John", - "last_name": "Doe", - "social_media": "@johndoe", - "text_field": "Contact request" -} - -## Goals - -### Get all goals for a user -GET https://nisa-invest-tfb-be.vercel.app/goals/user/2 - -### Get goal by ID -GET https://nisa-invest-tfb-be.vercel.app/goals/4 - -### Create goal -POST https://nisa-invest-tfb-be.vercel.app/goals -Content-Type: application/json - -{ - "user_id": 1, - "title": "New Goal", - "description": "Description", - "status": "not_done", - "due_date": "2024-12-31T23:59:59Z" -} - -### Update goal -PUT https://nisa-invest-tfb-be.vercel.app/goals/1 -Content-Type: application/json - -{ - "title": "Updated Goal Title", - "description": "Updated description", - "is_recurrent": true, - "recurrence_type": "week", - "recurrence_value": 1, - "category": "fitness" -} - -### Update user-specific goal -PUT https://nisa-invest-tfb-be.vercel.app/goals/user-goal/2/1 -Content-Type: application/json - -{ - "status": "not_done", - "due_date": "2023-12-31T23:59:59Z" -} - -### Delete goal -DELETE https://nisa-invest-tfb-be.vercel.app/goals/21 - -### Set goals as quiz selected -POST https://nisa-invest-tfb-be.vercel.app/goals/update-quiz-selected -Content-Type: application/json - -{ - "userId": 5, - "goalIds": [1, 2, 3] -} - -### Get categorized user goals -GET https://nisa-invest-tfb-be.vercel.app/goals/user-quiz-goals/1 - -## Quiz - -### Get all questions -GET https://nisa-invest-tfb-be.vercel.app/quiz/questions - -### Get questions with answers -GET https://nisa-invest-tfb-be.vercel.app/quiz/questions-with-answers - -### Get goals for answers -POST https://nisa-invest-tfb-be.vercel.app/quiz/goals-for-answers -Content-Type: application/json - -{ - "answerIds": [1, 2, 3] -} - -### Get question by ID -GET https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 - -### Create question -POST https://nisa-invest-tfb-be.vercel.app/quiz/questions -Content-Type: application/json - -{ - "question": "What is your financial goal?" -} - -### Edit question -PUT https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 -Content-Type: application/json - -{ - "question": "What is your main financial goal for this year?" -} - -### Delete question -DELETE https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 - -### Get all answers -GET https://nisa-invest-tfb-be.vercel.app/quiz/answers - -### Get answer by ID -GET https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 - -### Create answer -POST https://nisa-invest-tfb-be.vercel.app/quiz/answers -Content-Type: application/json - -{ - "answer_text": "Save for retirement", - "question_id": 1, - "goal_id": 1 -} - -### Edit answer -PUT https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 -Content-Type: application/json - -{ - "answer_text": "Save for a house down payment", - "question_id": 1, - "goal_id": 2 -} - -### Delete answer -DELETE https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 - -## Quotes - -### Get all quotes -GET https://nisa-invest-tfb-be.vercel.app/quotes - -### Get quote by ID -GET https://nisa-invest-tfb-be.vercel.app/quotes/10 - -### Create quote -POST https://nisa-invest-tfb-be.vercel.app/quotes -Content-Type: application/json - -{ - "text": "Invest in yourself.", - "author": "Warren Buffett", - "valid_from": "2023-01-01", - "valid_to": "2023-12-31" -} - -### Update quote -PUT https://nisa-invest-tfb-be.vercel.app/quotes/1 -Content-Type: application/json - -{ - "text": "The best investment you can make is in yourself.", - "author": "Warren Buffett" -} - -### Delete quote -DELETE https://nisa-invest-tfb-be.vercel.app/quotes/1 - -### Get random quotes -GET https://nisa-invest-tfb-be.vercel.app/quotes/random?date=2024-04-1&count=3 - -## Reports - -### Get all reports -GET https://nisa-invest-tfb-be.vercel.app/reports/all - -### Get reports for a user -GET https://nisa-invest-tfb-be.vercel.app/reports/user/1 - -### Create report -POST https://nisa-invest-tfb-be.vercel.app/reports -Content-Type: application/json - -{ - "user_id": 1, - "title": "Monthly Financial Report", - "text": "Details of monthly finances...", - "priority": "medium" -} - -### Update report -PUT https://nisa-invest-tfb-be.vercel.app/reports/1 -Content-Type: application/json - -{ - "title": "Updated Monthly Financial Report", - "text": "Updated details of monthly finances...", - "priority": "high" -} - -### Delete report -DELETE https://nisa-invest-tfb-be.vercel.app/reports/1 - -## Users - -### Get all users -GET https://nisa-invest-tfb-be.vercel.app/users/all - -### Get user by email -GET https://nisa-invest-tfb-be.vercel.app/users/email/emma.johnson@email.com - -### Create user -POST https://nisa-invest-tfb-be.vercel.app/users -Content-Type: application/json - -{ - "email": "user@example.com", - "first_name": "John", - "last_name": "Doe", - "password": "securepassword123" -} - -### Update user -PUT https://nisa-invest-tfb-be.vercel.app/users/1 -Content-Type: application/json - -{ - "first_name": "Jane", - "last_name": "Smith", - "email": "jane.smith@example.com" -} - -### Delete user +# API Endpoints Documentation + +## Contact Nisa + +### Get all contacts +GET https://nisa-invest-tfb-be.vercel.app/contactnisa/all + +### Create contact request +POST https://nisa-invest-tfb-be.vercel.app/contactnisa +Content-Type: application/json + +{ + "email": "john@example.com", + "first_name": "John", + "last_name": "Doe", + "social_media": "@johndoe", + "text_field": "Contact request" +} + +## Goals + +### Get all goals for a user +GET https://nisa-invest-tfb-be.vercel.app/goals/user/2 + +### Get goal by ID +GET https://nisa-invest-tfb-be.vercel.app/goals/4 + +### Create goal +POST https://nisa-invest-tfb-be.vercel.app/goals +Content-Type: application/json + +{ + "user_id": 1, + "title": "New Goal", + "description": "Description", + "status": "not_done", + "due_date": "2024-12-31T23:59:59Z" +} + +### Update goal +PUT https://nisa-invest-tfb-be.vercel.app/goals/1 +Content-Type: application/json + +{ + "title": "Updated Goal Title", + "description": "Updated description", + "is_recurrent": true, + "recurrence_type": "week", + "recurrence_value": 1, + "category": "fitness" +} + +### Update user-specific goal +PUT https://nisa-invest-tfb-be.vercel.app/goals/user-goal/2/1 +Content-Type: application/json + +{ + "status": "not_done", + "due_date": "2023-12-31T23:59:59Z" +} + +### Delete goal +DELETE https://nisa-invest-tfb-be.vercel.app/goals/21 + +### Set goals as quiz selected +POST https://nisa-invest-tfb-be.vercel.app/goals/update-quiz-selected +Content-Type: application/json + +{ + "userId": 5, + "goalIds": [1, 2, 3] +} + +### Get categorized user goals +GET https://nisa-invest-tfb-be.vercel.app/goals/user-quiz-goals/1 + +## Quiz + +### Get all questions +GET https://nisa-invest-tfb-be.vercel.app/quiz/questions + +### Get questions with answers +GET https://nisa-invest-tfb-be.vercel.app/quiz/questions-with-answers + +### Get goals for answers +POST https://nisa-invest-tfb-be.vercel.app/quiz/goals-for-answers +Content-Type: application/json + +{ + "answerIds": [1, 2, 3] +} + +### Get question by ID +GET https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 + +### Create question +POST https://nisa-invest-tfb-be.vercel.app/quiz/questions +Content-Type: application/json + +{ + "question": "What is your financial goal?" +} + +### Edit question +PUT https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 +Content-Type: application/json + +{ + "question": "What is your main financial goal for this year?" +} + +### Delete question +DELETE https://nisa-invest-tfb-be.vercel.app/quiz/questions/1 + +### Get all answers +GET https://nisa-invest-tfb-be.vercel.app/quiz/answers + +### Get answer by ID +GET https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 + +### Create answer +POST https://nisa-invest-tfb-be.vercel.app/quiz/answers +Content-Type: application/json + +{ + "answer_text": "Save for retirement", + "question_id": 1, + "goal_id": 1 +} + +### Edit answer +PUT https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 +Content-Type: application/json + +{ + "answer_text": "Save for a house down payment", + "question_id": 1, + "goal_id": 2 +} + +### Delete answer +DELETE https://nisa-invest-tfb-be.vercel.app/quiz/answers/1 + +## Quotes + +### Get all quotes +GET https://nisa-invest-tfb-be.vercel.app/quotes + +### Get quote by ID +GET https://nisa-invest-tfb-be.vercel.app/quotes/10 + +### Create quote +POST https://nisa-invest-tfb-be.vercel.app/quotes +Content-Type: application/json + +{ + "text": "Invest in yourself.", + "author": "Warren Buffett", + "valid_from": "2023-01-01", + "valid_to": "2023-12-31" +} + +### Update quote +PUT https://nisa-invest-tfb-be.vercel.app/quotes/1 +Content-Type: application/json + +{ + "text": "The best investment you can make is in yourself.", + "author": "Warren Buffett" +} + +### Delete quote +DELETE https://nisa-invest-tfb-be.vercel.app/quotes/1 + +### Get random quotes +GET https://nisa-invest-tfb-be.vercel.app/quotes/random?date=2024-04-1&count=3 + +## Reports + +### Get all reports +GET https://nisa-invest-tfb-be.vercel.app/reports/all + +### Get reports for a user +GET https://nisa-invest-tfb-be.vercel.app/reports/user/1 + +### Create report +POST https://nisa-invest-tfb-be.vercel.app/reports +Content-Type: application/json + +{ + "user_id": 1, + "title": "Monthly Financial Report", + "text": "Details of monthly finances...", + "priority": "medium" +} + +### Update report +PUT https://nisa-invest-tfb-be.vercel.app/reports/1 +Content-Type: application/json + +{ + "title": "Updated Monthly Financial Report", + "text": "Updated details of monthly finances...", + "priority": "high" +} + +### Delete report +DELETE https://nisa-invest-tfb-be.vercel.app/reports/1 + +## Users + +### Get all users +GET https://nisa-invest-tfb-be.vercel.app/users/all + +### Get user by email +GET https://nisa-invest-tfb-be.vercel.app/users/email/emma.johnson@email.com + +### Create user +POST https://nisa-invest-tfb-be.vercel.app/users +Content-Type: application/json + +{ + "email": "user@example.com", + "first_name": "John", + "last_name": "Doe", + "password": "securepassword123" +} + +### Update user +PUT https://nisa-invest-tfb-be.vercel.app/users/1 +Content-Type: application/json + +{ + "first_name": "Jane", + "last_name": "Smith", + "email": "jane.smith@example.com" +} + +### Delete user DELETE https://nisa-invest-tfb-be.vercel.app/users/7 \ No newline at end of file diff --git a/README.md b/README.md index 015b6d3..9ce71f8 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,42 @@ -# NisaInvest-TFB-BE - -This backend project is designed to work with Vercel's serverless environment. Here's a quick guide to get you started: - -## Deployment - -### Environment Variables -- **Development**: Use `.env` file -CORS_ORIGIN=http://localhost:3000 -- **Production**: Set in Vercel dashboard -CORS_ORIGIN=https://the-frontend-domain.com - -### Deployment Command -```npx vercel --prod``` -Backend URL: https://nisa-invest-tfb-be.vercel.app/ -It will also deploy when pushing code to the branch 'deployed' - -### Local Development -#### Supabase Commands -##### Start local instance: -```npx supabase start``` -##### Stop local instance: -```npx supabase stop``` -##### Reset local DB: -```npx supabase db reset``` -##### Access local Supabase Studio: -```http://localhost:54323/project/default``` - -### Supabase Remote Setup - -1) Generate access token at https://app.supabase.com -2) Set environment variable: -```export SUPABASE_ACCESS_TOKEN=your_new_token_here``` - -3) Link with remote DB: -```npx supabase link --project-ref xzzacivebczssoporkmz``` - -### Reset Remote DB (Caution: Will reseed) -```npx supabase db reset --linked``` - -## API Documentation +# NisaInvest-TFB-BE + +This backend project is designed to work with Vercel's serverless environment. Here's a quick guide to get you started: + +## Deployment + +### Environment Variables +- **Development**: Use `.env` file +CORS_ORIGIN=http://localhost:3000 +- **Production**: Set in Vercel dashboard +CORS_ORIGIN=https://the-frontend-domain.com + +### Deployment Command +```npx vercel --prod``` +Backend URL: https://nisa-invest-tfb-be.vercel.app/ +It will also deploy when pushing code to the branch 'deployed' + +### Local Development +#### Supabase Commands +##### Start local instance: +```npx supabase start``` +##### Stop local instance: +```npx supabase stop``` +##### Reset local DB: +```npx supabase db reset``` +##### Access local Supabase Studio: +```http://localhost:54323/project/default``` + +### Supabase Remote Setup + +1) Generate access token at https://app.supabase.com +2) Set environment variable: +```export SUPABASE_ACCESS_TOKEN=your_new_token_here``` + +3) Link with remote DB: +```npx supabase link --project-ref xzzacivebczssoporkmz``` + +### Reset Remote DB (Caution: Will reseed) +```npx supabase db reset --linked``` + +## API Documentation See [API Endpoints](API_endpoints.md) \ No newline at end of file diff --git a/src/config/config.ts b/src/config/config.ts index 7c62990..8937e0f 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -1,31 +1,31 @@ -import dotenv from 'dotenv'; - -dotenv.config(); - -interface Config { - port: number; - corsOrigin: string; - nodeEnv: string; - supabaseUrl: string; - supabaseAnonKey: string; -} - -const isProd = process.env.NODE_ENV === 'production'; - -console.log('Environment:', process.env.NODE_ENV); -console.log('Is Production:', isProd); - -const config: Config = { - port: parseInt(process.env.PORT || '3000', 10), - corsOrigin: process.env.CORS_ORIGIN || '*', - nodeEnv: process.env.NODE_ENV || 'development', - supabaseUrl: isProd ? process.env.PROD_SUPABASE_URL! : process.env.LOCAL_SUPABASE_URL!, - supabaseAnonKey: isProd ? process.env.PROD_SUPABASE_ANON_KEY! : process.env.LOCAL_SUPABASE_ANON_KEY!, -}; - -console.log('Config:', { - ...config, - supabaseAnonKey: config.supabaseAnonKey ? '[REDACTED]' : 'undefined' -}); - +import dotenv from 'dotenv'; + +dotenv.config(); + +interface Config { + port: number; + corsOrigin: string; + nodeEnv: string; + supabaseUrl: string; + supabaseAnonKey: string; +} + +const isProd = process.env.NODE_ENV === 'production'; + +console.log('Environment:', process.env.NODE_ENV); +console.log('Is Production:', isProd); + +const config: Config = { + port: parseInt(process.env.PORT || '3000', 10), + corsOrigin: process.env.CORS_ORIGIN || '*', + nodeEnv: process.env.NODE_ENV || 'development', + supabaseUrl: isProd ? process.env.PROD_SUPABASE_URL! : process.env.LOCAL_SUPABASE_URL!, + supabaseAnonKey: isProd ? process.env.PROD_SUPABASE_ANON_KEY! : process.env.LOCAL_SUPABASE_ANON_KEY!, +}; + +console.log('Config:', { + ...config, + supabaseAnonKey: config.supabaseAnonKey ? '[REDACTED]' : 'undefined' +}); + export default config; \ No newline at end of file diff --git a/src/routes/users.ts b/src/routes/users.ts index b4ccfbe..2e20c27 100644 --- a/src/routes/users.ts +++ b/src/routes/users.ts @@ -1,95 +1,95 @@ -import express from 'express'; -import supabase from '../supabaseClient'; - -const router = express.Router(); - -// Get all users -router.get('/all', async (req, res) => { - try { - const { data, error } = await supabase.from('users').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 user by ID -router.get('/id/:id', async (req, res) => { - try { - const { data, error } = await supabase - .from('users') - .select('*') - .eq('id', req.params.id); - - if (error) throw new Error(error.message); - if (data.length === 0) return res.status(404).json({ error: 'User not found' }); - if (data.length > 1) return res.status(500).json({ error: 'Multiple users found with the same ID' }); - - res.json(data[0]); - } catch (error: unknown) { - res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); - } -}); - -// Get user by email -router.get('/email/:email', async (req, res) => { - try { - const { data, error } = await supabase - .from('users') - .select('*') - .eq('email', req.params.email) - .single(); - if (error) throw new Error(error.message); - if (!data) return res.status(404).json({ error: 'User not found' }); - res.json(data); - } catch (error: unknown) { - res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); - } -}); - -// Create user -router.post('/', async (req, res) => { - try { - const { data, error } = await supabase - .from('users') - .insert([req.body]) - .select(); - if (error) throw new Error(error.message); - res.status(201).json(data[0]); - } catch (error: unknown) { - res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); - } -}); - -// Update user -router.put('/:id', async (req, res) => { - try { - const { data, error } = await supabase - .from('users') - .update(req.body) - .eq('id', req.params.id) - .select(); - if (error) throw new Error(error.message); - if (data.length === 0) return res.status(404).json({ error: 'User not found' }); - res.json(data[0]); - } catch (error: unknown) { - res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); - } -}); - -// Delete user -router.delete('/:id', async (req, res) => { - try { - const { error } = await supabase - .from('users') - .delete() - .eq('id', req.params.id); - 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' }); - } -}); - +import express from 'express'; +import supabase from '../supabaseClient'; + +const router = express.Router(); + +// Get all users +router.get('/all', async (req, res) => { + try { + const { data, error } = await supabase.from('users').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 user by ID +router.get('/id/:id', async (req, res) => { + try { + const { data, error } = await supabase + .from('users') + .select('*') + .eq('id', req.params.id); + + if (error) throw new Error(error.message); + if (data.length === 0) return res.status(404).json({ error: 'User not found' }); + if (data.length > 1) return res.status(500).json({ error: 'Multiple users found with the same ID' }); + + res.json(data[0]); + } catch (error: unknown) { + res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); + } +}); + +// Get user by email +router.get('/email/:email', async (req, res) => { + try { + const { data, error } = await supabase + .from('users') + .select('*') + .eq('email', req.params.email) + .single(); + if (error) throw new Error(error.message); + if (!data) return res.status(404).json({ error: 'User not found' }); + res.json(data); + } catch (error: unknown) { + res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); + } +}); + +// Create user +router.post('/', async (req, res) => { + try { + const { data, error } = await supabase + .from('users') + .insert([req.body]) + .select(); + if (error) throw new Error(error.message); + res.status(201).json(data[0]); + } catch (error: unknown) { + res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); + } +}); + +// Update user +router.put('/:id', async (req, res) => { + try { + const { data, error } = await supabase + .from('users') + .update(req.body) + .eq('id', req.params.id) + .select(); + if (error) throw new Error(error.message); + if (data.length === 0) return res.status(404).json({ error: 'User not found' }); + res.json(data[0]); + } catch (error: unknown) { + res.status(500).json({ error: error instanceof Error ? error.message : 'An unknown error occurred' }); + } +}); + +// Delete user +router.delete('/:id', async (req, res) => { + try { + const { error } = await supabase + .from('users') + .delete() + .eq('id', req.params.id); + 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' }); + } +}); + export default router; \ No newline at end of file diff --git a/src/supabaseClient.ts b/src/supabaseClient.ts index 17f66b3..50f27b5 100644 --- a/src/supabaseClient.ts +++ b/src/supabaseClient.ts @@ -1,14 +1,14 @@ -import { createClient } from '@supabase/supabase-js' -import config from './config/config' - -console.log('NODE_ENV:', config.nodeEnv) -console.log('Supabase URL:', config.supabaseUrl) -console.log('Supabase Key:', config.supabaseAnonKey ? '**hidden**' : 'undefined') - -if (!config.supabaseUrl || !config.supabaseAnonKey) { - throw new Error('Supabase URL or Key is missing. Check your environment variables.') -} - -const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey) - +import { createClient } from '@supabase/supabase-js' +import config from './config/config' + +console.log('NODE_ENV:', config.nodeEnv) +console.log('Supabase URL:', config.supabaseUrl) +console.log('Supabase Key:', config.supabaseAnonKey ? '**hidden**' : 'undefined') + +if (!config.supabaseUrl || !config.supabaseAnonKey) { + throw new Error('Supabase URL or Key is missing. Check your environment variables.') +} + +const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey) + export default supabase \ No newline at end of file diff --git a/supabase/seed.sql b/supabase/seed.sql index 521daba..22f4507 100644 --- a/supabase/seed.sql +++ b/supabase/seed.sql @@ -1,128 +1,128 @@ --- Clear existing data -TRUNCATE TABLE users, goals, quotes, user_goals RESTART IDENTITY CASCADE; - --- Insert goals -INSERT INTO goals (category, title, description, is_recurrent, recurrence_type, recurrence_value, sort_order) VALUES -('savings', 'I have at least 50% of one month''s salary saved', 'I have at least 50% of one month''s salary saved', false, NULL, NULL,1), -('savings', 'I built an emergency fund of 3 to 6 months of expenses', 'I built an emergency fund of 3 to 6 months of expenses', false, NULL, NULL,2), -('expenses', 'I can login online to all my utility providers', 'I can login online to all my utility providers', false, NULL, NULL,1), -('expenses', 'I know the cost of my monthly expenses', 'I know the cost of my monthly expenses', false, NULL, NULL,2), -('expenses', 'I have logged into my personal tax account and confirmed my tax code', 'I have logged into my personal tax account and confirmed my tax code', false, NULL, NULL,3), -('expenses', 'I have a SIM-only mobile phone plan', 'I have a SIM-only mobile phone plan', false, NULL, NULL,4), -('expenses', 'I have negotiated with my utilities providers in the last 18 months', 'I have negotiated with my utilities providers in the last 18 months', false, NULL, NULL,5), -('expenses', 'My expenses are no more than 50-60% of my take home pay', 'My expenses are no more than 50-60% of my take home pay', false, NULL, NULL,6), -('expenses', 'I save in advance for larger purchases with a sinking fund', 'I save in advance for larger purchases with a sinking fund', false, NULL, NULL,7), -('expenses', 'My personal spending comes out of a separate bank account', 'My personal spending comes out of a separate bank account', false, NULL, NULL,8), -('investing', 'I have a list of any debts I have outstanding', 'I have a list of any debts I have outstanding', false, NULL, NULL,1), -('investing', 'I don''t use a credit card', 'I don''t use a credit card', false, NULL, NULL,2), -('investing', 'I can login online to my pension accounts', 'I can login online to my pension accounts', false, NULL, NULL,3), -('investing', 'I know what my employer''s pension offers and confirmed the halal options', 'I know what my employer''s pension offers and confirmed the halal options', false, NULL, NULL,4), -('investing', 'I have checked and confirmed the information on my credit report', 'I have checked and confirmed the information on my credit report', false, NULL, NULL,5), -('investing', 'I know which platform to use to open an investment account that offers halal options', 'I know which platform to use to open an investment account that offers halal options', false, NULL, NULL,6), -('investing', 'I am being tax efficient', 'I am being tax efficient', false, NULL, NULL,7), -('investing', 'I have a plan to pay down my debt including contributing at least 20% of my take-home pay to it', 'I have a plan to pay down my debt including contributing at least 20% of my take-home pay to it', false, NULL, NULL,8), -('investing', 'I am investing 20% of my take-home pay in halal assets', 'I am investing 20% of my take-home pay in halal assets', false, NULL, NULL,9), -('charity', 'I purify any interest I receive in my bank accounts', 'I purify any interest I receive in my bank accounts', false, NULL, NULL,1), -('charity', 'I give back in person', 'I give back in person', false, NULL, NULL,2), -('charity', 'I know how to calculate and pay my zakat', 'I know how to calculate and pay my zakat', false, NULL, NULL,3), -('charity', 'I make a regular donation from my payslip', 'I make a regular donation from my payslip', false, NULL, NULL,4); - --- Insert quotes -INSERT INTO quotes (text, author, valid_from, valid_to) VALUES -('Strive for that which will benefit you, seek the help of Allah, and do not feel helpless.', 'Hadith Muslim', NULL, NULL), -('The Messenger of Allah (PBUH) said: Whoever among you wakes up physically healthy, feeling safe and secure within himself, with food for the day, it is as if he acquired the whole world.', 'Salamah bin ''Ubaidullah bin Mihsan Al-Ansari', NULL, NULL), -('The Prophet (PBUH) said, "So his wealth is whatever he spends (in Allah''s Cause) during his life (on good deeds) while the wealth of his heirs is whatever he leaves after his death.', 'Al-Bukhari', NULL, NULL), -('Truly, for every nation there is a trial, and the trial for my nation is wealth', 'Prophet Muhammad (PBUH)', NULL, NULL), -('If the son of Adam had a valley full of gold, he would like to have two valleys.', 'Prophet Muhammad (PBUH)', NULL, NULL), -('Believe in Allah and His Messenger and spend out of that of which He has made you trustees. For those who have believed among you and spent, there will be a great reward.', 'Qur''an 57:7', NULL, NULL), -('And [they are] those who, when they spend, do so not excessively or sparingly but are ever, between that, justly moderate.', 'Qur''an 25:67', NULL, NULL), -('Eat, drink, give in charity, and wear nice clothing, but without pride and extravagance. Verily, Allah loves for His blessings to be seen upon His servants.', 'Prophet Muhammad (PBUH)', NULL, NULL), -('The example of those who spend their wealth in the way of Allah is like a seed [of grain] which grows seven spikes; in each spike is a hundred grains. And Allah multiplies [His reward] for whom He wills.', 'Qur''an 2:261', NULL, NULL), -('Compare [yourself] to those who are lower than you [in wealth] and do not look at those who are above you [in wealth], for it is more suitable that you do not discount the blessings of Allah.', 'Prophet Muhammad (PBUH)', NULL, NULL), -('Charity does not decrease wealth, no one forgives another person but Allah increases their honor, and no one humbles himself for the sake of Allah but that Allah raises their status.', 'Prophet Muhammad (PBUH)', NULL, NULL), -('And if you should count the favors of Allah, you could not enumerate them.', 'Qur''an 17:100', NULL, NULL), -('Tie your camel first, and then put your trust in Allah.', 'Prophet Muhammad (PBUH)', NULL, NULL), -('Richness does not lie in the abundance of (worldly) goods but richness is the richness of the soul (heart, self).', 'Prophet Muhammad (PBUH)', NULL, NULL), -('Wealth is not in having many possessions, but rather (true) wealth is feeling sufficiency in the soul.', 'Prophet Muhammad (PBUH)', NULL, NULL); - --- Insert users -INSERT INTO users (created_at, email, first_name, last_name, password) VALUES -('2024-01-01 10:00:00+00', 'emma.johnson@email.com', 'Emma', 'Johnson Nore', 'hashed_password_1'), -('2024-01-02 11:30:00+00', 'liam.smith@email.com', 'Liam', 'Smith', 'hashed_password_2'), -('2024-01-03 09:15:00+00', 'sophia.brown@email.com', 'Sophia', 'Brown', 'hashed_password_3'), -('2024-01-04 14:45:00+00', 'noah.taylor@email.com', 'Noah', 'Taylor', 'hashed_password_4'), -('2024-01-05 16:20:00+00', 'olivia.davis@email.com', 'Olivia', 'Davis', 'hashed_password_5'); - --- Insert user_goals -INSERT INTO user_goals (user_id, goal_id, assigned_at, due_date, status, completed_at) VALUES -(1, 1, '2023-07-01T10:00:00Z', '2023-12-31T23:59:59Z', 'completed', NULL), -(1, 2, '2023-07-02T11:30:00Z', '2023-11-30T23:59:59Z', 'focused', '2023-10-15T14:45:00Z'), -(1, 3, '2023-07-03T09:15:00Z', '2024-01-31T23:59:59Z', 'not_done', NULL), -(1, 4, '2023-07-04T14:00:00Z', '2023-12-15T23:59:59Z', 'completed', NULL), -(1, 5, '2023-07-05T16:45:00Z', '2024-02-29T23:59:59Z', 'not_done', NULL), -(2, 1, '2023-07-06T08:30:00Z', '2023-10-31T23:59:59Z', 'focused', '2023-09-30T18:20:00Z'), -(2, 2, '2023-07-07T13:00:00Z', '2024-03-31T23:59:59Z', 'completed', NULL), -(2, 3, '2023-07-08T11:45:00Z', '2023-12-31T23:59:59Z', 'not_done', NULL), -(2, 4, '2023-07-09T10:30:00Z', '2024-01-15T23:59:59Z', 'not_done', NULL), -(3, 1, '2023-07-10T15:15:00Z', '2023-11-30T23:59:59Z', 'completed', '2023-11-15T09:30:00Z'), -(3, 2, '2023-07-11T09:45:00Z', '2024-02-28T23:59:59Z', 'focused', NULL), -(3, 3, '2023-07-12T14:30:00Z', '2023-12-31T23:59:59Z', 'not_done', NULL), -(4, 1, '2023-07-13T11:00:00Z', '2023-10-31T23:59:59Z', 'completed', '2023-10-20T16:45:00Z'), -(4, 2, '2023-07-14T16:30:00Z', '2024-01-31T23:59:59Z', 'not_done', NULL), -(5, 1, '2023-07-15T10:45:00Z', '2023-12-15T23:59:59Z', 'not_done', NULL); - --- Insert questions -INSERT INTO questions (id, question, created_at) VALUES -(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'); - - ---Instert Answers -INSERT INTO answers (id, answer_text, question_id, goal_id, created_at) VALUES -(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'); - - ---Insert Reports -INSERT INTO reports (user_id, title, text, priority) VALUES --- Reports for user 1 -(1, 'Financial Review Meeting 1', 'The user is doing well on savings, but is finding it hard to give to charity due to not being involved with her community. It is recommended that she joins a local charity group to increase her involvement and opportunities to give back.', 'medium'), -(1, 'Savings Plan Review', 'Emma has successfully saved up an emergency fund of three months of expenses. She is advised to continue contributing to her savings and to start looking into investment options.', 'high'), -(1, 'Charity Contribution Advice', 'Emma shows strong financial discipline, but she needs to diversify her charity contributions. Suggest connecting with community leaders to find more opportunities.', 'low'), -(1, 'Investment Plan Update', 'Emma is advised to explore more diversified investment options to balance risk and return effectively.', 'medium'), - --- Reports for user 2 -(2, 'Investment Portfolio Review', 'Liam has diversified his investments well, but should look into halal investment options to align with his values. Regular reviews are necessary to maintain this alignment.', 'high'), -(2, 'Expense Management Strategy', 'Liam is keeping his expenses under control but should revisit his budget monthly to ensure he is meeting his financial goals.', 'medium'), -(2, 'Retirement Planning', 'Liam needs to focus more on his pension contributions. Increasing his monthly pension contributions will benefit him in the long term.', 'medium'), -(2, 'Monthly Budget Review', 'Liam needs to re-evaluate his monthly budget to cut down unnecessary expenses and increase savings.', 'low'), - --- Reports for user 3 -(3, 'Debt Management Plan', 'Sophia has a clear understanding of her debts. It is advised that she creates a detailed repayment plan to systematically reduce her debt over time.', 'high'), -(3, 'Pension Account Review', 'Sophia has been proactive about her pension. Reviewing her pension plans periodically will ensure she is getting the best returns.', 'medium'), -(3, 'Emergency Fund Analysis', 'Sophia has an adequate emergency fund. She should now focus on long-term savings and investment plans.', 'high'), - --- Reports for user 4 -(4, 'Savings Strategy Review', 'Noah is doing a great job with his savings. To further improve, he should consider setting up automatic transfers to his savings account.', 'low'), -(4, 'Utility Bills Management', 'Noah needs to monitor his utility bills closely to ensure he is not overpaying. Negotiating with providers could lead to significant savings.', 'medium'), -(4, 'Debt Repayment Strategy', 'Noah needs a structured plan to pay off his debts efficiently. Consolidating high-interest debts might be beneficial.', 'medium'), - --- Reports for user 5 -(5, 'Financial Health Check', 'Olivia has a solid financial foundation. However, she needs to focus on reducing her discretionary spending to free up more funds for savings and investments.', 'medium'), -(5, 'Community Involvement for Charity', 'Olivia is struggling with regular charity contributions. Joining community events can help her find more opportunities to give back.', 'low'), -(5, 'Charity Engagement Plan', 'Olivia should look into local community services to enhance her charity efforts and contribute more effectively.', 'low'); +-- Clear existing data +TRUNCATE TABLE users, goals, quotes, user_goals RESTART IDENTITY CASCADE; + +-- Insert goals +INSERT INTO goals (category, title, description, is_recurrent, recurrence_type, recurrence_value, sort_order) VALUES +('savings', 'I have at least 50% of one month''s salary saved', 'I have at least 50% of one month''s salary saved', false, NULL, NULL,1), +('savings', 'I built an emergency fund of 3 to 6 months of expenses', 'I built an emergency fund of 3 to 6 months of expenses', false, NULL, NULL,2), +('expenses', 'I can login online to all my utility providers', 'I can login online to all my utility providers', false, NULL, NULL,1), +('expenses', 'I know the cost of my monthly expenses', 'I know the cost of my monthly expenses', false, NULL, NULL,2), +('expenses', 'I have logged into my personal tax account and confirmed my tax code', 'I have logged into my personal tax account and confirmed my tax code', false, NULL, NULL,3), +('expenses', 'I have a SIM-only mobile phone plan', 'I have a SIM-only mobile phone plan', false, NULL, NULL,4), +('expenses', 'I have negotiated with my utilities providers in the last 18 months', 'I have negotiated with my utilities providers in the last 18 months', false, NULL, NULL,5), +('expenses', 'My expenses are no more than 50-60% of my take home pay', 'My expenses are no more than 50-60% of my take home pay', false, NULL, NULL,6), +('expenses', 'I save in advance for larger purchases with a sinking fund', 'I save in advance for larger purchases with a sinking fund', false, NULL, NULL,7), +('expenses', 'My personal spending comes out of a separate bank account', 'My personal spending comes out of a separate bank account', false, NULL, NULL,8), +('investing', 'I have a list of any debts I have outstanding', 'I have a list of any debts I have outstanding', false, NULL, NULL,1), +('investing', 'I don''t use a credit card', 'I don''t use a credit card', false, NULL, NULL,2), +('investing', 'I can login online to my pension accounts', 'I can login online to my pension accounts', false, NULL, NULL,3), +('investing', 'I know what my employer''s pension offers and confirmed the halal options', 'I know what my employer''s pension offers and confirmed the halal options', false, NULL, NULL,4), +('investing', 'I have checked and confirmed the information on my credit report', 'I have checked and confirmed the information on my credit report', false, NULL, NULL,5), +('investing', 'I know which platform to use to open an investment account that offers halal options', 'I know which platform to use to open an investment account that offers halal options', false, NULL, NULL,6), +('investing', 'I am being tax efficient', 'I am being tax efficient', false, NULL, NULL,7), +('investing', 'I have a plan to pay down my debt including contributing at least 20% of my take-home pay to it', 'I have a plan to pay down my debt including contributing at least 20% of my take-home pay to it', false, NULL, NULL,8), +('investing', 'I am investing 20% of my take-home pay in halal assets', 'I am investing 20% of my take-home pay in halal assets', false, NULL, NULL,9), +('charity', 'I purify any interest I receive in my bank accounts', 'I purify any interest I receive in my bank accounts', false, NULL, NULL,1), +('charity', 'I give back in person', 'I give back in person', false, NULL, NULL,2), +('charity', 'I know how to calculate and pay my zakat', 'I know how to calculate and pay my zakat', false, NULL, NULL,3), +('charity', 'I make a regular donation from my payslip', 'I make a regular donation from my payslip', false, NULL, NULL,4); + +-- Insert quotes +INSERT INTO quotes (text, author, valid_from, valid_to) VALUES +('Strive for that which will benefit you, seek the help of Allah, and do not feel helpless.', 'Hadith Muslim', NULL, NULL), +('The Messenger of Allah (PBUH) said: Whoever among you wakes up physically healthy, feeling safe and secure within himself, with food for the day, it is as if he acquired the whole world.', 'Salamah bin ''Ubaidullah bin Mihsan Al-Ansari', NULL, NULL), +('The Prophet (PBUH) said, "So his wealth is whatever he spends (in Allah''s Cause) during his life (on good deeds) while the wealth of his heirs is whatever he leaves after his death.', 'Al-Bukhari', NULL, NULL), +('Truly, for every nation there is a trial, and the trial for my nation is wealth', 'Prophet Muhammad (PBUH)', NULL, NULL), +('If the son of Adam had a valley full of gold, he would like to have two valleys.', 'Prophet Muhammad (PBUH)', NULL, NULL), +('Believe in Allah and His Messenger and spend out of that of which He has made you trustees. For those who have believed among you and spent, there will be a great reward.', 'Qur''an 57:7', NULL, NULL), +('And [they are] those who, when they spend, do so not excessively or sparingly but are ever, between that, justly moderate.', 'Qur''an 25:67', NULL, NULL), +('Eat, drink, give in charity, and wear nice clothing, but without pride and extravagance. Verily, Allah loves for His blessings to be seen upon His servants.', 'Prophet Muhammad (PBUH)', NULL, NULL), +('The example of those who spend their wealth in the way of Allah is like a seed [of grain] which grows seven spikes; in each spike is a hundred grains. And Allah multiplies [His reward] for whom He wills.', 'Qur''an 2:261', NULL, NULL), +('Compare [yourself] to those who are lower than you [in wealth] and do not look at those who are above you [in wealth], for it is more suitable that you do not discount the blessings of Allah.', 'Prophet Muhammad (PBUH)', NULL, NULL), +('Charity does not decrease wealth, no one forgives another person but Allah increases their honor, and no one humbles himself for the sake of Allah but that Allah raises their status.', 'Prophet Muhammad (PBUH)', NULL, NULL), +('And if you should count the favors of Allah, you could not enumerate them.', 'Qur''an 17:100', NULL, NULL), +('Tie your camel first, and then put your trust in Allah.', 'Prophet Muhammad (PBUH)', NULL, NULL), +('Richness does not lie in the abundance of (worldly) goods but richness is the richness of the soul (heart, self).', 'Prophet Muhammad (PBUH)', NULL, NULL), +('Wealth is not in having many possessions, but rather (true) wealth is feeling sufficiency in the soul.', 'Prophet Muhammad (PBUH)', NULL, NULL); + +-- Insert users +INSERT INTO users (created_at, email, first_name, last_name, password) VALUES +('2024-01-01 10:00:00+00', 'emma.johnson@email.com', 'Emma', 'Johnson Nore', 'hashed_password_1'), +('2024-01-02 11:30:00+00', 'liam.smith@email.com', 'Liam', 'Smith', 'hashed_password_2'), +('2024-01-03 09:15:00+00', 'sophia.brown@email.com', 'Sophia', 'Brown', 'hashed_password_3'), +('2024-01-04 14:45:00+00', 'noah.taylor@email.com', 'Noah', 'Taylor', 'hashed_password_4'), +('2024-01-05 16:20:00+00', 'olivia.davis@email.com', 'Olivia', 'Davis', 'hashed_password_5'); + +-- Insert user_goals +INSERT INTO user_goals (user_id, goal_id, assigned_at, due_date, status, completed_at) VALUES +(1, 1, '2023-07-01T10:00:00Z', '2023-12-31T23:59:59Z', 'completed', NULL), +(1, 2, '2023-07-02T11:30:00Z', '2023-11-30T23:59:59Z', 'focused', '2023-10-15T14:45:00Z'), +(1, 3, '2023-07-03T09:15:00Z', '2024-01-31T23:59:59Z', 'not_done', NULL), +(1, 4, '2023-07-04T14:00:00Z', '2023-12-15T23:59:59Z', 'completed', NULL), +(1, 5, '2023-07-05T16:45:00Z', '2024-02-29T23:59:59Z', 'not_done', NULL), +(2, 1, '2023-07-06T08:30:00Z', '2023-10-31T23:59:59Z', 'focused', '2023-09-30T18:20:00Z'), +(2, 2, '2023-07-07T13:00:00Z', '2024-03-31T23:59:59Z', 'completed', NULL), +(2, 3, '2023-07-08T11:45:00Z', '2023-12-31T23:59:59Z', 'not_done', NULL), +(2, 4, '2023-07-09T10:30:00Z', '2024-01-15T23:59:59Z', 'not_done', NULL), +(3, 1, '2023-07-10T15:15:00Z', '2023-11-30T23:59:59Z', 'completed', '2023-11-15T09:30:00Z'), +(3, 2, '2023-07-11T09:45:00Z', '2024-02-28T23:59:59Z', 'focused', NULL), +(3, 3, '2023-07-12T14:30:00Z', '2023-12-31T23:59:59Z', 'not_done', NULL), +(4, 1, '2023-07-13T11:00:00Z', '2023-10-31T23:59:59Z', 'completed', '2023-10-20T16:45:00Z'), +(4, 2, '2023-07-14T16:30:00Z', '2024-01-31T23:59:59Z', 'not_done', NULL), +(5, 1, '2023-07-15T10:45:00Z', '2023-12-15T23:59:59Z', 'not_done', NULL); + +-- Insert questions +INSERT INTO questions (id, question, created_at) VALUES +(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'); + + +--Instert Answers +INSERT INTO answers (id, answer_text, question_id, goal_id, created_at) VALUES +(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'); + + +--Insert Reports +INSERT INTO reports (user_id, title, text, priority) VALUES +-- Reports for user 1 +(1, 'Financial Review Meeting 1', 'The user is doing well on savings, but is finding it hard to give to charity due to not being involved with her community. It is recommended that she joins a local charity group to increase her involvement and opportunities to give back.', 'medium'), +(1, 'Savings Plan Review', 'Emma has successfully saved up an emergency fund of three months of expenses. She is advised to continue contributing to her savings and to start looking into investment options.', 'high'), +(1, 'Charity Contribution Advice', 'Emma shows strong financial discipline, but she needs to diversify her charity contributions. Suggest connecting with community leaders to find more opportunities.', 'low'), +(1, 'Investment Plan Update', 'Emma is advised to explore more diversified investment options to balance risk and return effectively.', 'medium'), + +-- Reports for user 2 +(2, 'Investment Portfolio Review', 'Liam has diversified his investments well, but should look into halal investment options to align with his values. Regular reviews are necessary to maintain this alignment.', 'high'), +(2, 'Expense Management Strategy', 'Liam is keeping his expenses under control but should revisit his budget monthly to ensure he is meeting his financial goals.', 'medium'), +(2, 'Retirement Planning', 'Liam needs to focus more on his pension contributions. Increasing his monthly pension contributions will benefit him in the long term.', 'medium'), +(2, 'Monthly Budget Review', 'Liam needs to re-evaluate his monthly budget to cut down unnecessary expenses and increase savings.', 'low'), + +-- Reports for user 3 +(3, 'Debt Management Plan', 'Sophia has a clear understanding of her debts. It is advised that she creates a detailed repayment plan to systematically reduce her debt over time.', 'high'), +(3, 'Pension Account Review', 'Sophia has been proactive about her pension. Reviewing her pension plans periodically will ensure she is getting the best returns.', 'medium'), +(3, 'Emergency Fund Analysis', 'Sophia has an adequate emergency fund. She should now focus on long-term savings and investment plans.', 'high'), + +-- Reports for user 4 +(4, 'Savings Strategy Review', 'Noah is doing a great job with his savings. To further improve, he should consider setting up automatic transfers to his savings account.', 'low'), +(4, 'Utility Bills Management', 'Noah needs to monitor his utility bills closely to ensure he is not overpaying. Negotiating with providers could lead to significant savings.', 'medium'), +(4, 'Debt Repayment Strategy', 'Noah needs a structured plan to pay off his debts efficiently. Consolidating high-interest debts might be beneficial.', 'medium'), + +-- Reports for user 5 +(5, 'Financial Health Check', 'Olivia has a solid financial foundation. However, she needs to focus on reducing her discretionary spending to free up more funds for savings and investments.', 'medium'), +(5, 'Community Involvement for Charity', 'Olivia is struggling with regular charity contributions. Joining community events can help her find more opportunities to give back.', 'low'), +(5, 'Charity Engagement Plan', 'Olivia should look into local community services to enhance her charity efforts and contribute more effectively.', 'low'); diff --git a/tests/users.http b/tests/users.http index 4503aa9..fab1bda 100644 --- a/tests/users.http +++ b/tests/users.http @@ -1,31 +1,31 @@ -### Users Endpoints ### - -### Get all users -GET http://localhost:3000/users/all - -### Get user by id -GET http://localhost:3000/users/id/2 - -### Get user by email -GET http://localhost:3000/users/email/emma.johnson@email.com - -### Create user -POST http://localhost:3000/users -Content-Type: application/json - -{ - "email": "new.user@exassdf.com", - "first_name": "New User", - "password": "securepassword123" -} - -### Update user -PUT http://localhost:3000/users/1 -Content-Type: application/json - -{ - "first_name": "Updated Name" -} - -### Delete user +### Users Endpoints ### + +### Get all users +GET http://localhost:3000/users/all + +### Get user by id +GET http://localhost:3000/users/id/2 + +### Get user by email +GET http://localhost:3000/users/email/emma.johnson@email.com + +### Create user +POST http://localhost:3000/users +Content-Type: application/json + +{ + "email": "new.user@exassdf.com", + "first_name": "New User", + "password": "securepassword123" +} + +### Update user +PUT http://localhost:3000/users/1 +Content-Type: application/json + +{ + "first_name": "Updated Name" +} + +### Delete user DELETE http://localhost:3000/users/7 \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e9d246a..d0ab6ca 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "rootDir": "./", - "outDir": "./dist", - "esModuleInterop": true, - "strict": true - }, - "include": ["src/**/*", "api/**/*"], - "exclude": ["node_modules", "**/*.spec.ts"] +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "rootDir": "./", + "outDir": "./dist", + "esModuleInterop": true, + "strict": true + }, + "include": ["src/**/*", "api/**/*"], + "exclude": ["node_modules", "**/*.spec.ts"] } \ No newline at end of file