Commit e59b7e26 authored by Diego Iván's avatar Diego Iván
Browse files

agregando categorias por defecto

parent e00cd30f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ import { PointOfInterest } from 'src/pointOfInterest/entities/PointOfInterest.en
import { AvailableDate } from 'src/place/entities/available-date.entity';
import { PlaceTraduction } from 'src/place/entities/place-traduction.entity';
import { PointOfInterestTraduction } from 'src/pointOfInterest/entities/PointOfInterestTraduction.entity';
import { CategoryService } from 'src/category/category.service';
import { Category } from 'src/category/entities/category.entity';

@Module({
  providers: [
@@ -31,6 +33,7 @@ import { PointOfInterestTraduction } from 'src/pointOfInterest/entities/PointOfI
    TownService,
    PointOfInterestService,
    PlaceService,
    CategoryService,
  ],
  imports: [
    TypeOrmModule.forFeature([
@@ -44,6 +47,7 @@ import { PointOfInterestTraduction } from 'src/pointOfInterest/entities/PointOfI
      AvailableDate,
      PlaceTraduction,
      PointOfInterestTraduction,
      Category,
    ]),
  ],
})
+29 −4
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@ import { UserStatus } from 'src/shared/enum/user-status.enum';
import { AuthAdminService } from 'src/auth/admin/authAdmin.service';
import { TownService } from 'src/town/town.service';
import { CreateTownDto } from 'src/town/dto/create-town.dto';
import { PointOfInterestService } from 'src/pointOfInterest/PointOfInterest.service';
import { PlaceService } from 'src/place/place.service';
import { LANGUAGES } from 'src/shared/enum/languages.enum';
import { Category } from 'src/category/entities/category.entity';

@Injectable()
export class DatabaseSeederService implements OnModuleInit {
@@ -20,8 +20,7 @@ export class DatabaseSeederService implements OnModuleInit {
    private readonly stateService: StateService,
    private readonly authAdminService: AuthAdminService,
    private readonly townService: TownService,
    private readonly activityService: PointOfInterestService,
    private readonly placeService: PlaceService,
    @InjectRepository(Category) private categoryRepo: Repository<Category>,
  ) {}

  async insertStates() {
@@ -93,9 +92,35 @@ export class DatabaseSeederService implements OnModuleInit {
    await this.townService.create(town);
  }

  async insertCategories() {
    const categoriesES = [
      { idCategory: 1, language: LANGUAGES.ES, name: 'Arquitectura' },
      { idCategory: 2, language: LANGUAGES.ES, name: 'Comida' },
    ];
    const categoriesEN = [
      { idCategory: 1, language: LANGUAGES.EN, name: 'Architecture' },
      { idCategory: 2, language: LANGUAGES.EN, name: 'Food' },
    ];
    for (let i = 0; i < categoriesES.length; i++) {
      await this.categoryRepo.upsert(
        [{ idCategory: categoriesES[i].idCategory, language: LANGUAGES.ES, name: categoriesES[i].name }],
        {
          conflictPaths: ['idCategory', 'language'],
        },
      );
      await this.categoryRepo.upsert(
        [{ idCategory: categoriesES[i].idCategory, language: LANGUAGES.EN, name: categoriesEN[i].name }],
        {
          conflictPaths: ['idCategory', 'language'],
        },
      );
    }
  }

  async onModuleInit() {
    await this.insertStates();
    await this.insertSuperAdmin();
    await this.insertTowns();
    await this.insertCategories();
  }
}