Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Setup and Seed Migration #23

Merged
merged 16 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT=8000
auth-secret=

DB_USER=
DB_HOST=
DB_PASSWORD=
DB_NAME=


6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
port=8000
auth-secret=
DB_USER=
DB_HOST=
DB_PASSWORD=
DB_NAME=
29 changes: 29 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Fixes Issue/Linear Ticket

> This could be an existing issue or a linear ticket
>
> - Github Issue Example: My PR Closes #{ISSUE}
> - Linear Ticket Example: Fixes ID-#{ISSUE}

## Changes proposed

> Talk about the things you did eg. files changes, dependencies installed e.t.c

## Check List (Check all the applicable boxes)

:rotating_light:Please review the [style guide for contributing](add link here) and [guidelines for contributing](add link here) to this repository.

- [ ] My code follows the code style of this project.
- [ ] This PR does not contain plagiarized content.
- [ ] The title and description of the PR is clear and explains the approach.
- [ ] I am making a pull request against the **main branch** (left side).
- [ ] My commit messages styles matches our requested structure.
- [ ] My code additions will fail neither code linting checks nor unit test.
- [ ] I am only making changes to files I was requested to.

## Screenshots/ Videos

<!-- If the changes are static page changes or UI changes add screenshots -->
<!-- If the changes involve implementing a functionality or working with apis, include a video
detailing how to implement the functionality and the request to the api and responses from the api endpoint-->
<!-- Add all the screenshots/videos which support your changes i.e before your change and after your change -->
135 changes: 6 additions & 129 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,130 +1,7 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
.idea/
.vscode/
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
build/
tmp/
temp/
.env
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ For example:
git switch -c add-alonzo-church
```

### Important notice:

```bash
console.log
```

is not allowed

a default logger has been created

```bash
import log from "./utils/logger";

log.info("information")
```

### Make Changes

Make your changes to the codebase. Ensure your code follows the project's coding standards and guidelines.
Expand Down Expand Up @@ -161,23 +177,15 @@ cp .env.example .env

Edit the `.env` file to match your environment configuration.

### 4. Compile TypeScript

Compile the TypeScript code to JavaScript.

```sh
npm run build
```

### 5. Run the Development Server
### 4. Run the Development Server

Start the development server with the following command. This will also watch for any changes in your code and automatically restart the server.

```sh
yarn start:dev
```

### 6. Run the Production Server
### 5. Run the Production Server

To run the application in a production environment, use the following command:

Expand All @@ -195,4 +203,12 @@ All API endpoints can be referenced in the [API Reference](API_REFERENCE.md) doc

## Versioning

This project is versioned to ensure backward compatibility and easy maintenance. The current version is [version].
This project is versioned to ensure backward compatibility and easy maintenance. The current version is [version 1].

## route naming conventions

all routes should have a prefix of

```bash
api/v1
```
14 changes: 14 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Config } from "jest";

const config: Config = {
verbose: true,
preset: "ts-jest",
testEnvironment: "node",
globals: {
"ts-jest": {
tsconfig: "tsconfig.jest.json",
},
},
};

export default config;
64 changes: 40 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
{
"name": "hng_boilerplate_expressjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start:dev": "nodemon --exec ts-node src/index.ts",
"start": "ts-node src/index.ts",
"build": "tsc",
"prod": "node dist/index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.21",
"@types/node": "^20.14.11",
"nodemon": "^3.1.4",
"ts-node": "10.9.1",
"typescript": "^5.5.3"
},
"dependencies": {
"dotenv": "^16.4.5",
"express": "^4.19.2"
}
"name": "hng_boilerplate_expressjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start:dev": "ts-node-dev --respawn --transpile-only ./src/index",
"start": "ts-node src/index.ts",
"test": "jest",
"typeorm": "typeorm-ts-node-commonjs"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^16.11.10",
"@types/supertest": "^6.0.2",
"ts-node": "10.9.1",
"typescript": "4.5.2"
},
"dependencies": {
"@types/bcryptjs": "^2.4.6",
"@types/config": "^3.3.4",
"bcryptjs": "^2.4.3",
"class-validator": "^0.14.1",
"config": "^3.3.12",
"dayjs": "^1.11.12",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"jest": "^29.7.0",
"pg": "^8.4.0",
"pino": "^9.3.1",
"pino-pretty": "^11.2.1",
"reflect-metadata": "^0.1.13",
"supertest": "^7.0.0",
"ts-jest": "^29.2.3",
"ts-node-dev": "^2.0.0",
"typeorm": "0.3.20"
}
}
14 changes: 14 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import dotenv from "dotenv";

dotenv.config();
const config = {
port: process.env.PORT ?? 8000,
"api-prefix": "api/v1",
DB_USER: process.env.DB_USER,
DB_HOST: process.env.DB_HOST,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_PORT: process.env.DB_PORT,
DB_NAME: process.env.DB_NAME,
};

export default config;
32 changes: 32 additions & 0 deletions src/controllers/UserController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// // src/controllers/UserController.ts
import { Request, Response } from "express";

import { User } from "../models";

class UserController {
static async getUser(req: Request, res: Response) {
const user = await User.findOne({
where: { id: req.params.id },
relations: ["profile", "products", "organizations"],
});

if (!user) {
return res.status(404).json({ message: "User not found" });
}

res.json(user);
}
static async getAllUsers(req: Request, res: Response) {
const users = await User.find({
relations: ["profile", "products", "organizations"],
});

res.json(users);
}
}

export default UserController;

{
relations: ["profile", "products", "organizations"];
}
1 change: 1 addition & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// silence is golden
Loading