-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
6,601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# postgres | ||
# DATABASE_URL="postgresql://dwbkuveecopvik:5601d237f2967441aacc1186d7e21d863fc87a26cca4f92ab119e3c01a45d8de@ec2-52-54-212-232.compute-1.amazonaws.com:5432/d6q4glcl90m0pk" | ||
DATABASE_URL="postgresql://donaldwu:@localhost:5432/donaldwu" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# postgres | ||
DATABASE_URL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn run lint && yarn run prisma:format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: yarn run production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# dummy-api | ||
|
||
dummy-api | ||
|
||
documentation: <> | ||
|
||
api url: <> | ||
|
||
## Requirement | ||
|
||
- install yarn | ||
- install node (v14+) | ||
|
||
## Testing and run | ||
|
||
```zsh | ||
// test api in local | ||
$ yarn run start:dev | ||
|
||
// run in production | ||
$ yarn run production | ||
|
||
// lint code | ||
$ yarn run lint | ||
|
||
// format code | ||
$ yarn run format | ||
|
||
// run test case | ||
$ yarn run test | ||
|
||
// generate schema.prisma and prisma client | ||
$ yarn run prisma:generate | ||
|
||
// create migration file if schema.prisma changed | ||
$ yarn run prisma:migrate:dev | ||
|
||
// reset database | ||
$ yarn run prisma:migrate:reset | ||
|
||
// apply pending migrations in the production/staging database | ||
$ yarn run prisma:migrate:deploy | ||
|
||
// check migrations status in the production/staging database | ||
$ yarn run prisma:migrate:status | ||
|
||
// push schema.prisma state to database | ||
$ yarn run prisma:db:push | ||
|
||
// seed data to database | ||
$ yarn run prisma:db:seed | ||
|
||
// format schema.prisma | ||
$ yarn run prisma:format | ||
|
||
// open prisma studio | ||
$ yarn run prisma:studio | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
"name": "dummy-api", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
"repository": "https://github.com/yeukfei02/dummy-api.git", | ||
"author": "Donald Wu <yeukfei02@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@nestjs/common": "^8.0.0", | ||
"@nestjs/core": "^8.0.0", | ||
"@nestjs/platform-express": "^8.0.0", | ||
"@prisma/client": "^3.12.0", | ||
"compression": "^1.7.4", | ||
"dayjs": "^1.11.1", | ||
"helmet": "^5.0.2", | ||
"reflect-metadata": "^0.1.13", | ||
"rimraf": "^3.0.2", | ||
"rxjs": "^7.2.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^8.0.0", | ||
"@nestjs/schematics": "^8.0.0", | ||
"@nestjs/testing": "^8.0.0", | ||
"@types/compression": "^1.7.2", | ||
"@types/express": "^4.17.13", | ||
"@types/helmet": "^4.0.0", | ||
"@types/jest": "27.4.1", | ||
"@types/node": "^16.0.0", | ||
"@types/supertest": "^2.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.0.0", | ||
"@typescript-eslint/parser": "^5.0.0", | ||
"eslint": "^8.0.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"git-cz": "^4.8.0", | ||
"husky": "^7.0.0", | ||
"jest": "^27.2.5", | ||
"prettier": "^2.3.2", | ||
"prisma": "^3.12.0", | ||
"source-map-support": "^0.5.20", | ||
"standard-version": "^9.3.2", | ||
"supertest": "^6.1.3", | ||
"ts-jest": "^27.0.3", | ||
"ts-loader": "^9.2.3", | ||
"ts-node": "^10.0.0", | ||
"tsconfig-paths": "^3.10.1", | ||
"typescript": "^4.3.5" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*\\.spec\\.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
}, | ||
"scripts": { | ||
"prebuild": "rimraf dist", | ||
"build": "nest build", | ||
"heroku-postbuild": "yarn run build", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/src/main", | ||
"production": "yarn run build && yarn run start:prod", | ||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", | ||
"test:e2e": "jest --config ./test/jest-e2e.json", | ||
"prisma:generate": "npx prisma db pull && npx prisma generate", | ||
"prisma:migrate:dev": "npx prisma migrate dev", | ||
"prisma:migrate:reset": "npx prisma migrate reset", | ||
"prisma:migrate:deploy": "npx prisma migrate deploy", | ||
"prisma:migrate:status": "npx prisma migrate status", | ||
"prisma:db:push": "npx prisma db push", | ||
"prisma:db:seed": "npx prisma db seed", | ||
"prisma:format": "npx prisma format", | ||
"prisma:studio": "npx prisma studio", | ||
"commit": "git-cz", | ||
"release": "standard-version", | ||
"prepare": "husky install" | ||
}, | ||
"prisma": { | ||
"seed": "ts-node ./prisma/seed.ts" | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
prisma/migrations/20220420080908_create_users_and_location/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
-- CreateEnum | ||
CREATE TYPE "Title" AS ENUM ('mr', 'ms', 'mrs', 'miss', 'dr'); | ||
|
||
-- CreateEnum | ||
CREATE TYPE "Gender" AS ENUM ('male', 'female', 'other'); | ||
|
||
-- CreateTable | ||
CREATE TABLE "users" ( | ||
"id" UUID NOT NULL, | ||
"title" "Title" NOT NULL, | ||
"first_name" VARCHAR(50), | ||
"last_name" VARCHAR(50), | ||
"gender" "Gender" NOT NULL, | ||
"email" TEXT, | ||
"date_of_birth" TIMESTAMP(3), | ||
"register_date" TIMESTAMP(3), | ||
"phone" TEXT, | ||
"picture" TEXT, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "users_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "location" ( | ||
"id" UUID NOT NULL, | ||
"street" VARCHAR(100) NOT NULL, | ||
"city" VARCHAR(30) NOT NULL, | ||
"state" VARCHAR(30) NOT NULL, | ||
"country" VARCHAR(30) NOT NULL, | ||
"timezone" VARCHAR(30) NOT NULL, | ||
"users_id" UUID NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "location_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_created_at" ON "users"("created_at"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_date_of_birth" ON "users"("date_of_birth"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_email" ON "users"("email"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_first_name" ON "users"("first_name"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_gender" ON "users"("gender"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_last_name" ON "users"("last_name"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_phone" ON "users"("phone"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_picture" ON "users"("picture"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_register_date" ON "users"("register_date"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_title" ON "users"("title"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_users_on_updated_at" ON "users"("updated_at"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_street" ON "location"("street"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_city" ON "location"("city"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_state" ON "location"("state"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_country" ON "location"("country"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_timezone" ON "location"("timezone"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_created_at" ON "location"("created_at"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "index_location_on_updated_at" ON "location"("updated_at"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "location" ADD CONSTRAINT "location_users_id_fkey" FOREIGN KEY ("users_id") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
Oops, something went wrong.