-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get default model assumptions and base data for project calculation
- Loading branch information
Showing
6 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { DataSource } from 'typeorm'; | ||
import { ModelAssumptions } from '@shared/entities/model-assumptions.entity'; | ||
import { Country } from '@shared/entities/country.entity'; | ||
import { ECOSYSTEM } from '@shared/entities/ecosystem.enum'; | ||
import { ACTIVITY } from '@shared/entities/activity.enum'; | ||
import { BaseDataView } from '@shared/entities/base-data.view'; | ||
|
||
export type GetBaseData = { | ||
countryCode: Country['code']; | ||
ecosystem: ECOSYSTEM; | ||
activity: ACTIVITY; | ||
}; | ||
|
||
export type BaseDataForCalculation = { | ||
defaultAssumptions: ModelAssumptions[]; | ||
baseData: BaseDataView; | ||
}; | ||
|
||
@Injectable() | ||
export class CalculationEngine {} | ||
export class CalculationEngine { | ||
constructor(private readonly dataSource: DataSource) {} | ||
|
||
async getBaseData(filter: GetBaseData): Promise<BaseDataForCalculation> { | ||
return this.dataSource.transaction(async (manager) => { | ||
const defaultAssumptions = await manager | ||
.getRepository(ModelAssumptions) | ||
.find(); | ||
const baseData = await manager.getRepository(BaseDataView).findOne({ | ||
where: { | ||
country_code: filter.countryCode, | ||
ecosystem: filter.ecosystem, | ||
activity: filter.activity, | ||
}, | ||
}); | ||
return { | ||
defaultAssumptions, | ||
baseData, | ||
}; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { AppBaseService } from '@api/utils/app-base.service'; | ||
import { CreateCustomProjectDto } from '@shared/dtos/custom-projects/create-custom-project.dto'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Project } from '@shared/entities/projects.entity'; | ||
import { Repository } from 'typeorm'; | ||
import { CustomProject } from '@shared/entities/custom-project.entity'; | ||
import { CalculationEngine } from '@api/modules/calculations/calculation.engine'; | ||
|
||
@Injectable() | ||
export class CustomProjectsService {} | ||
export class CustomProjectsService extends AppBaseService< | ||
CustomProject, | ||
CreateCustomProjectDto, | ||
unknown, | ||
unknown | ||
> { | ||
constructor( | ||
@InjectRepository(CustomProject) | ||
public readonly repo: Repository<CustomProject>, | ||
public readonly calculationEngine: CalculationEngine, | ||
) { | ||
super(repo, 'customProject', 'customProjects'); | ||
} | ||
|
||
async create(dto: CreateCustomProjectDto): Promise<any> { | ||
const { countryCode, ecosystem, activity } = dto; | ||
return this.calculationEngine.getBaseData({ | ||
countryCode, | ||
ecosystem, | ||
activity, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters