Skip to content

Commit

Permalink
fix: added auth check
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushgarg-dev committed Oct 8, 2023
1 parent 42c08d5 commit 476d13d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion functions/graphql/form/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const queries = {
ctx: ServerContext
) => {
ensureAuthenticated(ctx)
return FormService.getFormResponsesByFormId(input.formId)
return FormService.getFormResponsesByFormId(input.formId, ctx)
},
}

Expand Down
4 changes: 3 additions & 1 deletion functions/graphql/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export const types = `#graphql
type FormResponse {
id: ID!
form: Form
formId: String!
name: String!
Expand All @@ -110,6 +109,9 @@ export const types = `#graphql
websiteUrl: String
company: String
tags: [String]
approved: Boolean
reatedAt: Date
updatedAt: Date
}
Expand Down
19 changes: 17 additions & 2 deletions services/form.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import prismaClient from '../db'
import AccessDeniedError from '../errors/AccessDeniedError'
import { UpdateFormData } from '../functions/graphql/form/interfaces'
import { ServerContext } from '../functions/graphql/interfaces'

class FormService {
public static createForm = prismaClient.form.create
Expand Down Expand Up @@ -30,9 +32,22 @@ class FormService {

public static createFormResponse = prismaClient.formResponse.create

public static getFormResponsesByFormId(formId: string) {
public static getFormResponsesByFormId(formId: string, ctx: ServerContext) {
if (!ctx.user?.id) throw new AccessDeniedError()

return prismaClient.formResponse.findMany({
where: { form: { id: formId } },
where: {
AND: [
{
form: {
id: formId,
project: {
ProjectAccessMapping: { every: { user: { id: ctx.user.id } } }, // TODO: Need to test more deeply
},
},
},
],
},
})
}
}
Expand Down

0 comments on commit 476d13d

Please sign in to comment.