Skip to content

Commit

Permalink
Added query for get public form data
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushgarg-dev committed Oct 15, 2023
1 parent e85d111 commit 5ffe0ba
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
5 changes: 5 additions & 0 deletions functions/graphql/form/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ export interface SubmitFormResponseData {
export interface GetFormResponsesByFormIdInput {
formId: string
}

export interface GetPublicFormDataInput {
domain: string
formSlug: string
}
1 change: 1 addition & 0 deletions functions/graphql/form/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const queries = `#graphql
getForms(input: GetFormsInput!): [Form]
getFormById(id: ID!): Form
getFormResponses(input: GetFormResponsesByFormIdInput!): [FormResponse]
getPublicFormData(input: GetPublicFormDataInput!): FormPublicData
`
10 changes: 10 additions & 0 deletions functions/graphql/form/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CreateFormData,
GetFormResponsesByFormIdInput,
GetFormsInput,
GetPublicFormDataInput,
SubmitFormResponseData,
UpdateFormData,
} from './interfaces'
Expand Down Expand Up @@ -33,6 +34,15 @@ const queries = {
ensureAuthenticated(ctx)
return FormService.getFormResponsesByFormId(input.formId, ctx)
},
getPublicFormData: async (
_: any,
{ input }: { input: GetPublicFormDataInput }
) => {
return FormService.getPublicFormData({
domain: input.domain,
slug: input.formSlug,
})
},
}

const mutations = {
Expand Down
36 changes: 36 additions & 0 deletions functions/graphql/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export const types = `#graphql
projectId: String!
}
input GetPublicFormDataInput {
domain: String!
formSlug: String!
}
input UpdateFormInput {
id: ID!
Expand Down Expand Up @@ -45,6 +50,37 @@ export const types = `#graphql
input GetFormsInput {
projectId: ID!
}
type FormPublicData {
primaryColor: String!
backgroundColor: String!
introTitle: String!
introMessage: String
promptTitle: String!
promptDescription: String
thankyouTitle: String!
thankyouMessage: String
name: String!
enableCTA: Boolean!
ctaTitle: String
ctaURL: String
collectVideoTestimonials: Boolean!
collectTextTestimonials: Boolean!
collectRatings: Boolean!
collectImages: Boolean!
collectEmail: Boolean!
collectJobTitle: Boolean!
collectUserImage: Boolean!
collectWebsiteURL: Boolean!
collectCompany: Boolean!
lang: String!
}
type Form {
id: ID!
Expand Down
42 changes: 42 additions & 0 deletions services/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,48 @@ class FormService {
return prismaClient.form.findUnique({ where: { id } })
}

public static getPublicFormData({
domain,
slug,
}: {
domain: string
slug: string
}) {
return prismaClient.form.findFirst({
where: {
AND: [
{
project: { OR: [{ subdomain: domain }, { customDomain: domain }] },
},
{ slug },
],
},
select: {
backgroundColor: true,
collectCompany: true,
collectEmail: true,
collectImages: true,
collectJobTitle: true,
collectRatings: true,
collectUserImage: true,
collectTextTestimonials: true,
collectVideoTestimonials: true,
collectWebsiteURL: true,
ctaTitle: true,
enableCTA: true,
ctaURL: true,
introMessage: true,
introTitle: true,
name: true,
primaryColor: true,
promptDescription: true,
promptTitle: true,
thankyouMessage: true,
thankyouTitle: true,
},
})
}

public static updateFormById(id: string, formData: UpdateFormData) {
return prismaClient.form.update({
data: {
Expand Down

0 comments on commit 5ffe0ba

Please sign in to comment.