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
import { Module } from '@nestjs/common'; | |
import { BooksController } from './books.controller'; | |
import { BooksService } from './books.service'; | |
@Module({ | |
controllers: [BooksController], | |
providers: [BooksService] | |
}) | |
export class BooksModule {} |
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
export class CreateBookDTO { | |
readonly id: number; | |
readonly title: string; | |
readonly description: string; | |
readonly author: string; | |
} |
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
import { Controller, Get, Param, Post, Body, Query, Delete } from '@nestjs/common'; | |
import { BooksService } from './books.service'; | |
import { CreateBookDTO } from './dto/create-book.dto'; | |
@Controller('books') | |
export class BooksController { | |
constructor(private booksService: BooksService) { } | |
@Get() | |
async getBooks() { |
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
import { Injectable, HttpException } from '@nestjs/common'; | |
import { BOOKS } from '../mocks/books.mock'; | |
@Injectable() | |
export class BooksService { | |
books = BOOKS; | |
... | |
deleteBook(bookID): Promise { | |
let id = Number(bookID); | |
return new Promise(resolve => { | |
let index = this.books.findIndex(book => book.id === id); |
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
import { Injectable, HttpException } from '@nestjs/common'; | |
import { BOOKS } from '../mocks/books.mock'; | |
@Injectable() | |
export class BooksService { | |
books = BOOKS; | |
... | |
addBook(book): Promise { | |
return new Promise(resolve => { | |
this.books.push(book); | |
resolve(this.books); |
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
import { Injectable, HttpException } from '@nestjs/common'; | |
import { BOOKS } from '../mocks/books.mock'; | |
@Injectable() | |
export class BooksService { | |
books = BOOKS; | |
getBooks(): Promise { | |
return new Promise(resolve => { | |
resolve(this.books); |
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
export const BOOKS = [ | |
{ id: 1, title: 'First book', description: "This is the description for the first book", author: 'Olususi Oluyemi' }, | |
{ id: 2, title: 'Second book', description: "This is the description for the second book", author: 'John Barry' }, | |
{ id: 3, title: 'Third book', description: "This is the description for the third book", author: 'Clement Wilfred' }, | |
{ id: 4, title: 'Fourth book', description: "This is the description for the fourth book", author: 'Christian nwamba' }, | |
{ id: 5, title: 'Fifth book', description: "This is the description for the fifth book", author: 'Chris anderson' }, | |
{ id: 6, title: 'Sixth book', description: "This is the description for the sixth book", author: 'Olususi Oluyemi' }, | |
]; |
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
import { Module } from '@nestjs/common'; | |
@Module({}) | |
export class BooksModule {} |
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
... | |
@Controller('users') | |
export class UsersController { | |
constructor(private readonly usersService: UsersService){} | |
... | |
} |
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
... | |
import { UsersModule } from './users/users.module'; | |
@Module({ | |
... | |
}) | |
export class AppModule { } |
NewerOlder