Skip to content

Commit

Permalink
Merge branch 'main' into feat-added-eslint-to-avoid-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikrantsingh22 authored Oct 30, 2023
2 parents 4c8b65a + 12e0f1e commit 3c45468
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 45 deletions.
93 changes: 70 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,97 @@
# Review App - Backend Repo

This repository contains the backend code for the Review App project.

[![Screenshot-86.png](https://i.postimg.cc/pXzH9rcC/Screenshot-86.png)](https://postimg.cc/9rmSKmhw)
##### This project is divided into two repositories:
![Screenshot-86.png](https://i.postimg.cc/pXzH9rcC/Screenshot-86.png)

**Please Note**: This project is divided into two repositories:

1. [Review App Frontend](https://github.com/piyushgarg-dev/review-app)
2. Review App Backend (You are here)

Go to [this repository](https://github.com/piyushgarg-dev/review-app) to know more about the project.
For more information about the project, visit the [frontend repository](https://github.com/piyushgarg-dev/review-app).

## Environment Setup:

### Prerequisites:

1. Clone the repository:

```shell
git clone https://github.com/piyushgarg-dev/review-app-api.git
```

2. Move to the backend folder:

```shell
cd review-app-api
```

## Environment Setup :
3. Install and set up Docker.

1. Pre-requisites :
4. Run Docker in the background. If you have an older version of Docker, use the following command to run the `docker-compose.yml` file in detached mode:

a. Clone the Repo : `git clone https://github.com/piyushgarg-dev/review-app-api.git`
b. Move to backend foler : `cd review-app-api`
c. Install and Setup Docker
d. Run Docker in background
e. Run this command to run "docker-compose.yml" file in detach mode : `docker compose up -d`
f. Setup Backend by running command : `yarn`
```shell
docker-compose up -d
```

2. Create a `.env.local` file in the project's root directory
Otherwise, run:

3. The `.env.local` file should consist of :
```shell
docker compose up -d
```

`DATABASE_URL=postgresql://postgres:password@localhost:5432/review
JWT_SECRET=superman123`
5. Set up the backend by running the following command:
```shell
yarn
```

4. Run Migrations by running command : `yarn migrate:latest`
### Create a `.env.local` file in the project's root directory.

5. Run Backend server by running command : `yarn local`
The `.env.local` file should contain the following environment variables:

CONGRATULATIONS! your backend starts running on http://localhost:8000/local/graphql
```shell
DATABASE_URL=postgresql://postgres:password@localhost:5432/review
JWT_SECRET=superman123
```

## Communication Channels
### Run Migrations:

Run database migrations with the following command:

```shell
yarn migrate:latest
```

### Start the Backend Server:

To start the backend server, run the following command:

```shell
yarn local
```

Congratulations! Your backend is now running at http://localhost:8000/local/graphql.

## Communication Channels:

If you have any questions, need clarifications, or want to discuss ideas, feel free to reach out through the following channels:

- [Discord Server](https://discord.com/invite/YuUjtrufmT)
- [X(formerly Twitter)](https://twitter.com/piyushgarg_dev)
- [Discord Server](https://discord.com/invite/YuUjtrufmT)
- [Twitter](https://twitter.com/piyushgarg_dev) (formerly X)

We appreciate your contributions and look forward to working with you to make this project even better!

## Best Contributors
## Best Contributors:

<div align="center">
<a href="https://github.com/piyushgarg-dev/review-app-api/graphs/contributors">
<img src="https://contrib.rocks/image?repo=piyushgarg-dev/review-app-api&anon=1" />
</a>
</div>
</div>

## Thanks To All Our Contributors:

<a href="https://github.com/piyushgarg-dev/review-app-api/graphs/contributors">
<img src="https://contrib.rocks/image?repo=piyushgarg-dev/review-app-api" />
</a>
11 changes: 11 additions & 0 deletions functions/graphql/form/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ export interface SubmitFormResponseData {
export interface GetFormResponsesByFormIdInput {
formId: string
}

export interface GetFormResponsesByProjectId {
projectId: string
itemsPerPage?: number
cursor?: string
}

export interface GetPublicFormDataInput {
domain: string
formSlug: string
}
4 changes: 3 additions & 1 deletion functions/graphql/form/queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const queries = `#graphql
getForms(input: GetFormsInput!): [Form]
getFormById(id: ID!): Form
getFormResponses(input: GetFormResponsesByFormIdInput!): [FormResponse]
getFormResponsesByFormId(input: GetFormResponsesByFormIdInput!): [FormResponse]
getFormResponsesByProjectId(input: GetFormResponsesByProjectIdInput!): [FormResponse]
getPublicFormData(input: GetPublicFormDataInput!): FormPublicData
`
26 changes: 24 additions & 2 deletions functions/graphql/form/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ServerContext } from '../interfaces'
import {
CreateFormData,
GetFormResponsesByFormIdInput,
GetFormResponsesByProjectId,
GetFormsInput,
GetPublicFormDataInput,
SubmitFormResponseData,
UpdateFormData,
} from './interfaces'
Expand All @@ -25,13 +27,33 @@ const queries = {
ensureAuthenticated(ctx)
return FormService.getFormById(id)
},
getFormResponses: async (
getFormResponsesByFormId: async (
_: any,
{ input }: { input: GetFormResponsesByFormIdInput },
ctx: ServerContext
) => {
return FormService.getFormResponsesByFormId(input.formId)
},
getFormResponsesByProjectId: async (
_: any,
{ input }: { input: GetFormResponsesByProjectId },
ctx: ServerContext
) => {
ensureAuthenticated(ctx)
return FormService.getFormResponsesByFormId(input.formId, ctx)
const { projectId, itemsPerPage = 10, cursor } = input
return FormService.getFormResponsesByProjectId(projectId, ctx, {
cursor,
itemsPerPage,
})
},
getPublicFormData: async (
_: any,
{ input }: { input: GetPublicFormDataInput }
) => {
return FormService.getPublicFormData({
domain: input.domain,
slug: input.formSlug,
})
},
}

Expand Down
47 changes: 45 additions & 2 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,38 @@ export const types = `#graphql
input GetFormsInput {
projectId: ID!
}
type FormPublicData {
id: ID!
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 Expand Up @@ -75,7 +112,7 @@ export const types = `#graphql
primaryColor: String!
backgroundColor: String!
lang: String!
lang: String
collectVideoTestimonials: Boolean!
collectTextTestimonials: Boolean!
Expand Down Expand Up @@ -112,7 +149,7 @@ export const types = `#graphql
tags: [String]
approved: Boolean
reatedAt: Date
createdAt: Date
updatedAt: Date
}
Expand All @@ -132,4 +169,10 @@ export const types = `#graphql
input GetFormResponsesByFormIdInput {
formId: ID!
}
input GetFormResponsesByProjectIdInput {
projectId: ID!
itemsPerPage: Int
cursor: String
}
`
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
"repository": "[email protected]:piyushgarg-dev/review-app-api.git",
"author": "Piyush Garg <[email protected]>",
"scripts": {
"local": "dotenv -c local -- npm run prisma:generate && concurrently \"serverless offline --stage local --disableCookieValidation\"",
"migrate:latest": "dotenv -c local -- prisma migrate deploy",
"prisma:migrate:local": "dotenv -c local -- prisma migrate dev",
"local": "dotenv -c development -- npm run prisma:generate && concurrently \"serverless offline --stage development --disableCookieValidation\"",
"migrate:latest": "dotenv -c development -- prisma migrate deploy",
"prisma:migrate:local": "dotenv -c development -- prisma migrate dev",
"prisma:generate": "prisma generate",
"prisma:studio": "dotenv -c local -- prisma studio",
"prisma:studio": "dotenv -c development -- prisma studio",
"lint": "eslint .",
"check-types": "tsc -p tsconfig.json --noEmit"
"check-types": "tsc -p tsconfig.json --noEmit",
"deploy:prod": "dotenv -c production -- sh scripts/deploy.sh production"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.2",
Expand Down
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

datasource db {
Expand Down
10 changes: 10 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
STAGE="$1"

echo "[$STAGE]: Migrate Primsa"
dotenv -c $STAGE -- prisma migrate deploy

echo "[$STAGE]: Generate Primsa Client"
npm run prisma:generate

echo "[$STAGE]: Start Serverless Deployment"
sls deploy --stage $STAGE
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ provider:
timeout: 25
lambdaHashingVersion: 20201221
region: ap-south-1
profile: default
profile: melonreviews
environment:
STAGE: ${self:provider.stage}
NODE_ENV: ${self:provider.stage}
Expand Down
Loading

0 comments on commit 3c45468

Please sign in to comment.