Skip to content

Commit

Permalink
add countries module with custom repository
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 19, 2024
1 parent 513486d commit ae757a2
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { UsersModule } from '@api/modules/users/users.module';
import { APP_FILTER } from '@nestjs/core';
import { AllExceptionsFilter } from '@api/filters/all-exceptions.exception.filter';
import { TsRestModule } from '@ts-rest/nest';
import { CountriesModule } from './modules/countries/countries.module';

@Module({
imports: [
Expand All @@ -27,6 +28,7 @@ import { TsRestModule } from '@ts-rest/nest';
AdminModule,
ImportModule,
UsersModule,
CountriesModule,
],
controllers: [AppController],
providers: [
Expand Down
11 changes: 11 additions & 0 deletions api/src/modules/countries/countries.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Country } from '@shared/entities/countries/country.entity';

@Module({
imports: [TypeOrmModule.forFeature([Country])],
controllers: [],
providers: [],
exports: [],
})
export class CountriesModule {}
14 changes: 14 additions & 0 deletions api/src/modules/countries/countries.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Country } from '@shared/entities/countries/country.entity';

@Injectable()
export class CountryRepository extends Repository<Country> {
constructor(
@InjectRepository(Country)
private readonly repository: Repository<Country>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}
}
3 changes: 2 additions & 1 deletion api/src/modules/import/import.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, ServiceUnavailableException } from '@nestjs/common';
import { XlsxParser } from '@api/modules/import/services/xlsx.parser';
import { EntityPreprocessor } from '@api/modules/import/services/entity.preprocessor';
import { BaseDataRepository } from '@api/modules/model/base-data.repository';
Expand All @@ -21,6 +21,7 @@ export class ImportService {
return dbResult;
} catch (e) {
console.log(e);
throw new ServiceUnavailableException('Error importing data');
} finally {
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Column, Entity, PrimaryColumn, BaseEntity } from 'typeorm';
import {
Column,
Entity,
PrimaryColumn,
BaseEntity,
Geometry,
Index,
} from 'typeorm';

export enum CONTINENTS {
AFRICA = 'Africa',
Expand Down Expand Up @@ -34,4 +41,13 @@ export class Country extends BaseEntity {

@Column({ name: 'hdi', type: 'int', nullable: true })
hdi?: number;

@Index({ spatial: true })
@Column({
type: 'geometry',
srid: 4326,
// TODO: Make it nullable false once we have all the data
nullable: true,
})
geometry: Geometry;
}
3 changes: 2 additions & 1 deletion shared/entities/database.entities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { User } from "@shared/entities/users/user.entity";
import { Country } from "@shared/entities/countries/country.entity";

export const COMMON_DATABASE_ENTITIES = [User];
export const COMMON_DATABASE_ENTITIES = [User, Country];
2 changes: 1 addition & 1 deletion shared/lib/db-entities.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { User } from "@shared/entities/users/user.entity";
import { ApiEventsEntity } from "@api/modules/api-events/api-events.entity";
import { Country } from "@api/modules/model/entities/country.entity";
import { BaseData } from "@api/modules/model/base-data.entity";
import { CostInput } from "@api/modules/model/entities/cost-input.entity";
import { CarbonInputEntity } from "@api/modules/model/entities/carbon-input.entity";
import { Country } from "@shared/entities/countries/country.entity";

export const DB_ENTITIES = [
User,
Expand Down

0 comments on commit ae757a2

Please sign in to comment.