refactor imports/exports

This commit is contained in:
andres
2023-07-16 16:21:55 +02:00
parent 2f1579ed48
commit 4a9bf1e858
26 changed files with 50 additions and 40 deletions

View File

@@ -1,4 +1,5 @@
import { isObject } from 'remeda'
import { DEFAULT_PAGE_NUMBER, DEFAULT_PAGE_SIZE } from './pagination.constants'
export class Pagination {
static getPaginationData<T>(query: T) {
@@ -9,13 +10,13 @@ export class Pagination {
typeof query.currentPage === 'string' &&
!isNaN(Number(query.currentPage))
? +query.currentPage
: 1
: DEFAULT_PAGE_NUMBER
const itemsPerPage =
'itemsPerPage' in query &&
typeof query.itemsPerPage === 'string' &&
!isNaN(Number(query.itemsPerPage))
? +query.itemsPerPage
: 10
: DEFAULT_PAGE_SIZE
return { currentPage, itemsPerPage, ...query }
}

View File

@@ -0,0 +1,3 @@
export * from './cookie.decorator'
export * from './is-optional-or-empty-string.decorator'
export * from './is-order-by-constraint.decorator'

View File

@@ -13,11 +13,9 @@ import {
UseGuards,
} from '@nestjs/common'
import { RegistrationDto } from './dto/registration.dto'
import { LocalAuthGuard } from './guards/local-auth.guard'
import { JwtAuthGuard } from './guards/jwt-auth.guard'
import { LocalAuthGuard, JwtAuthGuard, JwtRefreshGuard } from './guards'
import { Response as ExpressResponse } from 'express'
import { JwtRefreshGuard } from './guards/jwt-refresh.guard'
import { Cookies } from '../../infrastructure/decorators/cookie.decorator'
import { Cookies } from '../../infrastructure/decorators'
import { CommandBus } from '@nestjs/cqrs'
import {
CreateUserCommand,

View File

@@ -0,0 +1,4 @@
export * from './base-auth.guard'
export * from './jwt-auth.guard'
export * from './jwt-refresh.guard'
export * from './local-auth.guard'

View File

@@ -5,8 +5,8 @@ import { PrismaService } from '../../../prisma.service'
export class AuthRepository {
constructor(private prisma: PrismaService) {}
async createRefreshToken(userId: string, token: string, expiresAt: Date) {
return await this.prisma.refreshToken.create({
createRefreshToken(userId: string, token: string, expiresAt: Date) {
return this.prisma.refreshToken.create({
data: {
userId,
token,

View File

@@ -2,7 +2,7 @@ export * from './create-user-use-case'
export * from './get-current-user-data-use-case'
export * from './logout-use-case'
export * from './resend-verification-email-use-case'
export * from './refresh-token-use-case'
export * from './verify-email-use-case'
export * from './send-password-recovery-email-use-case'
export * from './reset-password-use-case'
export * from './refresh-token-use-case'
export * from './send-password-recovery-email-use-case'
export * from './verify-email-use-case'

View File

@@ -11,10 +11,10 @@ import {
UseInterceptors,
} from '@nestjs/common'
import { CardsService } from './cards.service'
import { UpdateCardDto } from './dto/update-card.dto'
import { UpdateCardDto } from './dto'
import { CommandBus } from '@nestjs/cqrs'
import { DeleteCardByIdCommand, GetDeckByIdCommand, UpdateCardCommand } from './use-cases'
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'
import { JwtAuthGuard } from '../auth/guards'
import { FileFieldsInterceptor } from '@nestjs/platform-express'
@Controller('cards')

View File

@@ -1,7 +1,6 @@
import { Length } from 'class-validator'
import { PaginationDto } from '../../../infrastructure/common/pagination/pagination.dto'
import { IsOptionalOrEmptyString } from '../../../infrastructure/decorators/is-optional-or-empty-string'
import { IsOrderBy } from '../../../infrastructure/decorators/is-order-by-constraint'
import { IsOptionalOrEmptyString, IsOrderBy } from '../../../infrastructure/decorators'
export class GetAllCardsInDeckDto extends PaginationDto {
@IsOptionalOrEmptyString()

View File

@@ -0,0 +1,3 @@
export * from './create-card.dto'
export * from './get-all-cards.dto'
export * from './update-card.dto'

View File

@@ -1,3 +1,3 @@
export * from './get-deck-by-id-use-case'
export * from './delete-card-by-id-use-case'
export * from './get-deck-by-id-use-case'
export * from './update-card-use-case'

View File

@@ -14,8 +14,7 @@ import {
UseInterceptors,
} from '@nestjs/common'
import { DecksService } from './decks.service'
import { CreateDeckDto } from './dto/create-deck.dto'
import { UpdateDeckDto } from './dto/update-deck.dto'
import { UpdateDeckDto, CreateDeckDto, GetAllDecksDto } from './dto'
import { CommandBus } from '@nestjs/cqrs'
import {
CreateDeckCommand,
@@ -24,15 +23,13 @@ import {
GetAllDecksCommand,
GetDeckByIdCommand,
UpdateDeckCommand,
GetRandomCardInDeckCommand,
SaveGradeCommand,
CreateCardCommand,
} from './use-cases'
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'
import { GetAllDecksDto } from './dto/get-all-decks.dto'
import { GetAllCardsInDeckDto } from '../cards/dto/get-all-cards.dto'
import { CreateCardDto } from '../cards/dto/create-card.dto'
import { JwtAuthGuard } from '../auth/guards'
import { CreateCardDto, GetAllCardsInDeckDto } from '../cards/dto'
import { Pagination } from '../../infrastructure/common/pagination/pagination.service'
import { GetRandomCardInDeckCommand } from './use-cases/get-random-card-in-deck-use-case'
import { SaveGradeCommand } from './use-cases/save-grade-use-case'
import { FileFieldsInterceptor } from '@nestjs/platform-express'
@Controller('decks')

View File

@@ -10,12 +10,12 @@ import {
UpdateDeckHandler,
GetAllCardsInDeckHandler,
CreateCardHandler,
SaveGradeHandler,
GetRandomCardInDeckHandler,
} from './use-cases'
import { DecksRepository } from './infrastructure/decks.repository'
import { CardsRepository } from '../cards/infrastructure/cards.repository'
import { GetRandomCardInDeckHandler } from './use-cases/get-random-card-in-deck-use-case'
import { GradesRepository } from './infrastructure/grades.repository'
import { SaveGradeHandler } from './use-cases/save-grade-use-case'
import { FileUploadService } from '../../infrastructure/file-upload-service/file-upload.service'
const commandHandlers = [

View File

@@ -1,6 +1,6 @@
import { IsUUID, Max, Min } from 'class-validator'
export class CreateDeckDto {
export class CreateGradeDto {
@Min(1)
@Max(5)
grade: number

View File

@@ -1,7 +1,6 @@
import { IsUUID } from 'class-validator'
import { IsOptionalOrEmptyString } from '../../../infrastructure/decorators/is-optional-or-empty-string'
import { IsOptionalOrEmptyString, IsOrderBy } from '../../../infrastructure/decorators'
import { PaginationDto } from '../../../infrastructure/common/pagination/pagination.dto'
import { IsOrderBy } from '../../../infrastructure/decorators/is-order-by-constraint'
export class GetAllDecksDto extends PaginationDto {
@IsOptionalOrEmptyString()

View File

@@ -0,0 +1,4 @@
export * from './create-deck.dto'
export * from './create-grade.dto'
export * from './get-all-decks.dto'
export * from './update-deck.dto'

View File

@@ -1,6 +1,6 @@
import { PartialType } from '@nestjs/mapped-types'
import { CreateDeckDto } from './create-deck.dto'
import { IsOptionalOrEmptyString } from '../../../infrastructure/decorators/is-optional-or-empty-string'
import { IsOptionalOrEmptyString } from '../../../infrastructure/decorators'
import { IsBoolean } from 'class-validator'
export class UpdateDeckDto extends PartialType(CreateDeckDto) {

View File

@@ -1,6 +1,6 @@
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common'
import { PrismaService } from '../../../prisma.service'
import { GetAllDecksDto } from '../dto/get-all-decks.dto'
import { GetAllDecksDto } from '../dto'
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
import { createPrismaOrderBy } from '../../../infrastructure/common/helpers/get-order-by-object'

View File

@@ -1,5 +1,5 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { CreateCardDto } from '../../cards/dto/create-card.dto'
import { CreateCardDto } from '../../cards/dto'
import { CardsRepository } from '../../cards/infrastructure/cards.repository'
import { FileUploadService } from '../../../infrastructure/file-upload-service/file-upload.service'

View File

@@ -1,5 +1,5 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { CreateDeckDto } from '../dto/create-deck.dto'
import { CreateDeckDto } from '../dto'
import { DecksRepository } from '../infrastructure/decks.repository'
import { FileUploadService } from '../../../infrastructure/file-upload-service/file-upload.service'

View File

@@ -1,6 +1,6 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { CardsRepository } from '../../cards/infrastructure/cards.repository'
import { GetAllCardsInDeckDto } from '../../cards/dto/get-all-cards.dto'
import { GetAllCardsInDeckDto } from '../../cards/dto'
import { ForbiddenException, NotFoundException } from '@nestjs/common'
import { DecksRepository } from '../infrastructure/decks.repository'

View File

@@ -1,6 +1,6 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { DecksRepository } from '../infrastructure/decks.repository'
import { GetAllDecksDto } from '../dto/get-all-decks.dto'
import { GetAllDecksDto } from '../dto'
export class GetAllDecksCommand {
constructor(public readonly params: GetAllDecksDto) {}

View File

@@ -1,7 +1,9 @@
export * from './create-card-use-case'
export * from './create-deck-use-case'
export * from './delete-deck-by-id-use-case'
export * from './get-all-cards-in-deck-use-case'
export * from './get-all-decks-use-case'
export * from './get-deck-by-id-use-case'
export * from './delete-deck-by-id-use-case'
export * from './get-random-card-in-deck-use-case'
export * from './save-grade-use-case'
export * from './update-deck-use-case'
export * from './get-all-cards-in-deck-use-case'
export * from './create-card-use-case'

View File

@@ -1,6 +1,6 @@
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { DecksRepository } from '../infrastructure/decks.repository'
import { UpdateDeckDto } from '../dto/update-deck.dto'
import { UpdateDeckDto } from '../dto'
import { BadRequestException, NotFoundException } from '@nestjs/common'
import { FileUploadService } from '../../../infrastructure/file-upload-service/file-upload.service'

View File

@@ -12,7 +12,7 @@ import {
import { UsersService } from '../services/users.service'
import { CreateUserDto } from '../dto/create-user.dto'
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
import { BaseAuthGuard } from '../../auth/guards/base-auth.guard'
import { BaseAuthGuard } from '../../auth/guards'
import { CommandBus } from '@nestjs/cqrs'
import { CreateUserCommand } from '../../auth/use-cases'