Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVOiceover committed Aug 4, 2024
2 parents 9f6d79f + 0008207 commit 0f50519
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import userRoutes from './routes/users'
import goalRoutes from './routes/goals'
import quoteRoutes from './routes/quotes'
import quizRoutes from './routes/quiz'
import contact_nisaRoutes from './routes/contactnisa'
import config from './config/config'

const app = express()
Expand All @@ -23,6 +24,7 @@ app.use('/users', userRoutes)
app.use('/goals', goalRoutes)
app.use('/quotes', quoteRoutes)
app.use('/quiz', quizRoutes)
app.use('/contactnisa', contact_nisaRoutes)

if (config.nodeEnv !== 'production') {
const server = app.listen(config.port, () => {
Expand Down
47 changes: 47 additions & 0 deletions src/routes/contactnisa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import express from 'express'
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
router.get('/all', async (req, res) => {
try {
const { data, error } = await supabase.from('contact_nisa').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' });
}
});


// Create contact request
router.post('/', async (req, res) => {
try {
const { data, error } = await supabase
.from('contact_nisa')
.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',
})
}
})

export default router


6 changes: 1 addition & 5 deletions supabase/20240729142954_remote_schema.sql.nore
Original file line number Diff line number Diff line change
@@ -1,6 +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');
14 changes: 13 additions & 1 deletion supabase/migrations/20240729115609_initial_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ CREATE TABLE IF NOT EXISTS
id bigint generated by default as identity,
created_at timestamp with time zone not null default now(),
email text not null default ''::text,
name text not null,
first_name text not null,
last_name text,
password text null,
constraint users_pkey primary key (id),
constraint users_email_key unique (email)
Expand Down Expand Up @@ -98,6 +99,17 @@ CREATE TABLE IF NOT EXISTS public.answers (
CONSTRAINT answers_pkey primary key (id)
) TABLESPACE pg_default;

CREATE TABLE IF NOT EXISTS
public.contact_nisa (
id bigserial,
first_name text null,
last_name text null,
email text not null default ''::text,
social_media text null,
text_field text null,
created_at timestamp with time zone null default current_timestamp,
constraint consact_nisa_pkey primary key (id)
) 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;
Expand Down
12 changes: 6 additions & 6 deletions supabase/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ INSERT INTO quotes (text, author, valid_from, valid_to) VALUES
('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, 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 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
Expand Down
4 changes: 2 additions & 2 deletions tests/users.http
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Content-Type: application/json

{
"email": "new.user@exsdf.com",
"name": "New User",
"first_name": "New User",
"password": "securepassword123"
}

Expand All @@ -21,7 +21,7 @@ PUT http://localhost:3000/users/1
Content-Type: application/json

{
"name": "Updated Name"
"first_name": "Updated Name"
}

### Delete user
Expand Down

0 comments on commit 0f50519

Please sign in to comment.