Loading backend/src/app.module.ts +3 −0 Original line number Diff line number Diff line Loading @@ -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({ Loading @@ -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, Loading @@ -42,5 +44,6 @@ import { TownTraduction } from './town/entities/town-traduction.entity'; ], controllers: [AppController], providers: [AppService, DatabaseSeederModule], exports: [TypeOrmModule], }) export class AppModule {} backend/src/database-seeder/database-seeder.module.ts +2 −1 Original line number Diff line number Diff line Loading @@ -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 {} backend/src/town/dto/town-res.dto.ts 0 → 100644 +7 −0 Original line number Diff line number Diff line export class TownResDto { townId: number; name: string; description: string; imageName: string; stateId: number; } backend/src/town/entities/town-traduction.entity.ts +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; Loading backend/src/town/town.controller.ts +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 { Loading @@ -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 Loading
backend/src/app.module.ts +3 −0 Original line number Diff line number Diff line Loading @@ -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({ Loading @@ -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, Loading @@ -42,5 +44,6 @@ import { TownTraduction } from './town/entities/town-traduction.entity'; ], controllers: [AppController], providers: [AppService, DatabaseSeederModule], exports: [TypeOrmModule], }) export class AppModule {}
backend/src/database-seeder/database-seeder.module.ts +2 −1 Original line number Diff line number Diff line Loading @@ -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 {}
backend/src/town/dto/town-res.dto.ts 0 → 100644 +7 −0 Original line number Diff line number Diff line export class TownResDto { townId: number; name: string; description: string; imageName: string; stateId: number; }
backend/src/town/entities/town-traduction.entity.ts +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; Loading
backend/src/town/town.controller.ts +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 { Loading @@ -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