Skip to content

Commit 300e0f8

Browse files
committed
Initial structure
1 parent 1b21577 commit 300e0f8

17 files changed

+5271
-96
lines changed

.eslintrc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
sourceType: 'module',
6+
},
7+
plugins: ['@typescript-eslint/eslint-plugin'],
8+
extends: [
9+
'plugin:@typescript-eslint/recommended',
10+
'plugin:prettier/recommended',
11+
],
12+
root: true,
13+
env: {
14+
node: true,
15+
jest: true,
16+
},
17+
ignorePatterns: ['.eslintrc.js'],
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/explicit-module-boundary-types': 'off',
22+
'@typescript-eslint/no-explicit-any': 'off',
23+
},
24+
};

.gitignore

Lines changed: 27 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,35 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
15
# Logs
26
logs
37
*.log
48
npm-debug.log*
9+
pnpm-debug.log*
510
yarn-debug.log*
611
yarn-error.log*
712
lerna-debug.log*
813

9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
72-
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
14+
# OS
15+
.DS_Store
16+
17+
# Tests
18+
/coverage
19+
/.nyc_output
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all"
4+
}

nest-cli.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"collection": "@nestjs/schematicsgs",
3+
"sourceRoot": "src"
4+
}

package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "nestjs-rest-api",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"prebuild": "rimraf dist",
10+
"build": "nest build",
11+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
12+
"start": "nest start",
13+
"start:dev": "nest start --watch",
14+
"start:debug": "nest start --debug --watch",
15+
"start:prod": "node dist/main",
16+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17+
"test": "jest",
18+
"test:watch": "jest --watch",
19+
"test:cov": "jest --coverage",
20+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
21+
"test:e2e": "jest --config ./test/jest-e2e.json"
22+
},
23+
"dependencies": {
24+
"@nestjs/common": "^8.0.0",
25+
"@nestjs/core": "^8.0.0",
26+
"@nestjs/platform-express": "^8.0.0",
27+
"reflect-metadata": "^0.1.13",
28+
"rimraf": "^3.0.2",
29+
"rxjs": "^7.2.0"
30+
},
31+
"devDependencies": {
32+
"@nestjs/cli": "^8.0.0",
33+
"@nestjs/schematics": "^8.0.0",
34+
"@nestjs/testing": "^8.0.0",
35+
"@types/express": "^4.17.13",
36+
"@types/jest": "^27.0.1",
37+
"@types/node": "^16.0.0",
38+
"@types/supertest": "^2.0.11",
39+
"@typescript-eslint/eslint-plugin": "^5.0.0",
40+
"@typescript-eslint/parser": "^5.0.0",
41+
"eslint": "^8.0.1",
42+
"eslint-config-prettier": "^8.3.0",
43+
"eslint-plugin-prettier": "^4.0.0",
44+
"jest": "^27.2.5",
45+
"prettier": "^2.3.2",
46+
"source-map-support": "^0.5.20",
47+
"supertest": "^6.1.3",
48+
"ts-jest": "^27.0.3",
49+
"ts-loader": "^9.2.3",
50+
"ts-node": "^10.0.0",
51+
"tsconfig-paths": "^3.10.1",
52+
"typescript": "^4.3.5"
53+
},
54+
"jest": {
55+
"moduleFileExtensions": [
56+
"js",
57+
"json",
58+
"ts"
59+
],
60+
"rootDir": "src",
61+
"testRegex": ".*\\.spec\\.ts$",
62+
"transform": {
63+
"^.+\\.(t|j)s$": "ts-jest"
64+
},
65+
"collectCoverageFrom": [
66+
"**/*.(t|j)s"
67+
],
68+
"coverageDirectory": "../coverage",
69+
"testEnvironment": "node"
70+
}
71+
}

src/app.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { CartsModule } from './handlers/carts/carts.module';
3+
4+
@Module({
5+
imports: [CartsModule],
6+
controllers: [],
7+
providers: [],
8+
})
9+
export class AppModule {}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
2+
import { CartsService } from './carts.service';
3+
import { CreateCartDto } from './dto/create-cart.dto';
4+
import { UpdateCartDto } from './dto/update-cart.dto';
5+
6+
@Controller('carts')
7+
export class CartsController {
8+
constructor(private readonly cartsService: CartsService) {}
9+
10+
@Post()
11+
create(@Body() createCartDto: CreateCartDto) {
12+
return this.cartsService.create(createCartDto);
13+
}
14+
15+
@Get()
16+
findAll() {
17+
return this.cartsService.findAll();
18+
}
19+
20+
@Get(':id')
21+
findOne(@Param('id') id: string) {
22+
return this.cartsService.findOne(+id);
23+
}
24+
25+
@Patch(':id')
26+
update(@Param('id') id: string, @Body() updateCartDto: UpdateCartDto) {
27+
return this.cartsService.update(+id, updateCartDto);
28+
}
29+
30+
@Delete(':id')
31+
remove(@Param('id') id: string) {
32+
return this.cartsService.remove(+id);
33+
}
34+
}

src/handlers/carts/carts.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Module } from '@nestjs/common';
2+
import { CartsService } from './carts.service';
3+
import { CartsController } from './carts.controller';
4+
5+
@Module({
6+
controllers: [CartsController],
7+
providers: [CartsService]
8+
})
9+
export class CartsModule {}

src/handlers/carts/carts.service.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { CreateCartDto } from './dto/create-cart.dto';
3+
import { UpdateCartDto } from './dto/update-cart.dto';
4+
5+
@Injectable()
6+
export class CartsService {
7+
create(createCartDto: CreateCartDto) {
8+
return 'This action adds a new cart';
9+
}
10+
11+
findAll() {
12+
return `This action returns all carts`;
13+
}
14+
15+
findOne(id: number) {
16+
return `This action returns a #${id} cart`;
17+
}
18+
19+
update(id: number, updateCartDto: UpdateCartDto) {
20+
return `This action updates a #${id} cart`;
21+
}
22+
23+
remove(id: number) {
24+
return `This action removes a #${id} cart`;
25+
}
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class CreateCartDto {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { PartialType } from '@nestjs/mapped-types';
2+
import { CreateCartDto } from './create-cart.dto';
3+
4+
export class UpdateCartDto extends PartialType(CreateCartDto) {}

src/main.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NestFactory } from '@nestjs/core';
2+
import { AppModule } from './app.module';
3+
4+
async function bootstrap() {
5+
const app = await NestFactory.create(AppModule);
6+
await app.listen(3000);
7+
}
8+
bootstrap();

test/app.e2e-spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { INestApplication } from '@nestjs/common';
3+
import * as request from 'supertest';
4+
import { AppModule } from './../src/app.module';
5+
6+
describe('AppController (e2e)', () => {
7+
let app: INestApplication;
8+
9+
beforeEach(async () => {
10+
const moduleFixture: TestingModule = await Test.createTestingModule({
11+
imports: [AppModule],
12+
}).compile();
13+
14+
app = moduleFixture.createNestApplication();
15+
await app.init();
16+
});
17+
18+
it('/ (GET)', () => {
19+
return request(app.getHttpServer())
20+
.get('/')
21+
.expect(200)
22+
.expect('Hello World!');
23+
});
24+
});

test/jest-e2e.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"moduleFileExtensions": ["js", "json", "ts"],
3+
"rootDir": ".",
4+
"testEnvironment": "node",
5+
"testRegex": ".e2e-spec.ts$",
6+
"transform": {
7+
"^.+\\.(t|j)s$": "ts-jest"
8+
}
9+
}

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4+
}

0 commit comments

Comments
 (0)