-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added submitFormResponse mutation #17
Conversation
Thank you for following the naming conventions! 🙏 |
@piyushgarg-dev Hello sir, kindly review the changes. If any other change is required please let me know, and if everything is right, please merge my PR |
Great Work 🎉 |
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.
Here are few changes 😄 Thanks a lot for contributing 🙏🏻
prisma/schema.prisma
Outdated
userName String @map("user_name") | ||
userEmail String? @unique @map("user_email") | ||
userImage String? @map("user_image") | ||
rating Int? | ||
testimonial String @map("testimonial") | ||
jobTitle String? @map("job_title") | ||
websiteUrl String? @map("website_url") | ||
company String? | ||
createdAt DateTime @default(now()) @map("created_at") | ||
updatedAt DateTime @updatedAt @map("updated_at") |
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.
Can we drop the word user
?
We can have something like
name String
email String?
imageURL String? @map("image_url")
prisma/schema.prisma
Outdated
formId String @map("form_id") | ||
|
||
userName String @map("user_name") | ||
userEmail String? @unique @map("user_email") |
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.
Drop the @unique
here as one user can submit multiple feedbacks also.
Maybe in future, we can have a composite unique of formId+email
to enforce one entry per form.
functions/graphql/form/interfaces.ts
Outdated
company?: string | ||
} | ||
|
||
export interface GetFormResponsesInput { |
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.
Let's rename this to GetFormResponsesByFormIdInput
functions/graphql/form/resolver.ts
Outdated
const form = await FormService.getFormById(formId) | ||
|
||
if (!form) { | ||
throw new Error('No form exist with given id') |
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.
Replace the throw Error
with BadRequestError
from errors/BadRequestError.ts
functions/graphql/form/resolver.ts
Outdated
const { formId, ...otherData } = data | ||
|
||
//Check if form exist with given id | ||
const form = await FormService.getFormById(formId) |
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.
Can we include a select
here as this would do SELECT *
from DB which is expensive 😄
functions/graphql/form/resolver.ts
Outdated
{ data }: { data: SubmitFormResponseData }, | ||
ctx: ServerContext | ||
) => { | ||
const { formId, ...otherData } = data |
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.
This can be dangerous as ...otherdata
can bring any data which would go into DB.
Destructure each value and insert it in DB for security 😄
Example:
review-app-api/functions/graphql/form/resolver.ts
Lines 30 to 48 in 93a0f92
const form = await FormService.createForm({ | |
data: { | |
name, | |
slug: slugify(slug), | |
introTitle: 'Share a testimonial!', | |
introMessage: `Do you love using our product? We'd love to hear about it! - Share your experience with a quick video or text testimonial - Recording a video? Don't forget to smile 😊`, | |
promptTitle: 'Write a testimonial', | |
promptDescription: `- What do you like most about us?\n- Would you recommend us to a friend?`, | |
thankyouTitle: 'Thank you 🙏', | |
thankyouMessage: | |
'Thank you so much for your support! We appreciate your support and we hope you enjoy using our product.', | |
autoApproveTestimonials: false, | |
autoAddTags: [], | |
primaryColor: '#8B41F2', | |
backgroundColor: '#FFFFFF', | |
createdBy: { connect: { id: ctx.user?.id! } }, | |
project: { connect: { id: projectId } }, | |
}, | |
}) |
Hi @psworld Thanks 😄 |
Yes, sir. almost done. should I add |
We can take it up in different issue 😄 |
@piyushgarg-dev kindly review the new commit. I have made all the changes suggested by you. If there are any more changes required please let me know |
@piyushgarg-dev Are the migrations causing difficulties ? I just saw the migrations, I am working to reset the migration to main branch, and add only one migration to create the form_responses table. Please allow some time |
Great @psworld |
@psworld Can you please merge the lastest main branch into your code? |
Yes sir, I will do that |
@piyushgarg-dev hello sir, thankyou for your patience.
then I committed and pushed all the changes to my hopefully this what you wanted. |
Great Work @psworld |
@piyushgarg-dev Thankyou so much sir ! and really thankyou for your patience with me. I am a complete newbie , I only knew basic python, just saw your hackoberfest video at around 2 am at night and decided to contribute. and also really love your teaching style |
@piyushgarg-dev Hello sir. There is a small error in ordering of migration files:
The currently if you run By manually exchanging and renaming the migration files and putting them in correct order, no error occur while running Should I make submit with correct order of migration files, in this same branch |
What does this PR do?
Fixes #1
submitFormResponse
Mutation. This allows to submit responses of a form created by a user.getFormResponsesByFormId
Query. This allows to query form responses based on form Id.FormResponse
Type of change
How should this be tested?
-> mutation -> SubmitFormResponse
All the necessary changes required for the above changes are done at their respective places.
No unnecessary change has been done.