Skip to content

Commit e421306

Browse files
authored
Release v2.1.2 (#195)
2 parents b1a83be + 0e56896 commit e421306

19 files changed

+166
-208
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ RUN npm install
1414
# (assuming your app is in the "src" directory of your project)
1515
COPY . .
1616

17+
# Copy the init-db.sh script to the working directory
18+
COPY init-db.sh /app/src/init-db.sh
19+
20+
# Make the init-db.sh script executable
21+
RUN chmod +x /app/src/init-db.sh
1722
# Make port 8080 available to the world outside this container
1823
EXPOSE 8080
1924

2025
# Run the app when the container launches
21-
CMD [ "npm", "start" ]
2226

27+
CMD [ "sh", "init-db.sh"]

README.md

Lines changed: 64 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ We welcome contributions to make ScholarX even better! Feel free to send us a pu
1818

1919
## Prerequisites
2020

21-
Before you can start using this project, make sure you have the following installed on your machine:
21+
Before you can start using this project, make sure you have the following installed on your local machine:
2222

2323
- Node.js (version 18 or later)
2424
- npm (version 9 or later)
25+
- PostgreSQL (version 15 or later)
2526

2627
## Getting Started
2728

29+
### **Project setup walkthrough :- https://youtu.be/1STopJMM2nM**
30+
2831
Follow these steps to get started with the ScholarX backend:
2932

3033
1. Clone this repository to your local machine:
@@ -39,13 +42,13 @@ Follow these steps to get started with the ScholarX backend:
3942
npm install
4043
```
4144

42-
3. Copy the `.env` file:
45+
3. Copy `.env.example` file as `.env`:
4346

4447
```bash
45-
cp .env.example .env
48+
cp .env.example .env #For Linux and macos
4649
```
4750

48-
4. Replace the environment variables in the newly created `.env` file with your configuration.
51+
4. Replace the environment variables in the newly created `.env` file with your configurations.
4952

5053
5. Start the server:
5154

@@ -61,115 +64,28 @@ Follow these steps to get started with the ScholarX backend:
6164

6265
7. Open your web browser and navigate to `http://localhost:${server_port}` to access the running server.
6366

64-
## Docker Setup
65-
66-
If you prefer to use Docker for development, follow these steps:
67-
68-
1. Ensure Docker and Docker Compose are installed on your machine. You can download them from here https://www.docker.com/products/docker-desktop/.
69-
70-
2. Build the Docker images:
71-
72-
`docker-compose build`
73-
74-
3. Start the Docker containers:
75-
76-
`docker-compose up`
77-
78-
4. The application and its services are now running in Docker containers. You can access the application at `http://localhost:${SERVER_PORT}`, where `SERVER_PORT` is the port number specified in your `.env` file.
79-
80-
5. To stop the Docker containers, use the following commnd:
81-
82-
`docker-compose down`
83-
84-
Please note that the Docker Compose setup assumes that you have a `.env` file in your project root. You can create one by copying the `.env.example` file:
85-
86-
`cp .env.example .env`
87-
88-
Then, replace the environment variables in the newly created `.env` file with your configuration.
89-
90-
The environment directive sets environment variables inside the Docker container. These variables are used to configure the PostgreSQL server. The values for `${DB_USER}`, `${DB_PASSWORD}`, and `${DB_NAME}` should be specified in your .env file.
91-
92-
Remember to replace `${SERVER_PORT}` with the actual port number if it's a fixed value. If it's specified in the `.env` file, you can leave it as is.
93-
94-
In the `docker-compose.yml` file, we also have a `db` service for the PostgreSQL database:
67+
Docker Setup (optional)
68+
-------------------------------------
9569

96-
```dockercompose
97-
db:
98-
image: postgres:15
99-
ports:
100-
- "5432:5432"
101-
environment:
102-
- POSTGRES_USER=${DB_USER}
103-
- POSTGRES_PASSWORD=${DB_PASSWORD}
104-
- POSTGRES_DB=${DB_NAME}
105-
```
106-
107-
This service uses the official postgres:15 Docker image. The ports directive maps port 5432 inside the Docker container to port 5432 on your host machine, allowing you to connect to the PostgreSQL server at `localhost:5432`.
108-
109-
Now, you can connect to the PostgreSQL server running inside the Docker container using a database client. Use `localhost:5432` as the server address, and the `${DB_USER}`, `${DB_PASSWORD}`, and `${DB_NAME}` values from your `.env` file for the username, password, and database name, respectively.
110-
111-
### Note
70+
Alternatively you can use Docker to run ScholarX. Follow these setps:
11271

113-
If you have a local PostgreSQL server running on port 5432, you will need to stop it before starting the Docker container, or change the port mapping to avoid a conflict.
72+
1. Ensure you have Docker and Docker Compose installed on you machine.
11473

115-
Remember to replace `${SERVER_PORT}` with the actual port number if it's a fixed value. If it's specified in the `.env` file, you can leave it as is.
116-
117-
---
118-
119-
#### Code Quality
120-
121-
We strive to maintain a high code quality. You can check for linting issues by running:
74+
2. Build and run the Docker containers.
12275

12376
```bash
124-
npm run lint
77+
docker compose up --build
12578
```
79+
3. The application will be available at `http://localhost:${server_port}`.
12680

127-
And to automatically format the code, use:
81+
4. To stop the containers, run:
12882

12983
```bash
130-
npm run format
84+
docker compose down
13185
```
13286

133-
## Project Structure
134-
135-
Here's an overview of the project structure:
136-
137-
```
138-
scholarx-backend/
139-
├── src/
140-
│ ├── controllers/
141-
│ │ └── index.ts
142-
│ ├── middleware/
143-
│ │ └── index.ts
144-
│ ├── routes/
145-
│ │ └── index.ts
146-
│ ├── services/
147-
│ │ └── auth.service.ts
148-
│ ├── entities/
149-
│ │ └── profile.entity.ts
150-
│ ├── index.ts
151-
│ └── types.ts
152-
├── .env.example
153-
├── .gitignore
154-
├── package.json
155-
├── tsconfig.json
156-
└── README.md
157-
```
158-
159-
- `src/controllers/`: Contains the controller classes that handle incoming requests.
160-
- `src/middleware/`: Contains the middleware functions used to modify requests and responses.
161-
- `src/routes/`: Contains the route definitions for the application.
162-
- `src/services/`: Contains the service definitions for the application.
163-
- `src/entities/`: Contains the entity models for the application.
164-
- `src/index.ts`: Creates and configures the Express application and starts the server.
165-
- `src/types.ts`: Defines custom types for the application.
166-
- `.env.example`: An example configuration file for environment variables.
167-
- `.gitignore`: A list of files and directories to be ignored by Git.
168-
- `package.json`: Contains information about the project and its dependencies.
169-
- `tsconfig.json`: Configuration file for the TypeScript compiler.
170-
171-
Database Configuration and Migration
172-
------------------------------------
87+
Database Configuration and Migrations
88+
-------------------------------------
17389

17490
### Setting up the Database
17591

@@ -180,8 +96,6 @@ Database Configuration and Migration
18096
```bash
18197
CREATE DATABASE scholarx;
18298
```
183-
184-
18599
3. Update your `.env` file with your database configuration:
186100

187101
```bash
@@ -191,48 +105,21 @@ Database Configuration and Migration
191105
DB_PASSWORD=your_db_password
192106
DB_NAME=scholarx
193107
```
108+
4. Synchronize the database schema:
194109

195-
### Running Migrations and Seeding the Database
196-
197-
#### Migration Commands
198-
199-
1. **Generate a new migration**:
200-
201-
202110
```bash
203-
npm run migration:generate -- -n MigrationName
204-
```
205-
206-
This command generates a new migration file with the specified name.
207-
208-
2. **Run migrations**:
209-
210-
211-
```bash
212-
npm run migration:run
213-
```
214-
215-
This command runs all pending migrations.
216-
217-
3. **Synchronize the database schema**:
218-
219-
220-
```bash
221111
npm run sync:db
222112
```
113+
This command synchronizes your database schema with the current state of the entities on your project.
223114

224-
This command synchronizes your database schema with the current state of your entities.
225-
226-
4. **Seed the database**:
115+
4. Seed the database
227116

228-
229117
```bash
230118
npm run seed
231119
```
232-
233120
This command builds the project and runs the database seeding script located in `dist/src/scripts/seed-db.js`.
234121

235-
### Example Migration and Seeding Commands
122+
### Example Migration Commands
236123

237124
- To generate a new migration named `AddUserTable`:
238125

@@ -248,18 +135,15 @@ Database Configuration and Migration
248135
npm run migration:run
249136
```
250137

251-
- To synchronize the database schema:
252-
253-
```bash
254-
npm run sync:db
255-
```
138+
## Setting up SMTP
256139

257-
- To seed the database:
140+
To enable Email functionality in this project, follow these steps:
258141

259-
260-
```bash
261-
npm run seed
262-
```
142+
1. Go to your Google Account. (Make sure to enable 2-step verification)
143+
2. Go to App Passwords section.
144+
3. Provide the app name as "scholarx" and click create.
145+
4. Copy the given password and paste it without spaces for SMTP_PASSWORD property in .env file.
146+
5. Enter your email for SMTP_EMAIL property in .env file.
263147

264148
## Setting up Google Authentication
265149

@@ -367,10 +251,40 @@ We appreciate your interest in ScholarX. Happy contributing! If you have any que
367251
368252
8. Verify it from your account.
369253
370-
## Create dummy data
254+
## Project Structure
371255
372-
1. Run the seeding script:
256+
Here's an overview of the project structure:
373257
374-
```bash
375-
npm run seed
376-
```
258+
```
259+
scholarx-backend/
260+
├── src/
261+
│ ├── controllers/
262+
│ │ └── index.ts
263+
│ ├── middleware/
264+
│ │ └── index.ts
265+
│ ├── routes/
266+
│ │ └── index.ts
267+
│ ├── services/
268+
│ │ └── auth.service.ts
269+
│ ├── entities/
270+
│ │ └── profile.entity.ts
271+
│ ├── index.ts
272+
│ └── types.ts
273+
├── .env.example
274+
├── .gitignore
275+
├── package.json
276+
├── tsconfig.json
277+
└── README.md
278+
```
279+
280+
- `src/controllers/`: Contains the controller classes that handle incoming requests.
281+
- `src/middleware/`: Contains the middleware functions used to modify requests and responses.
282+
- `src/routes/`: Contains the route definitions for the application.
283+
- `src/services/`: Contains the service definitions for the application.
284+
- `src/entities/`: Contains the entity models for the application.
285+
- `src/index.ts`: Creates and configures the Express application and starts the server.
286+
- `src/types.ts`: Defines custom types for the application.
287+
- `.env.example`: An example configuration file for environment variables.
288+
- `.gitignore`: A list of files and directories to be ignored by Git.
289+
- `package.json`: Contains information about the project and its dependencies.
290+
- `tsconfig.json`: Configuration file for the TypeScript compiler.

docker-compose.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@ services:
77
depends_on:
88
- db
99
environment:
10-
- DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
10+
- DB_HOST=db
11+
- DB_PORT=5432
12+
- DB_USER=${DB_USER}
13+
- DB_PASSWORD=${DB_PASSWORD}
14+
- DB_NAME=${DB_NAME}
1115
- JWT_SECRET=${JWT_SECRET}
16+
- GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID}
17+
- GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET}
18+
- GOOGLE_REDIRECT_URL=${GOOGLE_REDIRECT_URL}
19+
- LINKEDIN_CLIENT_ID=${LINKEDIN_CLIENT_ID}
20+
- LINKEDIN_CLIENT_SECRET=${LINKEDIN_CLIENT_SECRET}
21+
- LINKEDIN_REDIRECT_URL=${LINKEDIN_REDIRECT_URL}
22+
- CLIENT_URL=${CLIENT_URL}
23+
- IMG_HOST=${IMG_HOST}
24+
- SMTP_MAIL=${SMTP_MAIL}
25+
- SMTP_PASSWORD=${SMTP_PASSWORD}
26+
command: ["sh", "/app/src/init-db.sh"]
1227
db:
13-
1428
image: postgres:15
1529
ports:
1630
- "5432:5432"
17-
1831
environment:
1932
- POSTGRES_USER=${DB_USER}
2033
- POSTGRES_PASSWORD=${DB_PASSWORD}
21-
- POSTGRES_DB=${DB_NAME}
22-
34+
- POSTGRES_DB=${DB_NAME}

init-db.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This is a script to initialize the database for the first time when the container is started.
2+
# It will wait for the database to be ready before running the migrations.
3+
# Wait for the
4+
5+
echo "Database is ready. Running migrations..."
6+
7+
# Run the migrations
8+
npm run sync:db
9+
npm run seed
10+
11+
echo "Migrations complete. Database is ready."
12+
13+
# Start the application
14+
15+
npm run dev

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"migration:run": "npm run typeorm:db -- migration:run",
1818
"migration:revert": "npm run typeorm:db -- migration:revert",
1919
"sync:db": "npm run typeorm:db schema:sync",
20-
"seed": "npm run build && node dist/src/scripts/seed-db.js"
20+
"seed": "npx ts-node src/scripts/seed-db.ts"
2121
},
2222
"author": "",
2323
"license": "ISC",

src/configs/envConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const GOOGLE_REDIRECT_URL = process.env.GOOGLE_REDIRECT_URL ?? ''
1515
export const CLIENT_URL = process.env.CLIENT_URL ?? ''
1616
export const IMG_HOST = process.env.IMG_HOST ?? ''
1717
export const SMTP_MAIL = process.env.SMTP_MAIL ?? ''
18-
export const SMTP_PASS = process.env.SMTP_PASS ?? ''
18+
export const SMTP_PASSWORD = process.env.SMTP_PASSWORD ?? ''
1919
export const LINKEDIN_CLIENT_ID = process.env.LINKEDIN_CLIENT_ID ?? ''
2020
export const LINKEDIN_CLIENT_SECRET = process.env.LINKEDIN_CLIENT_SECRET ?? ''
2121
export const LINKEDIN_REDIRECT_URL = process.env.LINKEDIN_REDIRECT_URL ?? ''

src/controllers/monthlyChecking.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ export const postMonthlyCheckIn = async (
1515
try {
1616
const {
1717
menteeId,
18-
title,
18+
month,
1919
generalUpdatesAndFeedback,
2020
progressTowardsGoals,
2121
mediaContentLinks
2222
} = req.body
2323

2424
const newCheckIn = await addMonthlyCheckInByMentee(
2525
menteeId,
26-
title,
26+
month,
2727
generalUpdatesAndFeedback,
2828
progressTowardsGoals,
2929
mediaContentLinks

0 commit comments

Comments
 (0)