diff --git a/.gitignore b/.gitignore index cce557e..e2d1a56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ /node_modules -/build +/dist *.gen.ts diff --git a/codegen.yml b/codegen.yml index 8bb9da1..02f7569 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,5 @@ overwrite: true -schema: "src/typeDefs/typeDefs.gql" +schema: 'src/typeDefs/typeDefs.gql' documents: null generates: src/typeDefs/typeDefs.gen.ts: @@ -8,5 +8,5 @@ generates: wrapFieldDefinitions: true enumsAsTypes: true plugins: - - "typescript" - - "typescript-resolvers" + - 'typescript' + - 'typescript-resolvers' diff --git a/nodemon.json b/nodemon.json index e7690ad..4583c27 100644 --- a/nodemon.json +++ b/nodemon.json @@ -3,4 +3,4 @@ "watch": ["src"], "exec": "yarn start", "ext": "ts" -} \ No newline at end of file +} diff --git a/package.json b/package.json index 2e85e8e..0ab3da6 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "backend", "version": "1.0.0", "main": "src/index.ts", + "private": "true", "license": "MIT", "dependencies": { "@prisma/client": "^2.7.1", @@ -17,8 +18,11 @@ "scripts": { "dev": "nodemon", "start": "ts-node src/index.ts", + "copy-assets": "cp src/typeDefs/typeDefs.gql dist/typeDefs/typeDefs.gql && cp .env.example dist/.env && vi dist/.env", + "build": "tsc && npm copy-assets", "codegen": "graphql-codegen --config codegen.yml", - "lint": "eslint" + "lint": "eslint", + "test": "echo \"Error: no test specified\" && exit 1" }, "devDependencies": { "@graphql-codegen/cli": "1.17.10", diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index fbceb73..a523df0 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -2,7 +2,7 @@ import jwt from 'jsonwebtoken' import { ApolloError, AuthenticationError, - ForbiddenError + ForbiddenError, } from 'apollo-server-express' import { PrismaClient } from '@prisma/client' @@ -37,7 +37,7 @@ const getFormAuthor = async (db: PrismaClient, id: number) => { const tokenGenerate = (email: string, id: number) => { return jwt.sign({ email, id }, '' + process.env.JWT_SECRET, { algorithm: 'HS256', - expiresIn: '7 days' + expiresIn: '7 days', }) } diff --git a/src/controllers/form.ts b/src/controllers/form.ts index 818160d..8f41278 100644 --- a/src/controllers/form.ts +++ b/src/controllers/form.ts @@ -1,33 +1,35 @@ -import { Answer as DbAnswer, PrismaClient } from '@prisma/client' +import { Answer as DbAnswer, PrismaClient, Form } from '@prisma/client' import { ApolloError, UserInputError } from 'apollo-server-express' import { - Form, + ChoisesQuestion, Form as GraphqlForm, + FormSubmission, InputQuestion, MutationCreateFormArgs, MutationFormSubmitArgs, - ServerAnswer + ServerAnswer, + Variant, } from '../typeDefs/typeDefs.gen' import { CreateChoises, FormConstructor, UploadedChoisesQuestion, UploadedInputQuestion, - UploadedQuestion + UploadedQuestion, } from './types' import { createDBForm, getDBForm, getDBFormsByUser, - submitDBAnswer + submitDBAnswer, } from '../db' const getForm = async ( db: PrismaClient, id: number, user: { requesterId: number; userId: number } -): Promise