Skip to content

Commit

Permalink
feat: create nest api folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBuecher committed Dec 30, 2022
1 parent b1a28cd commit c0d1d33
Show file tree
Hide file tree
Showing 12 changed files with 1,626 additions and 16 deletions.
1,505 changes: 1,490 additions & 15 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"devDependencies": {
"@commitlint/cli": "^17.3.0",
"@commitlint/config-angular": "^17.3.0",
"@nestjs/cli": "^9.1.8",
"@nestjs/testing": "^9.2.1",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.18",
Expand Down
7 changes: 7 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from "@nestjs/common";
import { UsersModule } from "./users/users.module";

@Module({
imports: [UsersModule],
})
export class AppModule {}
13 changes: 12 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
console.log("Hello, world.");
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";

const DEFAULT_PORT = 3000;

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(process.env.PORT || DEFAULT_PORT);
console.log(`Application is running on: ${await app.getUrl()}`);
}

bootstrap();
1 change: 1 addition & 0 deletions src/users/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class CreateUserDto {}
4 changes: 4 additions & 0 deletions src/users/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from "@nestjs/mapped-types";
import { CreateUserDto } from "./create-user.dto";

export class UpdateUserDto extends PartialType(CreateUserDto) {}
1 change: 1 addition & 0 deletions src/users/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class User {}
20 changes: 20 additions & 0 deletions src/users/users.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Test, TestingModule } from "@nestjs/testing";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";

describe("UsersController", () => {
let controller: UsersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
providers: [UsersService],
}).compile();

controller = module.get<UsersController>(UsersController);
});

it("should be defined", () => {
expect(controller).toBeDefined();
});
});
36 changes: 36 additions & 0 deletions src/users/users.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Controller, Get, Post, Body, Patch, Param, Delete,
} from "@nestjs/common";
import { CreateUserDto } from "./dto/create-user.dto";
import { UpdateUserDto } from "./dto/update-user.dto";
import { UsersService } from "./users.service";

@Controller("users")
export class UsersController {
constructor(private readonly usersService: UsersService) {}

@Post()
create(@Body() createUserDto: CreateUserDto) {
return this.usersService.create(createUserDto);
}

@Get()
findAll() {
return this.usersService.findAll();
}

@Get(":id")
findOne(@Param("id") id: string) {
return this.usersService.findOne(+id);
}

@Patch(":id")
update(@Param("id") id: string, @Body() updateUserDto: UpdateUserDto) {
return this.usersService.update(+id, updateUserDto);
}

@Delete(":id")
remove(@Param("id") id: string) {
return this.usersService.remove(+id);
}
}
9 changes: 9 additions & 0 deletions src/users/users.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from "@nestjs/common";
import { UsersController } from "./users.controller";
import { UsersService } from "./users.service";

@Module({
controllers: [UsersController],
providers: [UsersService],
})
export class UsersModule {}
18 changes: 18 additions & 0 deletions src/users/users.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from "@nestjs/testing";
import { UsersService } from "./users.service";

describe("UsersService", () => {
let service: UsersService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [UsersService],
}).compile();

service = module.get<UsersService>(UsersService);
});

it("should be defined", () => {
expect(service).toBeDefined();
});
});
27 changes: 27 additions & 0 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable */
import { Injectable } from "@nestjs/common";
import { CreateUserDto } from "./dto/create-user.dto";
import { UpdateUserDto } from "./dto/update-user.dto";

@Injectable()
export class UsersService {
create(createUserDto: CreateUserDto) {
return "This action adds a new user";
}

findAll() {
return `This action returns all users`;
}

findOne(id: number) {
return `This action returns a #${id} user`;
}

update(id: number, updateUserDto: UpdateUserDto) {
return `This action updates a #${id} user`;
}

remove(id: number) {
return `This action removes a #${id} user`;
}
}

1 comment on commit c0d1d33

@vercel
Copy link

@vercel vercel bot commented on c0d1d33 Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.