Skip to content
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

Merged
merged 8 commits into from
Oct 8, 2023

Conversation

psworld
Copy link

@psworld psworld commented Oct 8, 2023

What does this PR do?

Fixes #1

  1. Added submitFormResponse Mutation. This allows to submit responses of a form created by a user.
  2. Added getFormResponsesByFormId Query. This allows to query form responses based on form Id.
  3. Created a database model named: FormResponse

Type of change

  • New feature (non-breaking change which adds functionality)

How should this be tested?

  • You can test this at http://localhost:8000/local/graphql -> mutation -> SubmitFormResponse
  • I have made sure that db model FormResponse keep those fields optional which are optional during creating a Form.
    • Only required fields are:
      form   Form   @relation(fields: [formId], references: [id])
      formId String @map("form_id")
      userName    String   @map("user_name")
      testimonial String   @map("testimonial")
      

All the necessary changes required for the above changes are done at their respective places.
No unnecessary change has been done.

@github-actions
Copy link

github-actions bot commented Oct 8, 2023

Thank you for following the naming conventions! 🙏

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@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

@piyushgarg-dev
Copy link
Owner

Great Work 🎉

Copy link
Owner

@piyushgarg-dev piyushgarg-dev left a 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 🙏🏻

Comment on lines 132 to 141
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")
Copy link
Owner

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")

formId String @map("form_id")

userName String @map("user_name")
userEmail String? @unique @map("user_email")
Copy link
Owner

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.

company?: string
}

export interface GetFormResponsesInput {
Copy link
Owner

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

const form = await FormService.getFormById(formId)

if (!form) {
throw new Error('No form exist with given id')
Copy link
Owner

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

const { formId, ...otherData } = data

//Check if form exist with given id
const form = await FormService.getFormById(formId)
Copy link
Owner

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 😄

{ data }: { data: SubmitFormResponseData },
ctx: ServerContext
) => {
const { formId, ...otherData } = data
Copy link
Owner

@piyushgarg-dev piyushgarg-dev Oct 8, 2023

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:

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 } },
},
})

@piyushgarg-dev
Copy link
Owner

Hi @psworld
Are you working on this issue?

Thanks 😄

@psworld
Copy link
Author

psworld commented Oct 8, 2023

Hi @psworld Are you working on this issue?

Thanks 😄

@piyushgarg-dev

Yes, sir. almost done.

should I add videoTestimonialURL to my FormResponse model ?

@piyushgarg-dev
Copy link
Owner

We can take it up in different issue 😄

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@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

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@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

@piyushgarg-dev
Copy link
Owner

Great @psworld
I'll merge this once I am done with testing 😄

@piyushgarg-dev
Copy link
Owner

@psworld Can you please merge the lastest main branch into your code?

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@psworld Can you please merge the lastest main branch into your code?

Yes sir, I will do that

@piyushgarg-dev
Copy link
Owner

Hi @psworld Can you please merge #29 this PR to your branch and will merge it

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@piyushgarg-dev hello sir, thankyou for your patience.
I was facing some problem using git.

  1. I fetched upstream/feat/submit_form and then merged to my feat/submit_form branch
  2. I also fetched upstream/main and merged it with my feat/submit_form so my branch is upto date with latest changes in main

then I committed and pushed all the changes to my feat/submit_form branch.

hopefully this what you wanted.
Again thankyou for your patience.
Please let me know if any more changes are required.

@piyushgarg-dev piyushgarg-dev added hacktoberfest Hacktoberfest Accepted Issues hacktoberfest-accepted Hacktoberfest Accepted labels Oct 8, 2023
@piyushgarg-dev piyushgarg-dev merged commit bacb6ce into piyushgarg-dev:main Oct 8, 2023
2 checks passed
@piyushgarg-dev
Copy link
Owner

Great Work @psworld
Merged 🎉

@psworld
Copy link
Author

psworld commented Oct 8, 2023

Great Work @psworld Merged 🎉

@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.
Haven't slept from past 1 day, but it was all worth it. I got to learn so much. Thankyou so much for providing me with this opportunity 😊
Hopefully I will be able to contribute more in future 🙏

and also really love your teaching style

@psworld
Copy link
Author

psworld commented Oct 8, 2023

@piyushgarg-dev Hello sir.

There is a small error in ordering of migration files:

20231008135244_added_approve_tags_to_forms is coming before 20231008144348_added_form_response_table. This is causing reference error as added_approve_tags_to_forms is refrencing form_responses table in its SQL but it is not yet present is database.

The added_form_response_table migration should be applied first and then added_approve_tags_to_forms. Currently it's the opposite.

currently if you run yarn prisma:migrate:local will give you error Error: The underlying table for model form_responses does not exist.

By manually exchanging and renaming the migration files and putting them in correct order, no error occur while running yarn prisma:migrate:local and all migrations are successful.
But this will drop the existing SCHEMA when applying the migrations and all local data of database will be lost.

Should I make submit with correct order of migration files, in this same branch feat/submit_form or should I open a new issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Hacktoberfest Accepted Issues hacktoberfest-accepted Hacktoberfest Accepted
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Mutation for Form Submission
2 participants