Skip to content

Commit

Permalink
refacor + update folder
Browse files Browse the repository at this point in the history
  • Loading branch information
milon27 committed Dec 2, 2024
1 parent 738635b commit 36c73f1
Show file tree
Hide file tree
Showing 51 changed files with 158 additions and 125 deletions.
4 changes: 3 additions & 1 deletion .doc/doc.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# write postman link
# write postman link

https://m27lab.postman.co/workspace/M27LAB~849f4e55-931f-4f55-96d9-fad5e24d1590/collection/12238877-777ce19b-5ed0-4a9d-ada9-74506e32d70e?action=share&source=copy-link&creator=12238877&active-environment=fed60369-7ea2-443c-b309-5a013b681d7d
3 changes: 3 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ TZ=Etc/UTC
DATABASE_URL="mysql://root:myPassWord@localhost:3308/test" # test, test

# redis
# with ssl
# REDIS_URL="rediss://default:[email protected]:6379"
# without ssl
REDIS_URL="redis://default:1234567@localhost:6379"
# redis cluster (not used)
REDIS_CLUSTER_ENABLE='false'
Expand Down
3 changes: 3 additions & 0 deletions .env.prod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ TZ=Etc/UTC
DATABASE_URL="mysql://root:myPassWord@localhost:3308/test" # test, test

# redis
# with ssl
# REDIS_URL="rediss://default:[email protected]:6379"
# without ssl
REDIS_URL="redis://default:1234567@localhost:6379"
# redis cluster (not used)
REDIS_CLUSTER_ENABLE='false'
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18.13.0-alpine as build
FROM node:20.18.0-alpine as build
RUN npm install -g pnpm

WORKDIR /app
Expand All @@ -14,7 +14,7 @@ RUN npm run build

# # ------------------dev -------------------

FROM node:18.13.0-alpine as dev
FROM node:20.18.0-alpine as dev
RUN npm install -g pnpm

WORKDIR /app
Expand All @@ -36,7 +36,7 @@ CMD ["/bin/sh", "-c", "pnpm db:migrate:prod && pnpm db:seed:prod && node dist/sr

# # ------------------prod -------------------

FROM node:18.13.0-alpine as prod
FROM node:20.18.0-alpine as prod
RUN npm install -g pnpm

WORKDIR /app
Expand Down
15 changes: 0 additions & 15 deletions docker-compose.dev.yml

This file was deleted.

38 changes: 38 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
services:
mysql:
container_name: mysql
image: mysql:8.0.33
restart: always
environment:
- MYSQL_ROOT_PASSWORD=myPassWord
- MYSQL_DATABASE=test
ports:
- 3308:3306
volumes:
- db_vol:/var/lib/mysql
# - .backup-db:/docker-entrypoint-initdb.d

redis:
container_name: redis
image: redis:7.4.1-alpine
restart: always
volumes:
- redis_vol:/data
environment:
- REDIS_PASSWORD=1234567
ports:
- 6379:6379

api:
container_name: api
build:
context: .
dockerfile: Dockerfile
target: prod
restart: always
ports:
- 4000:4000

volumes:
db_vol:
redis_vol:
11 changes: 0 additions & 11 deletions docker-compose.prod.yml

This file was deleted.

30 changes: 14 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
version: "3.9"
services:
mysql:
container_name: mysql
image: mysql:8.0.33
restart: always
environment:
- MYSQL_ROOT_PASSWORD=myPassWord
- MYSQL_DATABASE=test
ports:
- 3308:3306
volumes:
- db_vol:/var/lib/mysql
# - .backup-db:/docker-entrypoint-initdb.d
redis:
container_name: redis
image: redis:7.0.7-alpine
image: redis:7.4.1-alpine
restart: always
volumes:
- redis_vol:/data
Expand All @@ -23,6 +10,17 @@ services:
ports:
- 6379:6379

nginx_proxy:
container_name: nginx_proxy
image: "jc21/nginx-proxy-manager:latest"
restart: unless-stopped
ports:
- "80:80"
- "81:81"
- "443:443"
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt

volumes:
db_vol: {}
redis_vol: {}
redis_vol:
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build": "tsc --outDir dist",
"lint": "npx eslint . --fix",
"lint:check": "npx eslint .",
"test": "cross-env NODE_ENV=test npm run db:clean && cross-env NODE_ENV=test npm run db:seed && cross-env NODE_ENV=test vitest --config ./vitest.config.mjs",
"test": "cross-env NODE_ENV=test npm run db:migrate && cross-env NODE_ENV=test npm run db:clean && cross-env NODE_ENV=test npm run db:seed && cross-env NODE_ENV=test vitest --config ./vitest.config.mjs",
"dbml:generate": "ts-node src/config/db/utils/dbml.ts",
"db:generate": "drizzle-kit generate:mysql",
"db:rollback": "drizzle-kit drop --config=drizzle.config.ts",
"db:migrate": "ts-node --files src/config/db/utils/migrator.ts",
Expand All @@ -21,8 +22,7 @@
"db:all:clean": "pnpm db:clean && pnpm redis:clean && pnpm db:seed",
"np": "nestpress ",
"version:inc": "npm version patch --no-git-tag-version && git add .",
"all:update": "pnpm update -i -L",
"prepare": "husky install"
"all:update": "pnpm update -i -L"
},
"keywords": [
"express",
Expand Down Expand Up @@ -71,6 +71,7 @@
"@typescript-eslint/parser": "7.1.0",
"cross-env": "7.0.3",
"drizzle-kit": "0.20.14",
"drizzle-dbml-generator": "0.9.0",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-airbnb-typescript": "18.0.0",
Expand Down
24 changes: 11 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npx nestpress@latest module category blog
```bash

pnpm i
# rename .env.dev (if available) to .env then update db connection string (DATABASE_URL) and other env variable if needed
# rename .env.dev to .env then update db connection string (DATABASE_URL) and other env variable if needed
pnpm: db:migrate

# reload / reopen vscode to restart TS server
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/auth/logged-in-user.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import supertest from "supertest"
import { afterAll, beforeAll, describe, expect, it } from "vitest"
import app from "../../app"
import { StatusCode } from "../../config/constant/code.constant"
import { StatusCode } from "../../constant/code.constant"
import { TestUtil } from "../test.util"

describe("logged in user 👤", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/__test__/auth/login.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import supertest from "supertest"
import { afterAll, beforeAll, describe, expect, it } from "vitest"
import app from "../../app"
import { StatusCode } from "../../config/constant/code.constant"
import { Constant } from "../../config/constant/common.constant"
import { StatusCode } from "../../constant/code.constant"
import { CommonConstant } from "../../constant/common.constant"
import { createUserPayload } from "../data"
import { TestUtil } from "../test.util"

Expand Down Expand Up @@ -44,7 +44,7 @@ describe("login 🎇", () => {
it("given admin credentials", async () => {
const { statusCode, body } = await supertest(app).post("/v1/auth/login-with-email").send({
email: createUserPayload.user.email,
password: Constant.DEFAULT_ADMIN_PASSWORD,
password: CommonConstant.DEFAULT_ADMIN_PASSWORD,
})
expect(statusCode).toBe(StatusCode.OK)
expect(body.response.accessToken).toBeDefined()
Expand Down
4 changes: 2 additions & 2 deletions src/__test__/auth/logout.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import supertest from "supertest"
import { afterAll, beforeAll, describe, expect, it } from "vitest"
import app from "../../app"
import { StatusCode } from "../../config/constant/code.constant"
import { KeyConstant } from "../../config/constant/key.constant"
import { StatusCode } from "../../constant/code.constant"
import { KeyConstant } from "../../constant/key.constant"
import { TestUtil } from "../test.util"

// login -> login normal, login invalid, login as admin
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/auth/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import supertest from "supertest"
import { afterAll, beforeAll, describe, expect, it } from "vitest"
import app from "../../app"
import { ErrorCode, StatusCode } from "../../config/constant/code.constant"
import { ErrorCode, StatusCode } from "../../constant/code.constant"
import { createUserPayload } from "../data"
import { TestUtil } from "../test.util"

Expand Down
4 changes: 2 additions & 2 deletions src/__test__/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Constant } from "../config/constant/common.constant"
import { CommonConstant } from "../constant/common.constant"
import { ILoginWithEmailDto } from "../feature/auth/login-register/dto/login.dto"
import { IRegisterDto, RegisterProvider } from "../feature/auth/login-register/dto/register.dto"

Expand All @@ -12,6 +12,6 @@ export const createUserPayload: IRegisterDto = {
user: {
...loginUserPayload,
fullName: "test",
timeZone: Constant.TIMEZONE,
timeZone: CommonConstant.TIMEZONE,
},
}
2 changes: 1 addition & 1 deletion src/__test__/test.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/* eslint-disable no-console */
import { sql } from "drizzle-orm"
import { MySqlQueryResult } from "drizzle-orm/mysql2"
import { KeyConstant } from "../config/constant/key.constant"
import { db } from "../config/db/db"
import { KeyConstant } from "../constant/key.constant"
import { UserService } from "../feature/user/user.service"
import { AccessTokenUtil } from "../utils/access-token.util"
import { RedisUtil } from "../utils/redis.util"
Expand Down
Loading

0 comments on commit 36c73f1

Please sign in to comment.