Skip to content

Commit

Permalink
Merge pull request #10 from williamkoller/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
williamkoller authored Apr 26, 2022
2 parents 8889af4 + 040184d commit 18a384d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/modules/app/app.settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CacheModule } from '@/modules/cache/cache.module';
import { ScheduleModule } from '@nestjs/schedule';
import { ThrottlerModule } from '@nestjs/throttler';
import { CoreModule } from '@/modules/core/core.module';
import { GraphqlModule } from '@/modules/graphql/graphql.module';

export const imports = [
ConfigModule.forRoot({
Expand All @@ -31,6 +32,7 @@ export const imports = [
forwardRef(() => AwsModule),
forwardRef(() => CacheModule),
forwardRef(() => CoreModule),
forwardRef(() => GraphqlModule),
ThrottlerModule.forRoot({
ttl: 60,
limit: 10,
Expand Down
5 changes: 2 additions & 3 deletions src/modules/books/controllers/books.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { UpdateBookDto } from '@/modules/books/dtos/update-book.dto';
import { UpdateBookService } from '@/modules/books/services/update-book/update-book.service';
import { DeleteBookService } from '@/modules/books/services/delete-book/delete-book.service';
import { ApiBasicAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { BookOutputType } from '@/modules/books/types/book-output.type';
import { JwtAuthGuard } from '@/modules/auth/guards/auth.guard';
import { Cache } from 'cache-manager';
import { ProcessBook } from '../process/books.process';
Expand Down Expand Up @@ -51,7 +50,7 @@ export class BooksController {
status: HttpStatus.CONFLICT,
description: 'there is already a book with that name.',
})
async add(@Body() addBookDto: AddBookDto): Promise<BookOutputType> {
async add(@Body() addBookDto: AddBookDto): Promise<Book> {
return await this.addBookService.add(addBookDto);
}

Expand All @@ -65,7 +64,7 @@ export class BooksController {
status: HttpStatus.NOT_FOUND,
description: 'no record found.',
})
async index(): Promise<BookOutputType[] | number> {
async index(): Promise<Book[] | number> {
return await this.findAllBooksService.findAll();
}

Expand Down
7 changes: 3 additions & 4 deletions src/modules/books/resolvers/books.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Resolver, Query } from '@nestjs/graphql';
import { Book } from '../schemas/book.schema';
import { FindAllBooksService } from '../services/find-all-books/find-all.books.service';
import { BookOutputType } from '../types/book-output.type';

@Resolver()
export class BookResolver {
constructor(private readonly findAlllBooksService: FindAllBooksService) {}
constructor(private readonly findAllBooksService: FindAllBooksService) {}

@Query(() => [Book])
async books(): Promise<BookOutputType[] | number> {
return await this.findAlllBooksService.findAll();
async books(): Promise<Book[] | number> {
return await this.findAllBooksService.findAll();
}
}
4 changes: 2 additions & 2 deletions src/modules/books/services/add-book/add-book.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ConflictException, Injectable } from '@nestjs/common';
import { AddBookDto } from '@/modules/books/dtos/add-book.dto';
import { BooksRepository } from '@/modules/books/repositories/books.repository';
import { BookOutputType } from '@/modules/books/types/book-output.type';
import { bookTransform } from '@/modules/books/transforms/books.transform';
import { CachesRepository } from '@/modules/cache/repositories/caches.repository';
import { GET_BOOKS_CACHE_KEY } from '@/modules/cache/constants/books-cache-key.constant';
import { Book } from '../../schemas/book.schema';

@Injectable()
export class AddBookService {
Expand All @@ -14,7 +14,7 @@ export class AddBookService {
private readonly cachesRepository: CachesRepository,
) {}

async add(addBookDto: AddBookDto): Promise<BookOutputType> {
async add(addBookDto: AddBookDto): Promise<Book> {
const book = await this.booksRepo.findByName(addBookDto.name);

if (book) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class BooksCountService {

offset = offset === undefined ? 0 : offset;

this.logger.log(`offset ${offset}.`);
this.logger.log(`offset ${JSON.stringify(offset)}.`);

const countBooks = await this.booksRepository.countBooks(
offset,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { BooksRepository } from '@/modules/books/repositories/books.repository';
import { booksTransform } from '@/modules/books/transforms/books.transform';
import { BookOutputType } from '@/modules/books/types/book-output.type';
import { CachesRepository } from '@/modules/cache/repositories/caches.repository';
import { GET_BOOKS_CACHE_KEY } from '@/modules/cache/constants/books-cache-key.constant';
import { Book } from '../../schemas/book.schema';

@Injectable()
export class FindAllBooksService {
Expand All @@ -13,7 +13,7 @@ export class FindAllBooksService {
private readonly cachesRepository: CachesRepository,
) {}

async findAll(): Promise<BookOutputType[] | number> {
async findAll(): Promise<Book[] | number> {
const cache = await this.cachesRepository.getCache(GET_BOOKS_CACHE_KEY);

if (cache) {
Expand Down
8 changes: 3 additions & 5 deletions src/modules/books/transforms/books.transform.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Book } from '@/modules/books/schemas/book.schema';
import { BookOutputType } from '@/modules/books/types/book-output.type';

export const booksTransform = (books: Book[]): BookOutputType[] => {
export const booksTransform = (books: Book[]): Book[] => {
return books.map(bookTransform);
};

export const bookTransform = (book: Book): BookOutputType => {
export const bookTransform = (book: Book): Book => {
return {
id: book._id,
_id: book._id,
name: book.name,
description: book.description,
author: book.author,
Expand Down
10 changes: 0 additions & 10 deletions src/modules/books/types/book-output.type.ts

This file was deleted.

7 changes: 5 additions & 2 deletions src/modules/graphql/graphql.settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
import { GraphQLModule } from '@nestjs/graphql';
import { join } from 'path';

export const imports = [
GraphQLModule.forRoot({
autoSchemaFile: './schema.gql',
GraphQLModule.forRoot<ApolloDriverConfig>({
driver: ApolloDriver,
autoSchemaFile: join(process.cwd(), 'src/graphql/schema.gql'),
debug: true,
playground: true,
}),
Expand Down

0 comments on commit 18a384d

Please sign in to comment.