Skip to content

Commit

Permalink
remove duplicated entities
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Oct 22, 2024
1 parent 0dd44bd commit 5f94f42
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 165 deletions.
20 changes: 9 additions & 11 deletions admin/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { DataSource } from "typeorm";
import { User } from "@shared/entities/users/user.entity.js";
import { ApiEventsEntity } from "@api/modules/api-events/api-events.entity.js";
import { Country } from "@api/modules/model/entities/country.entity.js";
import { BaseData } from "@api/modules/model/base-data.entity.js";
import { ProjectSize } from "@api/modules/model/entities/project-size.entity.js";
import { FeasibilityAnalysis } from "@api/modules/model/entities/feasability-analysis.entity.js";
import { ConservationPlanningAndAdmin } from "@api/modules/model/entities/conservation-and-planning-admin.entity.js";
import { DataCollectionAndFieldCosts } from "@api/modules/model/entities/data-collection-and-field-costs.entity.js";
import { Country } from "@shared/entities/country.entity.js";
import { BaseData } from "@shared/entities/base-data.entity.js";
import { ProjectSize } from "@shared/entities/project-size.entity.js";
import { FeasibilityAnalysis } from "@shared/entities/feasability-analysis.entity.js";
import { ConservationPlanningAndAdmin } from "@shared/entities/conservation-and-planning-admin.entity.js";
import { DataCollectionAndFieldCosts } from "@shared/entities/data-collection-and-field-costs.entity.js";

// TODO: If we go with this, it might be better to share the datasource with the api, right now adminjs throws and error if we import the BACKEND_DB_ENTITIES
// we need to fix this and have a single source of truth for the entities

const ENTITIES = [
// TODO: If we import the COMMON_DATABASE_ENTITIES from shared, we get an error where DataSouce is not set for a given entity
export const ADMINJS_ENTITIES = [
User,
ApiEventsEntity,
Country,
Expand All @@ -29,7 +27,7 @@ export const dataSource = new DataSource({
password: process.env.DB_PASSWORD || "blue-carbon-cost",
database: process.env.DB_NAME || "blc",
// TODO: Use common db entities from shared
entities: ENTITIES,
entities: ADMINJS_ENTITIES,
synchronize: false,
ssl:
process.env.NODE_ENV === "production"
Expand Down
4 changes: 2 additions & 2 deletions admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import AdminJSExpress from "@adminjs/express";
import express from "express";
import * as AdminJSTypeorm from "@adminjs/typeorm";
import { dataSource } from "./datasource.js";
import { Country } from "@api/modules/model/entities/country.entity.js";
import { AuthProvider } from "./providers/auth.provider.js";
import { userResource } from "./resources/users/user.resource.js";
import { projectSizeResource } from "./resources/project-size/project-size.resource.js";
import { BaseData } from "@api/modules/model/base-data.entity.js";
import { BaseData } from "@shared/entities/base-data.entity.js";
import { Country } from "@shared/entities/country.entity.js";

AdminJS.registerAdapter({
Database: AdminJSTypeorm.Database,
Expand Down
7 changes: 4 additions & 3 deletions admin/resources/project-size/project-size.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
ResourceOptions,
ResourceWithOptions,
} from "adminjs";
import { ProjectSize } from "@api/modules/model/entities/project-size.entity.js";
import { BaseData } from "@api/modules/model/base-data.entity.js";
import { dataSource } from "../../datasource.js";
import { Country } from "@api/modules/model/entities/country.entity.js";

import { Sort } from "typeorm";
import { ProjectSize } from "@shared/entities/project-size.entity.js";
import { BaseData } from "@shared/entities/base-data.entity.js";
import { Country } from "@shared/entities/country.entity.js";

const DEFAULT_DIRECTION = "asc";

Expand Down
2 changes: 1 addition & 1 deletion api/src/modules/config/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TOKEN_TYPE_ENUM } from '@shared/schemas/auth/token-type.schema';
import { JwtConfigHandler } from '@api/modules/config/auth-config.handler';
import { COMMON_DATABASE_ENTITIES } from '@shared/lib/db-entities';
// import { BACKEND_DB_ENTITIES } from '@shared/lib/db-entities';
import { COMMON_DATABASE_ENTITIES } from '@shared/entities/database.entities';

export type JWTConfig = {
secret: string;
Expand Down
2 changes: 1 addition & 1 deletion api/src/modules/import/services/entity.preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';

import { Country } from '@api/modules/model/entities/country.entity';
import { BaseData } from '@shared/entities/base-data.entity';
import { Country } from '@shared/entities/country.entity';

export type ParsedDBEntities = {
countries: Country[];
Expand Down
3 changes: 1 addition & 2 deletions api/src/modules/model/base-data.repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DataSource, EntityManager, Repository } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { Injectable } from '@nestjs/common';

import { ParsedDBEntities } from '@api/modules/import/services/entity.preprocessor';

import { Country } from '@api/modules/model/entities/country.entity';
import { BaseData } from '@shared/entities/base-data.entity';

@Injectable()
Expand Down
37 changes: 0 additions & 37 deletions api/src/modules/model/entities/country.entity.ts

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions api/src/modules/model/entities/feasability-analysis.entity.ts

This file was deleted.

22 changes: 0 additions & 22 deletions api/src/modules/model/entities/project-size.entity.ts

This file was deleted.

1 change: 0 additions & 1 deletion api/src/modules/model/model.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BaseDataRepository } from '@api/modules/model/base-data.repository';
import { BaseData } from '@shared/entities/base-data.entity';
import { ConservationPlanningAndAdmin } from '@shared/entities/conservation-and-planning-admin.entity';

@Module({
imports: [TypeOrmModule.forFeature([BaseData])],
Expand Down
26 changes: 0 additions & 26 deletions shared/entities/database.entities.ts

This file was deleted.

38 changes: 19 additions & 19 deletions shared/lib/db-entities.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// 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 { ProjectSize } from "@api/modules/model/entities/project-size.entity";
// import { FeasibilityAnalysis } from "@api/modules/model/entities/feasability-analysis.entity";
// import { ConservationPlanningAndAdmin } from "@api/modules/model/entities/conservation-and-planning-admin.entity";
// import { DataCollectionAndFieldCosts } from "@api/modules/model/entities/data-collection-and-field-costs.entity";
//
// export const BACKEND_DB_ENTITIES = [
// User,
// ApiEventsEntity,
// Country,
// BaseData,
// ProjectSize,
// FeasibilityAnalysis,
// ConservationPlanningAndAdmin,
// DataCollectionAndFieldCosts,
// ];
import { User } from "@shared/entities/users/user.entity";
import { ApiEventsEntity } from "@api/modules/api-events/api-events.entity";
import { Country } from "@shared/entities/country.entity";
import { BaseData } from "@shared/entities/base-data.entity";
import { ProjectSize } from "@shared/entities/project-size.entity";
import { FeasibilityAnalysis } from "@shared/entities/feasability-analysis.entity";
import { ConservationPlanningAndAdmin } from "@shared/entities/conservation-and-planning-admin.entity";
import { DataCollectionAndFieldCosts } from "@shared/entities/data-collection-and-field-costs.entity";

export const COMMON_DATABASE_ENTITIES = [
User,
ApiEventsEntity,
Country,
BaseData,
ProjectSize,
FeasibilityAnalysis,
ConservationPlanningAndAdmin,
DataCollectionAndFieldCosts,
];

0 comments on commit 5f94f42

Please sign in to comment.