Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round project power view to 2 decimals #757

Merged
merged 3 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class ProjectPowerView1662915983384 implements MigrationInterface {
export class ProjectPowerView1662915983385 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`
Expand All @@ -9,7 +9,7 @@ export class ProjectPowerView1662915983384 implements MigrationInterface {
CREATE MATERIALIZED VIEW IF NOT EXISTS public.project_power_view AS
SELECT
innerview."projectId",
innerview."totalPower",
ROUND(CAST(innerview."totalPower" as NUMERIC), 2) as "totalPower",
rank() OVER (
ORDER BY
innerview."totalPower" DESC
Expand Down
10 changes: 8 additions & 2 deletions src/views/projectPowerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
RelationId,
BaseEntity,
PrimaryColumn,
Column,
} from 'typeorm';
import { Project } from '../entities/project';
import { Field, Int, ObjectType } from 'type-graphql';
import { Field, Float, Int, ObjectType } from 'type-graphql';
import { ColumnNumericTransformer } from '../utils/entities';

@ViewEntity('project_power_view', { synchronize: false })
@ObjectType()
Expand All @@ -20,7 +22,11 @@ export class ProjectPowerView extends BaseEntity {
projectId: number;

@ViewColumn()
@Field()
@Field(type => Float)
@Column('numeric', {
scale: 2,
transformer: new ColumnNumericTransformer(),
})
totalPower: number;

@Field(type => Project)
Expand Down
4 changes: 2 additions & 2 deletions test/pre-test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { NETWORK_IDS } from '../src/provider';
import { MainCategory } from '../src/entities/mainCategory';
import { getConnection } from 'typeorm';
import { UserProjectPowerView1662877385339 } from '../migration/1662877385339-UserProjectPowerView';
import { ProjectPowerView1662915983384 } from '../migration/1662915983383-ProjectPowerView';
import { ProjectPowerView1662915983385 } from '../migration/1662915983385-ProjectPowerView';
import { TakePowerBoostingSnapshotProcedure1663594895751 } from '../migration/1663594895751-takePowerSnapshotProcedure';
import { ProjectFuturePowerView1668411738120 } from '../migration/1668411738120-ProjectFuturePowerView';
import { createGivPowerHistoricTablesProcedure1670429143091 } from '../migration/1670429143091-createGivPowerHistoricTablesProcedure';
Expand Down Expand Up @@ -299,7 +299,7 @@ async function runMigrations() {

try {
const userProjectPowerView = new UserProjectPowerView1662877385339();
const projectPowerView = new ProjectPowerView1662915983384();
const projectPowerView = new ProjectPowerView1662915983385();
const projectFuturePowerView = new ProjectFuturePowerView1668411738120();
const takeSnapshotProcedure =
new TakePowerBoostingSnapshotProcedure1663594895751();
Expand Down