From f9dcf616d93a343f43c2fdaf75ba447045c1b9f0 Mon Sep 17 00:00:00 2001 From: Ram-tyagi Date: Wed, 11 Oct 2023 21:58:25 +0530 Subject: [PATCH 01/11] Contributers added in readme --- README.md | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f01b5bb..5d9acd5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # 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: + 1. [Review App Frontend](https://github.com/piyushgarg-dev/review-app) 2. Review App Backend (You are here) @@ -12,19 +15,19 @@ Go to [this repository](https://github.com/piyushgarg-dev/review-app) to know mo 1. Pre-requisites : - 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` + 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` 2. Create a `.env.local` file in the project's root directory 3. The `.env.local` file should consist of : - `DATABASE_URL=postgresql://postgres:password@localhost:5432/review - JWT_SECRET=superman123` + `DATABASE_URL=postgresql://postgres:password@localhost:5432/review +JWT_SECRET=superman123` 4. Run Migrations by running command : `yarn migrate:latest` @@ -36,8 +39,8 @@ CONGRATULATIONS! your backend starts running on http://localhost:8000/local/grap 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) +- [X(formerly Twitter)](https://twitter.com/piyushgarg_dev) We appreciate your contributions and look forward to working with you to make this project even better! @@ -47,4 +50,10 @@ We appreciate your contributions and look forward to working with you to make th - \ No newline at end of file + + +## Thanks To All Our Contributors + + + + From dacf31063ea63afae797073a19d768b51f3e7d8b Mon Sep 17 00:00:00 2001 From: Just Saad <115649011+saadabban76@users.noreply.github.com> Date: Fri, 13 Oct 2023 18:21:27 +0530 Subject: [PATCH 02/11] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d9acd5..8561340 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,9 @@ Go to [this repository](https://github.com/piyushgarg-dev/review-app) to know mo 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` + e. If you have an older version of Docker, run this command to run "docker-compose.yml" file in detach mode: + `docker-compose up -d` + Otherwise, run: `docker compose up -d` f. Setup Backend by running command : `yarn` 2. Create a `.env.local` file in the project's root directory From 94ad71336ba92a1129b380abb5fb9f695fed2b42 Mon Sep 17 00:00:00 2001 From: manish Date: Sat, 14 Oct 2023 10:06:12 +0530 Subject: [PATCH 03/11] docs: Update and Improve README --- README.md | 84 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 8561340..209ee4c 100644 --- a/README.md +++ b/README.md @@ -2,51 +2,87 @@ 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) +![Screenshot-86.png](https://i.postimg.cc/pXzH9rcC/Screenshot-86.png) -##### This project is divided into two repositories: +**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 : +## Environment Setup: -1. Pre-requisites : +### Prerequisites: - 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. If you have an older version of Docker, run this command to run "docker-compose.yml" file in detach mode: - `docker-compose up -d` - Otherwise, run: `docker compose up -d` - f. Setup Backend by running command : `yarn` +1. Clone the repository: -2. Create a `.env.local` file in the project's root directory + ```shell + git clone https://github.com/piyushgarg-dev/review-app-api.git + ``` -3. The `.env.local` file should consist of : +2. Move to the backend folder: - `DATABASE_URL=postgresql://postgres:password@localhost:5432/review -JWT_SECRET=superman123` + ```shell + cd review-app-api + ``` -4. Run Migrations by running command : `yarn migrate:latest` +3. Install and set up Docker. -5. Run Backend server by running command : `yarn local` +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: -CONGRATULATIONS! your backend starts running on http://localhost:8000/local/graphql + ```shell + docker-compose up -d + ``` -## Communication Channels + Otherwise, run: + + ```shell + docker compose up -d + ``` + +5. Set up the backend by running the following command: + ```shell + yarn + ``` + +### Create a `.env.local` file in the project's root directory. + +The `.env.local` file should contain the following environment variables: + +```shell +DATABASE_URL=postgresql://postgres:password@localhost:5432/review +JWT_SECRET=superman123 +``` + +### 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) +- [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:
@@ -54,7 +90,7 @@ We appreciate your contributions and look forward to working with you to make th
-## Thanks To All Our Contributors +## Thanks To All Our Contributors: From 5ffe0ba91a26e5d941b7b772dbf3c63695edb944 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Sun, 15 Oct 2023 14:45:09 +0530 Subject: [PATCH 04/11] Added query for get public form data --- functions/graphql/form/interfaces.ts | 5 ++++ functions/graphql/form/queries.ts | 1 + functions/graphql/form/resolver.ts | 10 +++++++ functions/graphql/form/types.ts | 36 ++++++++++++++++++++++++ services/form.ts | 42 ++++++++++++++++++++++++++++ 5 files changed, 94 insertions(+) diff --git a/functions/graphql/form/interfaces.ts b/functions/graphql/form/interfaces.ts index 5e57743..04e524b 100644 --- a/functions/graphql/form/interfaces.ts +++ b/functions/graphql/form/interfaces.ts @@ -61,3 +61,8 @@ export interface SubmitFormResponseData { export interface GetFormResponsesByFormIdInput { formId: string } + +export interface GetPublicFormDataInput { + domain: string + formSlug: string +} diff --git a/functions/graphql/form/queries.ts b/functions/graphql/form/queries.ts index da88a6a..db4de85 100644 --- a/functions/graphql/form/queries.ts +++ b/functions/graphql/form/queries.ts @@ -2,4 +2,5 @@ export const queries = `#graphql getForms(input: GetFormsInput!): [Form] getFormById(id: ID!): Form getFormResponses(input: GetFormResponsesByFormIdInput!): [FormResponse] + getPublicFormData(input: GetPublicFormDataInput!): FormPublicData ` diff --git a/functions/graphql/form/resolver.ts b/functions/graphql/form/resolver.ts index 67d3352..41712ca 100644 --- a/functions/graphql/form/resolver.ts +++ b/functions/graphql/form/resolver.ts @@ -6,6 +6,7 @@ import { CreateFormData, GetFormResponsesByFormIdInput, GetFormsInput, + GetPublicFormDataInput, SubmitFormResponseData, UpdateFormData, } from './interfaces' @@ -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 = { diff --git a/functions/graphql/form/types.ts b/functions/graphql/form/types.ts index 384e208..ce8f6e7 100644 --- a/functions/graphql/form/types.ts +++ b/functions/graphql/form/types.ts @@ -5,6 +5,11 @@ export const types = `#graphql projectId: String! } + input GetPublicFormDataInput { + domain: String! + formSlug: String! + } + input UpdateFormInput { id: ID! @@ -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! diff --git a/services/form.ts b/services/form.ts index 8120c61..5cef7d5 100644 --- a/services/form.ts +++ b/services/form.ts @@ -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: { From 60a8c83425991d9b02498013a75366eb3fd9bd2b Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Sun, 15 Oct 2023 18:17:22 +0530 Subject: [PATCH 05/11] bug fix: lang is not mandatory --- functions/graphql/form/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/graphql/form/types.ts b/functions/graphql/form/types.ts index ce8f6e7..bf28e2c 100644 --- a/functions/graphql/form/types.ts +++ b/functions/graphql/form/types.ts @@ -65,7 +65,7 @@ export const types = `#graphql thankyouMessage: String name: String! - + enableCTA: Boolean! ctaTitle: String ctaURL: String @@ -79,7 +79,7 @@ export const types = `#graphql collectUserImage: Boolean! collectWebsiteURL: Boolean! collectCompany: Boolean! - lang: String! + lang: String } type Form { @@ -111,7 +111,7 @@ export const types = `#graphql primaryColor: String! backgroundColor: String! - lang: String! + lang: String collectVideoTestimonials: Boolean! collectTextTestimonials: Boolean! From a3fdf69b1faa4347adc2367346ee42f516b7e714 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Wed, 18 Oct 2023 18:31:02 +0530 Subject: [PATCH 06/11] Added Query to fetch Public Form Responses --- functions/graphql/form/interfaces.ts | 4 ++++ functions/graphql/form/queries.ts | 3 ++- functions/graphql/form/resolver.ts | 11 ++++++++++- functions/graphql/form/types.ts | 6 +++++- services/form.ts | 17 +++++++++++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/functions/graphql/form/interfaces.ts b/functions/graphql/form/interfaces.ts index 04e524b..1005049 100644 --- a/functions/graphql/form/interfaces.ts +++ b/functions/graphql/form/interfaces.ts @@ -62,6 +62,10 @@ export interface GetFormResponsesByFormIdInput { formId: string } +export interface GetFormResponsesByProjectId { + projectId: string +} + export interface GetPublicFormDataInput { domain: string formSlug: string diff --git a/functions/graphql/form/queries.ts b/functions/graphql/form/queries.ts index db4de85..e3550d1 100644 --- a/functions/graphql/form/queries.ts +++ b/functions/graphql/form/queries.ts @@ -1,6 +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 ` diff --git a/functions/graphql/form/resolver.ts b/functions/graphql/form/resolver.ts index 41712ca..b5a0714 100644 --- a/functions/graphql/form/resolver.ts +++ b/functions/graphql/form/resolver.ts @@ -5,6 +5,7 @@ import { ServerContext } from '../interfaces' import { CreateFormData, GetFormResponsesByFormIdInput, + GetFormResponsesByProjectId, GetFormsInput, GetPublicFormDataInput, SubmitFormResponseData, @@ -26,7 +27,7 @@ const queries = { ensureAuthenticated(ctx) return FormService.getFormById(id) }, - getFormResponses: async ( + getFormResponsesByFormId: async ( _: any, { input }: { input: GetFormResponsesByFormIdInput }, ctx: ServerContext @@ -34,6 +35,14 @@ const queries = { ensureAuthenticated(ctx) return FormService.getFormResponsesByFormId(input.formId, ctx) }, + getFormResponsesByProjectId: async ( + _: any, + { input }: { input: GetFormResponsesByProjectId }, + ctx: ServerContext + ) => { + ensureAuthenticated(ctx) + return FormService.getFormResponsesByProjectId(input.projectId, ctx) + }, getPublicFormData: async ( _: any, { input }: { input: GetPublicFormDataInput } diff --git a/functions/graphql/form/types.ts b/functions/graphql/form/types.ts index bf28e2c..e712c98 100644 --- a/functions/graphql/form/types.ts +++ b/functions/graphql/form/types.ts @@ -148,7 +148,7 @@ export const types = `#graphql tags: [String] approved: Boolean - reatedAt: Date + createdAt: Date updatedAt: Date } @@ -168,4 +168,8 @@ export const types = `#graphql input GetFormResponsesByFormIdInput { formId: ID! } + + input GetFormResponsesByProjectIdInput { + projectId: ID! + } ` diff --git a/services/form.ts b/services/form.ts index 5cef7d5..7cdfafe 100644 --- a/services/form.ts +++ b/services/form.ts @@ -74,6 +74,23 @@ class FormService { public static createFormResponse = prismaClient.formResponse.create + public static getFormResponsesByProjectId( + projectId: string, + ctx: ServerContext + ) { + if (!ctx.user?.id) throw new AccessDeniedError() + return prismaClient.formResponse.findMany({ + where: { + form: { + project: { + id: projectId, + ProjectAccessMapping: { every: { user: { id: ctx.user.id } } }, // TODO: Need to test more deeply + }, + }, + }, + }) + } + public static getFormResponsesByFormId(formId: string, ctx: ServerContext) { if (!ctx.user?.id) throw new AccessDeniedError() From d788ff731f1d02372a1a79e3ffb27df456cafc6e Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Wed, 18 Oct 2023 23:26:47 +0530 Subject: [PATCH 07/11] Added Pagination --- functions/graphql/form/interfaces.ts | 2 ++ functions/graphql/form/resolver.ts | 6 +++++- functions/graphql/form/types.ts | 2 ++ services/form.ts | 17 ++++++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/functions/graphql/form/interfaces.ts b/functions/graphql/form/interfaces.ts index 1005049..cc46f84 100644 --- a/functions/graphql/form/interfaces.ts +++ b/functions/graphql/form/interfaces.ts @@ -64,6 +64,8 @@ export interface GetFormResponsesByFormIdInput { export interface GetFormResponsesByProjectId { projectId: string + itemsPerPage?: number + cursor?: string } export interface GetPublicFormDataInput { diff --git a/functions/graphql/form/resolver.ts b/functions/graphql/form/resolver.ts index b5a0714..0355ab7 100644 --- a/functions/graphql/form/resolver.ts +++ b/functions/graphql/form/resolver.ts @@ -41,7 +41,11 @@ const queries = { ctx: ServerContext ) => { ensureAuthenticated(ctx) - return FormService.getFormResponsesByProjectId(input.projectId, ctx) + const { projectId, itemsPerPage = 10, cursor } = input + return FormService.getFormResponsesByProjectId(projectId, ctx, { + cursor, + itemsPerPage, + }) }, getPublicFormData: async ( _: any, diff --git a/functions/graphql/form/types.ts b/functions/graphql/form/types.ts index e712c98..5119d3e 100644 --- a/functions/graphql/form/types.ts +++ b/functions/graphql/form/types.ts @@ -171,5 +171,7 @@ export const types = `#graphql input GetFormResponsesByProjectIdInput { projectId: ID! + itemsPerPage: Int + cursor: String } ` diff --git a/services/form.ts b/services/form.ts index 7cdfafe..91f863f 100644 --- a/services/form.ts +++ b/services/form.ts @@ -3,6 +3,11 @@ import AccessDeniedError from '../errors/AccessDeniedError' import { UpdateFormData } from '../functions/graphql/form/interfaces' import { ServerContext } from '../functions/graphql/interfaces' +interface GetFormResponsesByProjectIdOptions { + itemsPerPage?: number + cursor?: string +} + class FormService { public static createForm = prismaClient.form.create @@ -76,9 +81,11 @@ class FormService { public static getFormResponsesByProjectId( projectId: string, - ctx: ServerContext + ctx: ServerContext, + options?: GetFormResponsesByProjectIdOptions ) { if (!ctx.user?.id) throw new AccessDeniedError() + return prismaClient.formResponse.findMany({ where: { form: { @@ -88,6 +95,14 @@ class FormService { }, }, }, + cursor: options?.cursor + ? { + id: options?.cursor, + } + : undefined, + take: options?.itemsPerPage ?? 10, + skip: 1, // Skip the cursor + orderBy: { createdAt: 'desc' }, }) } From fe0fbb7eb52a58e15fd501f15e1c2e3d8d3da156 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Wed, 18 Oct 2023 23:45:51 +0530 Subject: [PATCH 08/11] Cursor Paginationn bug fixed --- services/form.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/form.ts b/services/form.ts index 91f863f..f9815ce 100644 --- a/services/form.ts +++ b/services/form.ts @@ -101,7 +101,7 @@ class FormService { } : undefined, take: options?.itemsPerPage ?? 10, - skip: 1, // Skip the cursor + skip: options?.cursor ? 1 : 0, // Skip the cursor orderBy: { createdAt: 'desc' }, }) } From 3582cf84630a7387571e18753149553431e197d6 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Thu, 19 Oct 2023 14:54:52 +0530 Subject: [PATCH 09/11] Include ID in Form data --- functions/graphql/form/types.ts | 1 + services/form.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/functions/graphql/form/types.ts b/functions/graphql/form/types.ts index 5119d3e..bb4d32a 100644 --- a/functions/graphql/form/types.ts +++ b/functions/graphql/form/types.ts @@ -52,6 +52,7 @@ export const types = `#graphql } type FormPublicData { + id: ID! primaryColor: String! backgroundColor: String! diff --git a/services/form.ts b/services/form.ts index f9815ce..d2f81bd 100644 --- a/services/form.ts +++ b/services/form.ts @@ -57,6 +57,7 @@ class FormService { promptTitle: true, thankyouMessage: true, thankyouTitle: true, + id: true, }, }) } From f3f0f307345a966a1863aca9c55de53bf758966c Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Sun, 29 Oct 2023 12:29:16 +0530 Subject: [PATCH 10/11] Added Public Route to display approved reviews --- functions/graphql/form/resolver.ts | 3 +-- services/form.ts | 32 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/functions/graphql/form/resolver.ts b/functions/graphql/form/resolver.ts index 0355ab7..516f397 100644 --- a/functions/graphql/form/resolver.ts +++ b/functions/graphql/form/resolver.ts @@ -32,8 +32,7 @@ const queries = { { input }: { input: GetFormResponsesByFormIdInput }, ctx: ServerContext ) => { - ensureAuthenticated(ctx) - return FormService.getFormResponsesByFormId(input.formId, ctx) + return FormService.getFormResponsesByFormId(input.formId) }, getFormResponsesByProjectId: async ( _: any, diff --git a/services/form.ts b/services/form.ts index d2f81bd..b0023e1 100644 --- a/services/form.ts +++ b/services/form.ts @@ -107,21 +107,27 @@ class FormService { }) } - public static getFormResponsesByFormId(formId: string, ctx: ServerContext) { - if (!ctx.user?.id) throw new AccessDeniedError() - + public static getFormResponsesByFormId(formId: string) { return prismaClient.formResponse.findMany({ where: { - AND: [ - { - form: { - id: formId, - project: { - ProjectAccessMapping: { every: { user: { id: ctx.user.id } } }, // TODO: Need to test more deeply - }, - }, - }, - ], + formId, + }, + orderBy: { + updatedAt: 'desc', + }, + select: { + approved: true, + company: true, + createdAt: true, + email: true, + imageURL: true, + id: true, + jobTitle: true, + rating: true, + testimonial: true, + name: true, + websiteUrl: true, + formId: true, }, }) } From 12e0f1e041fc28965474489e09a84fcb58573168 Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Sun, 29 Oct 2023 19:01:50 +0530 Subject: [PATCH 11/11] Added deployment scripts --- package.json | 9 +++++---- prisma/schema.prisma | 3 ++- scripts/deploy.sh | 10 ++++++++++ serverless.yml | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 scripts/deploy.sh diff --git a/package.json b/package.json index d8d575a..378e392 100644 --- a/package.json +++ b/package.json @@ -5,11 +5,12 @@ "repository": "git@github.com:piyushgarg-dev/review-app-api.git", "author": "Piyush Garg ", "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", + "deploy:prod": "dotenv -c production -- sh scripts/deploy.sh production" }, "devDependencies": { "@types/jsonwebtoken": "^9.0.2", diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9e9b2ed..5360d08 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 { diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..c5e5077 --- /dev/null +++ b/scripts/deploy.sh @@ -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 diff --git a/serverless.yml b/serverless.yml index 6694be0..79e86fa 100644 --- a/serverless.yml +++ b/serverless.yml @@ -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}