Browse Source

updated

master
krish 10 months ago
parent
commit
e452723e0f
26 changed files with 7144 additions and 4367 deletions
  1. +3
    -0
      .dockerignore
  2. +9
    -0
      .env.development
  3. +9
    -0
      .env.production
  4. +1
    -0
      .eslintrc.js
  5. +22
    -1
      .gitignore
  6. +13
    -0
      Dockerfile
  7. +1
    -1
      README.md
  8. +29
    -0
      docker-compose.dev.yml
  9. +30
    -0
      docker-compose.prod.yml
  10. +5
    -1
      nest-cli.json
  11. +6889
    -4327
      package-lock.json
  12. +30
    -31
      package.json
  13. +2
    -4
      src/app.module.ts
  14. +18
    -0
      src/auth/auth.controller.spec.ts
  15. +4
    -0
      src/auth/auth.controller.ts
  16. +9
    -0
      src/auth/auth.module.ts
  17. +18
    -0
      src/auth/auth.service.spec.ts
  18. +4
    -0
      src/auth/auth.service.ts
  19. +4
    -0
      src/auth/dto/auth.dto.ts
  20. +13
    -0
      src/auth/strategies/accessToken.strategy.ts
  21. +13
    -0
      src/auth/strategies/refreshToken.strategy.ts
  22. +7
    -0
      src/common/constants/main.ts
  23. +5
    -0
      src/common/guards/accessToken.guard.ts
  24. +5
    -0
      src/common/guards/refreshToken.guard.ts
  25. +0
    -1
      src/main.ts
  26. +1
    -1
      tsconfig.json

+ 3
- 0
.dockerignore View File

@ -0,0 +1,3 @@
node_modules
combined.log
error.log

+ 9
- 0
.env.development View File

@ -0,0 +1,9 @@
JWT_SECRET=sajdhgjhasdhgads
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USERNAME=krish@sentientgeeks.com
EMAIL_PASSWORD=123456
PORT=3000
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
JWT_EXPIRATION_MINUTES=300

+ 9
- 0
.env.production View File

@ -0,0 +1,9 @@
JWT_SECRET=sajdhgjhasdhgads
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USERNAME=krish@sentientgeeks.com
EMAIL_PASSWORD=123456
PORT=3000
# MONGO_URI_TESTS=mongodb://localhost:27017/sg-node-express-rest-api
MONGO_URI=mongodb://mongo:27017/sg-node-express-rest-api
JWT_EXPIRATION_MINUTES=300

+ 1
- 0
.eslintrc.js View File

@ -2,6 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
parserOptions: { parserOptions: {
project: 'tsconfig.json', project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module', sourceType: 'module',
}, },
plugins: ['@typescript-eslint/eslint-plugin'], plugins: ['@typescript-eslint/eslint-plugin'],


+ 22
- 1
.gitignore View File

@ -1,6 +1,7 @@
# compiled output # compiled output
/dist /dist
/node_modules /node_modules
/build
# Logs # Logs
logs logs
@ -32,4 +33,24 @@ lerna-debug.log*
!.vscode/settings.json !.vscode/settings.json
!.vscode/tasks.json !.vscode/tasks.json
!.vscode/launch.json !.vscode/launch.json
!.vscode/extensions.json
!.vscode/extensions.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# temp directory
.temp
.tmp
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

+ 13
- 0
Dockerfile View File

@ -0,0 +1,13 @@
FROM node:latest
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "start"]

+ 1
- 1
README.md View File

@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p> </p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456


+ 29
- 0
docker-compose.dev.yml View File

@ -0,0 +1,29 @@
version: '3'
services:
node:
container_name: nodejs-api
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=development
volumes:
- .:/app
depends_on:
- mongo
restart: always
mongo:
container_name: mongodb
image: mongo:latest
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
restart: always
volumes:
mongo_data:

+ 30
- 0
docker-compose.prod.yml View File

@ -0,0 +1,30 @@
version: '3'
services:
node:
container_name: nodejs-api
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
volumes:
- .:/app
depends_on:
- mongo
restart: always
mongo:
container_name: mongodb
image: mongo:latest
ports:
- "27017:27017"
volumes:
- mongo_data:/data/db
restart: always
volumes:
mongo_data:

+ 5
- 1
nest-cli.json View File

@ -1,4 +1,8 @@
{ {
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics", "collection": "@nestjs/schematics",
"sourceRoot": "src"
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
} }

+ 6889
- 4327
package-lock.json
File diff suppressed because it is too large
View File


+ 30
- 31
package.json View File

@ -1,12 +1,11 @@
{ {
"name": "cp-node-backend",
"name": "nest-demo",
"version": "0.0.1", "version": "0.0.1",
"description": "", "description": "",
"author": "", "author": "",
"private": true, "private": true,
"license": "UNLICENSED", "license": "UNLICENSED",
"scripts": { "scripts": {
"prebuild": "rimraf dist",
"build": "nest build", "build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start", "start": "nest start",
@ -21,37 +20,37 @@
"test:e2e": "jest --config ./test/jest-e2e.json" "test:e2e": "jest --config ./test/jest-e2e.json"
}, },
"dependencies": { "dependencies": {
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/mongoose": "^9.0.1",
"@nestjs/platform-express": "^8.0.0",
"mongoose": "^6.0.12",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0"
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/typeorm": "^10.0.2",
"mysql2": "^3.9.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"typeorm": "^0.3.20"
}, },
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^8.0.0",
"@nestjs/schematics": "^8.0.0",
"@nestjs/testing": "^8.0.0",
"@types/express": "^4.17.13",
"@types/jest": "^27.0.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",
"jest": "^27.2.5",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"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"
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [


+ 2
- 4
src/app.module.ts View File

@ -1,12 +1,10 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AppController } from './app.controller'; import { AppController } from './app.controller';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { UserModule } from './user/user.module';
import { SchoolModule } from './school/school.module';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from './auth/auth.module';
@Module({ @Module({
imports: [UserModule, SchoolModule,MongooseModule.forRoot('mongodb://localhost/classpoint')],
imports: [AuthModule],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],
}) })


+ 18
- 0
src/auth/auth.controller.spec.ts View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
describe('AuthController', () => {
let controller: AuthController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AuthController],
}).compile();
controller = module.get<AuthController>(AuthController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

+ 4
- 0
src/auth/auth.controller.ts View File

@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('auth')
export class AuthController {}

+ 9
- 0
src/auth/auth.module.ts View File

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
@Module({
controllers: [AuthController],
providers: [AuthService]
})
export class AuthModule {}

+ 18
- 0
src/auth/auth.service.spec.ts View File

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
describe('AuthService', () => {
let service: AuthService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

+ 4
- 0
src/auth/auth.service.ts View File

@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AuthService {}

+ 4
- 0
src/auth/dto/auth.dto.ts View File

@ -0,0 +1,4 @@
export class AuthDto {
username: string;
password: string;
}

+ 13
- 0
src/auth/strategies/accessToken.strategy.ts View File

@ -0,0 +1,13 @@
@injectable()
export default class AccessTokenStrategy extends PassportStrategy(
Strategy,
'access-token',
) {
constructor(private readonly authService: AuthService) {
super();
}
async validate(payload: any) {
return this.authService.validateAccessToken(payload);
}
}

+ 13
- 0
src/auth/strategies/refreshToken.strategy.ts View File

@ -0,0 +1,13 @@
@injectable()
export default class RefreshTokenStrategy extends PassportStrategy(
Strategy,
'refresh-token',
) {
constructor(private readonly authService: AuthService) {
super();
}
async validate(payload: any) {
return this.authService.validateRefreshToken(payload);
}
}

+ 7
- 0
src/common/constants/main.ts View File

@ -0,0 +1,7 @@
expect const mail = {
from: ' ',
to: ' ',
subject: ' ',
text: ' ',
html: ' ',
};

+ 5
- 0
src/common/guards/accessToken.guard.ts View File

@ -0,0 +1,5 @@
export class AccessToken extends AuthGuard('access-token') {}
function AuthGuard(arg0: string) {
throw new Error("Function not implemented.");
}

+ 5
- 0
src/common/guards/refreshToken.guard.ts View File

@ -0,0 +1,5 @@
export class RefreshTokenGuard extends AuthGuard('refresh-token') {}
function AuthGuard(arg0: string) {
throw new Error("Function not implemented.");
}

+ 0
- 1
src/main.ts View File

@ -3,7 +3,6 @@ import { AppModule } from './app.module';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
app.enableCors(); // Unable cors
await app.listen(3000); await app.listen(3000);
} }
bootstrap(); bootstrap();

+ 1
- 1
tsconfig.json View File

@ -6,7 +6,7 @@
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"target": "es2017",
"target": "ES2021",
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
"baseUrl": "./", "baseUrl": "./",


Loading…
Cancel
Save