This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 121
feat: inserting a question in a table #138
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3b6b0d
feat: change the way recency is asked
ykdojo e3344ea
feat: slight improvement in question submission backend
ykdojo 1b4fc01
feat: inserting a question into a table works
ykdojo a7e07ac
dx: convert submit_question from TS to JS
ykdojo 73e988f
fix: next env public -> private
ykdojo 8fe1ab4
dx: better error message
ykdojo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NEXT_PUBLIC_SUPABASE_URL=YOUR_SUPABASE_URL | ||
NEXT_PUBLIC_SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY | ||
NEXT_PRIVATE_SUPABASE_SERVICE_KEY=YOUR_SUPABASE_SERVICE_KEY |
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,41 @@ | ||||||
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction | ||||||
import { createClient, SupabaseClient } from '@supabase/supabase-js'; | ||||||
|
||||||
// TODO: move the following somewhere else. | ||||||
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || ''; | ||||||
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || ''; | ||||||
const supabaseServiceKey = process.env.NEXT_PRIVATE_SUPABASE_SERVICE_KEY || ''; | ||||||
const supabase = createClient(supabaseUrl, supabaseAnonKey); | ||||||
const supabaseSecret = createClient(supabaseUrl, supabaseServiceKey); | ||||||
|
||||||
export default async function handler(req, res) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Always nice to have :) |
||||||
// data format: | ||||||
// { | ||||||
// company: "a", | ||||||
// location: "a", | ||||||
// position: "b", | ||||||
// question: "a", | ||||||
// question_details: "", | ||||||
// recency-weeks: "2", | ||||||
// stay_anonymous: false | ||||||
// } | ||||||
const input_data = JSON.parse(req.body); | ||||||
const jwt = req.headers.authentication; | ||||||
const asked_date = new Date(new Date().setDate(new Date().getDate() - Number(input_data['recency-weeks']) * 7)); | ||||||
|
||||||
input_data['asked_date'] = asked_date; | ||||||
delete input_data['recency-weeks']; | ||||||
|
||||||
const { data: user, userError } = await supabase.auth.api.getUser(jwt); | ||||||
const id = user.identities[0]['id']; | ||||||
|
||||||
input_data['created_by'] = id; | ||||||
|
||||||
const { data, error } = await supabaseSecret.from('questions').insert([input_data]); | ||||||
|
||||||
if (error) { | ||||||
res.status(500).json({ error }); | ||||||
} else { | ||||||
res.status(200).json({ message: 'success!' }); | ||||||
} | ||||||
} |
This file was deleted.
Oops, something went wrong.
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -97,21 +97,22 @@ const Submit: NextPage<UserProps> = ({ session }) => { | |||||||||
</div> | ||||||||||
|
||||||||||
<div className='sm:col-span-3'> | ||||||||||
<label htmlFor='recency' className='block text-sm font-medium text-gray-700'> | ||||||||||
<label htmlFor='recency-weeks' className='block text-sm font-medium text-gray-700'> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
change here also as you have done in the below fields. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @debasishbsws thank you but this is an old PR so I'll close it |
||||||||||
How recently was this asked? | ||||||||||
</label> | ||||||||||
<div className='mt-1'> | ||||||||||
<select | ||||||||||
id='recency' | ||||||||||
{...register('recency', { required: true })} | ||||||||||
id='recency-weeks' | ||||||||||
{...register('recency-weeks', { required: true })} | ||||||||||
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
className='block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' | ||||||||||
> | ||||||||||
<option>Within the past week</option> | ||||||||||
<option>Within the past month</option> | ||||||||||
<option>1-2 months ago</option> | ||||||||||
<option>3-6 months ago</option> | ||||||||||
<option>7-12 months ago</option> | ||||||||||
<option>1+ year ago</option> | ||||||||||
{/* value is estimated # weeks since the question was asked */} | ||||||||||
<option value='1'>Within the past week</option> | ||||||||||
<option value='2'>Within the past month</option> | ||||||||||
<option value='6'>1-2 months ago</option> | ||||||||||
<option value='18'>3-6 months ago</option> | ||||||||||
<option value='38'>7-12 months ago</option> | ||||||||||
<option value='60'>1+ year ago</option> | ||||||||||
</select> | ||||||||||
</div> | ||||||||||
</div> | ||||||||||
|
@@ -131,13 +132,13 @@ const Submit: NextPage<UserProps> = ({ session }) => { | |||||||||
</div> | ||||||||||
|
||||||||||
<div className='sm:col-span-6'> | ||||||||||
<label htmlFor='question-details' className='block text-sm font-medium text-gray-700'> | ||||||||||
<label htmlFor='question_details' className='block text-sm font-medium text-gray-700'> | ||||||||||
Question details | ||||||||||
</label> | ||||||||||
<div className='mt-1'> | ||||||||||
<textarea | ||||||||||
id='question-details' | ||||||||||
{...register('question-details')} | ||||||||||
id='question_details' | ||||||||||
{...register('question_details')} | ||||||||||
rows={3} | ||||||||||
className='block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm' | ||||||||||
defaultValue={''} | ||||||||||
|
@@ -148,14 +149,14 @@ const Submit: NextPage<UserProps> = ({ session }) => { | |||||||||
<div className='relative mt-6 flex'> | ||||||||||
<div className='flex h-5 items-center'> | ||||||||||
<input | ||||||||||
id='stay-anonymous' | ||||||||||
{...register('stay-anonymous')} | ||||||||||
id='stay_anonymous' | ||||||||||
{...register('stay_anonymous')} | ||||||||||
type='checkbox' | ||||||||||
className='h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500' | ||||||||||
/> | ||||||||||
</div> | ||||||||||
<div className='ml-3 text-sm'> | ||||||||||
<label htmlFor='stay-anonymous' className='font-medium text-gray-700'> | ||||||||||
<label htmlFor='stay_anonymous' className='font-medium text-gray-700'> | ||||||||||
Stay anonymous | ||||||||||
</label> | ||||||||||
</div> | ||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.