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

Add qfStrategy to qfRounds #1903

Merged
merged 1 commit into from
Jan 13, 2025
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
24 changes: 24 additions & 0 deletions migration/1736719823637-MarkRoundsStrategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class MarkRoundsStrategy1736719823637 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "qf_strategy_enum" AS ENUM ('cocm', 'regular');
`);

await queryRunner.query(`
ALTER TABLE "qf_round"
ADD COLUMN "qfStrategy" "qf_strategy_enum" DEFAULT 'regular';
`);
Comment on lines +9 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the migration sequence: Create enum type before using it

The migration attempts to add a column of type qf_strategy_enum before creating the enum type itself. This will fail as the type doesn't exist yet.

Apply this diff to fix the sequence:

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
-            ALTER TABLE "qf_round"
-            ADD COLUMN "qfStrategy" "qf_strategy_enum" DEFAULT 'regular';
-        `);
-    await queryRunner.query(`
            CREATE TYPE "qf_strategy_enum" AS ENUM ('cocm', 'regular');
+        `);
+    await queryRunner.query(`
+            ALTER TABLE "qf_round"
+            ADD COLUMN "qfStrategy" "qf_strategy_enum" DEFAULT 'regular';
        `);
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await queryRunner.query(`
ALTER TABLE "qf_round"
ADD COLUMN "qfStrategy" "qf_strategy_enum" DEFAULT 'regular';
`);
await queryRunner.query(`
CREATE TYPE "qf_strategy_enum" AS ENUM ('cocm', 'regular');
`);
await queryRunner.query(`
ALTER TABLE "qf_round"
ADD COLUMN "qfStrategy" "qf_strategy_enum" DEFAULT 'regular';
`);

}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "qf_round"
DROP COLUMN "qfStrategy";
`);
await queryRunner.query(`
DROP TYPE "qf_strategy_enum";
`);
}
}
27 changes: 26 additions & 1 deletion src/entities/qfRound.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Field, ID, ObjectType, Int, Float } from 'type-graphql';
import {
Field,
ID,
ObjectType,
Int,
Float,
registerEnumType,
} from 'type-graphql';
import {
PrimaryGeneratedColumn,
Column,
Expand All @@ -13,6 +20,15 @@ import {
import { Project } from './project';
import { Donation } from './donation';

export enum QfStrategyEnum {
Cocm = 'cocm',
Regular = 'regular',
}

registerEnumType(QfStrategyEnum, {
name: 'QfStrategyEnum', // Name to expose in GraphQL schema
});

@Entity()
@ObjectType()
export class QfRound extends BaseEntity {
Expand Down Expand Up @@ -89,6 +105,15 @@ export class QfRound extends BaseEntity {
@Column()
endDate: Date;

@Field(_type => QfStrategyEnum, { nullable: true })
@Column({
type: 'enum',
enum: QfStrategyEnum,
default: QfStrategyEnum.Regular,
nullable: true,
})
qfStrategy?: QfStrategyEnum;

@Field(_type => String, { nullable: true })
@Column('text', { nullable: true })
bannerBgImage: string;
Expand Down
9 changes: 9 additions & 0 deletions src/server/adminJs/tabs/qfRoundTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ export const qfRoundTab = {
show: adminJs.bundle('./components/ProjectsInQfRound'),
},
},
qfStrategy: {
isVisible: {
filter: false,
list: false,
show: true,
new: true,
edit: true,
},
},
bannerBgImage: {
isVisible: {
filter: false,
Expand Down
Loading