Commit a7e8e6d6 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Agregando endpoint que regresa los pueblos por estado

See merge request !22
parents 3edb6270 7b031bba
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import { join } from 'path';
import { Town } from './town/entities/town.entity';
import { TownModule } from './town/town.module';
import { TownTraduction } from './town/entities/town-traduction.entity';

@Module({
  imports: [
    TypeOrmModule.forRoot({
@@ -28,6 +29,7 @@ import { TownTraduction } from './town/entities/town-traduction.entity';
      database: DbConstants.DB_NAME,
      entities: [Admin, User, State, Town, TownTraduction],
      synchronize: DbConstants.DB_SYNC,
      logging: true,
    }),
    AuthAdminModule,
    AdminModule,
@@ -42,5 +44,6 @@ import { TownTraduction } from './town/entities/town-traduction.entity';
  ],
  controllers: [AppController],
  providers: [AppService, DatabaseSeederModule],
  exports: [TypeOrmModule],
})
export class AppModule {}
+2 −1
Original line number Diff line number Diff line
@@ -3,9 +3,10 @@ import { DatabaseSeederService } from './database-seeder.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { State } from 'src/state/entities/state.entity';
import { StateService } from 'src/state/state.service';
import { Town } from 'src/town/entities/town.entity';

@Module({
  providers: [DatabaseSeederService, StateService],
  imports: [TypeOrmModule.forFeature([State])],
  imports: [TypeOrmModule.forFeature([State, Town])],
})
export class DatabaseSeederModule {}
+7 −0
Original line number Diff line number Diff line
export class TownResDto {
  townId: number;
  name: string;
  description: string;
  imageName: string;
  stateId: number;
}
+3 −3
Original line number Diff line number Diff line
import { Entity, Column, OneToOne, PrimaryColumn } from 'typeorm';
import { Entity, Column, PrimaryColumn, ManyToOne } from 'typeorm';
import { Town } from './town.entity';
import { LANGUAGES } from 'src/enum/languages.enum';
@Entity()
export class TownTraduction {
  @PrimaryColumn()
  @OneToOne(() => Town, (town) => town.townId)
  @PrimaryColumn({ name: 'townId' })
  @ManyToOne(() => Town, (town) => town.townId)
  townId: number;
  @PrimaryColumn()
  language: LANGUAGES;
+17 −4
Original line number Diff line number Diff line
import { Controller, Get, Post, Param, Delete, UseInterceptors, UploadedFile, Body } from '@nestjs/common';
import { Controller, Get, Post, Param, Delete, UseInterceptors, UploadedFile, Body, Query } from '@nestjs/common';
import { TownService } from './town.service';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe';
import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor';
import { CreateTownDto } from './dto/create-town.dto';
@Controller('town')
@Controller()
@ApiTags('Agregar un pueblo')
export class TownController {
  constructor(private readonly townService: TownService) {}
  constructor(
    private readonly townService: TownService,
    // private readonly stateService: StateService,
  ) {}

  @ApiBody({ type: CreateTownDto })
  @ApiConsumes('multipart/form-data')
  @Post()
  @Post('town')
  @UseInterceptors(fileInterceptor('image', 'static/towns/', ['.jpg', '.jpeg', '.png']))
  async create(@UploadedFile(new FileValidationPipe()) file, @Body() createTownDto: CreateTownDto) {
    try {
@@ -23,6 +26,16 @@ export class TownController {
    }
  }

  @Get('state/:stateId/town')
  async findTownsByState(@Param('stateId') stateId: number, @Query('lang') lang) {
    try {
      stateId = parseInt(stateId.toString());
      return await this.townService.findTownsByState(stateId, lang);
    } catch (error) {
      throw error;
    }
  }

  @Get()
  findAll() {
    return this.townService.findAll();
Loading