Skip to content

Commit

Permalink
remove useless db columns and relations from indicator-coefficient.en…
Browse files Browse the repository at this point in the history
…tity.ts and indicator-record.entity.ts entities
  • Loading branch information
alexeh committed Dec 7, 2024
1 parent cced48e commit 43c3585
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import {
BaseEntity,
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Indicator } from 'modules/indicators/indicator.entity';
import { Material } from 'modules/materials/material.entity';
import { AdminRegion } from 'modules/admin-regions/admin-region.entity';
import { User } from 'modules/users/user.entity';
import { BaseServiceResource } from 'types/resource.interface';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { TimestampedBaseEntity } from 'baseEntities/timestamped-base-entity';

export const indicatorCoefficientResource: BaseServiceResource = {
className: 'IndicatorCoefficient',
Expand All @@ -18,37 +21,27 @@ export const indicatorCoefficientResource: BaseServiceResource = {
};

@Entity()
export class IndicatorCoefficient extends TimestampedBaseEntity {
export class IndicatorCoefficient extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
@ApiProperty()
id!: string;

@Column({ type: 'float', nullable: true })
@ApiPropertyOptional()
value?: number;

@Column({ type: 'int' })
@ApiProperty()
year!: number;

@ManyToOne(() => AdminRegion, (ar: AdminRegion) => ar.indicatorCoefficients, {
nullable: true,
})
@ApiPropertyOptional()
adminRegion: AdminRegion;

@ManyToOne(() => User, (user: User) => user.indicatorCoefficients)
@ApiProperty({ type: () => User })
user!: User;

@ManyToOne(
() => Indicator,
(indicator: Indicator) => indicator.indicatorCoefficients,
)
@ApiProperty()
indicator!: Indicator;

@ManyToOne(() => Material, (mat: Material) => mat.indicatorCoefficients)
@ApiProperty()
material!: Material;
}
30 changes: 3 additions & 27 deletions api/src/modules/indicator-records/indicator-record.entity.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {
BaseEntity,
Check,
Column,
Entity,
Index,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Indicator } from 'modules/indicators/indicator.entity';
import { BaseServiceResource } from 'types/resource.interface';
import { ApiProperty } from '@nestjs/swagger';
import { TimestampedBaseEntity } from 'baseEntities/timestamped-base-entity';
import { SourcingRecord } from 'modules/sourcing-records/sourcing-record.entity';
import { IndicatorCoefficient } from 'modules/indicator-coefficients/indicator-coefficient.entity';
import { H3Data } from 'modules/h3-data/h3-data.entity';

export const indicatorRecordResource: BaseServiceResource = {
Expand All @@ -30,6 +27,7 @@ export const indicatorRecordResource: BaseServiceResource = {
'indicatorId',
],
};

export enum INDICATOR_RECORD_STATUS {
UNSTARTED = 'unstarted',
STARTED = 'started',
Expand All @@ -40,32 +38,20 @@ export enum INDICATOR_RECORD_STATUS {
@Entity()
@Check(`value <> 'NaN'`)
@Check(`scaler <> 'NaN'`)
export class IndicatorRecord extends TimestampedBaseEntity {
@ApiProperty()
export class IndicatorRecord extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@ApiProperty()
@Column({ type: 'float', nullable: true })
value!: number;

@ApiProperty()
@Column({
type: 'enum',
enum: INDICATOR_RECORD_STATUS,
default: INDICATOR_RECORD_STATUS.UNSTARTED,
})
status!: INDICATOR_RECORD_STATUS;

@ApiProperty()
@Column({ nullable: true })
statusMsg?: string;

@UpdateDateColumn({
type: 'timestamptz',
})
statusTimestamp!: string;

@ManyToOne(
() => SourcingRecord,
(sourcingRecord: SourcingRecord) => sourcingRecord.id,
Expand All @@ -86,16 +72,6 @@ export class IndicatorRecord extends TimestampedBaseEntity {
@Column({ nullable: true })
indicatorId: string;

@ManyToOne(
() => IndicatorCoefficient,
(indicatorCoefficient: IndicatorCoefficient) => indicatorCoefficient.id,
{
eager: false,
},
)
@JoinColumn({ name: 'indicatorCoefficientId' })
indicatorCoefficientId!: IndicatorCoefficient;

// Scaler: Production total sum.
@Column({ type: 'float', nullable: true })
scaler: number;
Expand Down
3 changes: 0 additions & 3 deletions api/src/modules/users/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ export class User extends BaseEntity {
@Column('boolean', { name: 'is_deleted', default: false })
isDeleted!: boolean;

@OneToMany(() => IndicatorCoefficient, (ic: IndicatorCoefficient) => ic.user)
indicatorCoefficients: IndicatorCoefficient[];

@OneToMany(() => SourcingLocation, (sc: SourcingLocation) => sc.updatedBy)
sourcingLocations: SourcingLocation[];

Expand Down

0 comments on commit 43c3585

Please sign in to comment.