This file contains hidden or 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 { registerAs } from '@nestjs/config'; | |
import { TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
export const mysqlDatabaseConfig = registerAs( | |
'database.mysql', | |
(): TypeOrmModuleOptions => ({ | |
type: 'mysql', | |
host: process.env.DB_HOST, | |
username: process.env.DB_USERNAME, | |
password: process.env.DB_PASSWORD, |
This file contains hidden or 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 { DynamicModule, Module } from '@nestjs/common'; | |
import { MysqlModule } from './mysql/mysql.module'; | |
import { InMemoryModule } from './in-memory/in-memory.module'; | |
@Module({ | |
imports: [MysqlModule, InMemoryModule], | |
}) | |
export class DatabaseModule { | |
static forRoot(): DynamicModule { | |
const isTestEnv = process.env.NODE_ENV === 'test'; |
This file contains hidden or 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 { MigrationInterface, QueryRunner, Table } from 'typeorm'; | |
export class CreateTaskTable1722825209848 implements MigrationInterface { | |
public async up(queryRunner: QueryRunner): Promise<void> { | |
await queryRunner.createTable( | |
new Table({ | |
name: 'task', | |
columns: [ | |
{ | |
name: 'id', |
This file contains hidden or 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 } from '@nestjs/common'; | |
import { EntityManager } from 'typeorm'; | |
import { faker } from '@faker-js/faker'; | |
import { Task } from '@/infrastructure/database/entities/task.entity'; | |
@Injectable() | |
export class TaskSeedService { | |
private done = [0, 1]; | |
constructor(private readonly entityManager: EntityManager) {} |
This file contains hidden or 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 { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'; | |
@Entity() | |
export class Task { | |
@PrimaryGeneratedColumn() | |
id: number; | |
@Column() | |
name: string; |
This file contains hidden or 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 } from '@nestjs/common'; | |
import { InjectRepository } from '@nestjs/typeorm'; | |
import { Repository } from 'typeorm'; | |
import { Task } from '../entities/task.entity'; | |
@Injectable() | |
export class TaskRepository { | |
constructor( | |
@InjectRepository(Task) | |
private repository: Repository<Task>, |
This file contains hidden or 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 { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
import { ConfigModule, ConfigService } from '@nestjs/config'; | |
import { inMemoryDatabaseConfig } from '@/main/config/database/in-memory-database.config'; | |
import { TaskRepository } from '@/infrastructure/database/repositories/task.repository'; | |
import { TaskSeedService } from '@/infrastructure/database/seeds/task-seed-service'; | |
import { Task } from '@/infrastructure/database/entities/task.entity'; | |
@Module({ | |
imports: [ |
This file contains hidden or 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 { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm'; | |
import { ConfigModule, ConfigService } from '@nestjs/config'; | |
import { mysqlDatabaseConfig } from '@/main/config/database/mysql-database.config'; | |
import { TaskRepository } from '@/infrastructure/database/repositories/task.repository'; | |
import { TaskSeedService } from '@/infrastructure/database/seeds/task-seed-service'; | |
import { Task } from '@/infrastructure/database/entities/task.entity'; | |
@Module({ | |
imports: [ |
This file contains hidden or 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 { Test, TestingModule } from '@nestjs/testing'; | |
import { TypeOrmModule } from '@nestjs/typeorm'; | |
import { Connection } from 'typeorm'; | |
import { TaskSeedService } from '../../infrastructure/database/seeds/task-seed-service'; | |
import { TaskService } from './task.service'; | |
import { Task } from '../../infrastructure/database/entities/task.entity'; | |
import { DatabaseModule } from '../../infrastructure/database/database.module'; | |
describe('TaskService', () => { | |
let service: TaskService; |
This file contains hidden or 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, Query, Req, Res, HttpStatus } from '@nestjs/common'; | |
import type { Request, Response } from 'express'; | |
import { TaskService } from '@/modules/task/task.service'; | |
@Controller('tasks') | |
export class TaskController { | |
constructor(private readonly taskService: TaskService) {} | |
@Get() | |
async searchTaskByState( |