Skip to content

Commit

Permalink
added delete form feature
Browse files Browse the repository at this point in the history
  • Loading branch information
swaraj-saasakitech committed Oct 22, 2023
1 parent 7cbdf65 commit 9c83ae0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions functions/graphql/form/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface GetFormsInput {
projectId: string
}

export interface DeleteFormData {
id: string
}

export interface UpdateFormData {
id: string

Expand Down
1 change: 1 addition & 0 deletions functions/graphql/form/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const mutations = `#graphql
createForm(data: CreateFormData!): String
updateForm(data: UpdateFormInput!): Boolean
submitFormResponse(data: SubmitFormResponseData!): String
deleteForm(data: DeleteFormInput!):Boolean
`
12 changes: 12 additions & 0 deletions functions/graphql/form/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ensureAuthenticated } from '../../../utils/auth'
import { ServerContext } from '../interfaces'
import {
CreateFormData,
DeleteFormData,
GetFormResponsesByFormIdInput,
GetFormResponsesByProjectId,
GetFormsInput,
Expand Down Expand Up @@ -97,6 +98,17 @@ const mutations = {
return true
},

deleteForm: async (
_: any,
{ data }: { data: DeleteFormData },
ctx: ServerContext
) => {
ensureAuthenticated(ctx)
await FormService.deleteForm(data.id)
return true
},


submitFormResponse: async (
_: any,
{ data }: { data: SubmitFormResponseData },
Expand Down
4 changes: 4 additions & 0 deletions functions/graphql/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export const types = `#graphql
projectId: ID!
}
input DeleteFormInput {
id: ID!
}
type FormPublicData {
id: ID!
primaryColor: String!
Expand Down
8 changes: 6 additions & 2 deletions services/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class FormService {
})
}

public static deleteForm(id: string) {
return prismaClient.form.delete({ where: { id }, });
}

public static createFormResponse = prismaClient.formResponse.create

public static getFormResponsesByProjectId(
Expand All @@ -98,8 +102,8 @@ class FormService {
},
cursor: options?.cursor
? {
id: options?.cursor,
}
id: options?.cursor,
}
: undefined,
take: options?.itemsPerPage ?? 10,
skip: options?.cursor ? 1 : 0, // Skip the cursor
Expand Down

0 comments on commit 9c83ae0

Please sign in to comment.