Skip to content

Commit

Permalink
merged from reports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVOiceover committed Aug 4, 2024
2 parents 82d1b59 + 5ca93a2 commit 0a46e56
Showing 5 changed files with 111 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deployVercel.yml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
node-version: '20' # or whatever version you're using.

- name: Install dependencies
run: npm ci
@@ -25,4 +25,4 @@ jobs:
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
3 changes: 3 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ import goalRoutes from './routes/goals'
import quoteRoutes from './routes/quotes'
import quizRoutes from './routes/quiz'
import contact_nisaRoutes from './routes/contactnisa'
import reportRoutes from './routes/reports'
import config from './config/config'

const app = express()
@@ -24,6 +25,8 @@ app.use('/users', userRoutes)
app.use('/goals', goalRoutes)
app.use('/quotes', quoteRoutes)
app.use('/quiz', quizRoutes)
app.use('/reports', reportRoutes)

app.use('/contactnisa', contact_nisaRoutes)

if (config.nodeEnv !== 'production') {
19 changes: 3 additions & 16 deletions src/routes/contactnisa.ts
Original file line number Diff line number Diff line change
@@ -3,17 +3,7 @@ import supabase from '../supabaseClient'

const router = express.Router()

// interface ContactRequest {
// id: number;
// firstName: string;
// lastName: string;
// email: string;
// socialMedia: string;
// textField: string;
// date: string;
// }

// Create contact request
// Get contact_request
router.get('/all', async (req, res) => {
try {
const { data, error } = await supabase.from('contact_nisa').select('*');
@@ -24,8 +14,7 @@ router.get('/all', async (req, res) => {
}
});


// Create contact request
// Create contact_request
router.post('/', async (req, res) => {
try {
const { data, error } = await supabase
@@ -42,6 +31,4 @@ router.post('/', async (req, res) => {
}
})

export default router


export default router
87 changes: 87 additions & 0 deletions src/routes/reports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import express from 'express'
import supabase from '../supabaseClient'

const router = express.Router()

// Get all reports
router.get('/all', async (req, res) => {
try {
const { data, error } = await supabase.from('reports').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 reports for a specific user
router.get('/user/:userId', async (req, res) => {
const userId = parseInt(req.params.userId);
try {
const { data, error } = await supabase
.from('reports')
.select('*')
.eq('user_id', userId);
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' });
}
});

// Create a new report
router.post('/', async (req, res) => {
try {
const { data, error } = await supabase
.from('reports')
.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 a report
router.put('/:id', async (req, res) => {
const reportId = parseInt(req.params.id);
try {
const { data, error } = await supabase
.from('reports')
.update(req.body)
.eq('id', reportId)
.select()
if (error) throw new Error(error.message)
if (data.length === 0) return res.status(404).json({ error: 'Report not found' })
res.json(data[0])
} catch (error: unknown) {
res.status(500).json({
error:
error instanceof Error ? error.message : 'An unknown error occurred',
})
}
});

// Delete a report
router.delete('/:id', async (req, res) => {
const reportId = parseInt(req.params.id);
try {
const { error } = await supabase
.from('reports')
.delete()
.eq('id', reportId)
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
19 changes: 16 additions & 3 deletions supabase/migrations/20240729115609_initial_schema.sql
Original file line number Diff line number Diff line change
@@ -113,10 +113,23 @@ CREATE TABLE IF NOT EXISTS
constraint consact_nisa_pkey primary key (id)
) tablespace pg_default;

CREATE TABLE IF NOT EXISTS
public.reports (
id bigint generated by default as identity,
user_id bigint null,
title text not null,
created_at timestamp with time zone not null default now(),
text text not null,
priority text not null,
constraint reports_pkey primary key (id),
constraint reports_user_id_fkey foreign key (user_id) references users (id),
constraint priority_check check (
priority = any (array['low'::text, 'medium'::text, 'high'::text])
)
) tablespace pg_default;

create index if not exists idx_quotes_date_range on public.quotes using btree (valid_from, valid_to) tablespace pg_default;
create index if not exists idx_user_goals_user_id on public.user_goals using btree (user_id) tablespace pg_default;
create index if not exists idx_user_goals_goal_id on public.user_goals using btree (goal_id) tablespace pg_default;
create index if not exists idx_answers_goal_id on public.user_goals using btree (goal_id) tablespace pg_default;

create type "public"."recurrence_type" as enum ('day', 'week', 'month', 'year');
create type "public"."status" as enum ('not_done', 'in_progress', 'completed');
CREATE index IF NOT EXISTS idx_reports_user_id ON public.reports USING btree (user_id) tablespace pg_default;

0 comments on commit 0a46e56

Please sign in to comment.