Skip to content

Commit

Permalink
feat(hero): add equippedItem column in hero typeorm entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Chabardes committed May 24, 2022
1 parent b90e369 commit 7e57384
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions migrations/1653392427820-AlterHeroTableAddEquippedItemColumn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class AlterHeroTableAddEquippedItemColumn1653392427820 implements MigrationInterface {
name = 'AlterHeroTableAddEquippedItemColumn1653392427820'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "hero" ADD "equippedItem" character varying`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "hero" DROP COLUMN "equippedItem"`);
}

}
3 changes: 3 additions & 0 deletions src/heroes/infrastructure/typeorm/hero.orm-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ export class Hero extends BaseOrmEntity {

@OneToMany(() => Item, (item: Item) => item.owner)
items!: Item[] | null;

@Column({ type: 'varchar', nullable: true })
equippedItem?: Item['id'] | undefined;
}
1 change: 1 addition & 0 deletions src/heroes/infrastructure/typeorm/hero.orm-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const mapHeroOrmEntityToHeroEntity = (
xp: +heroOrmEntity.xp,
level: +heroOrmEntity.level,
currentHp: +heroOrmEntity.currentHp,
equippedItem: heroOrmEntity.equippedItem,
};
};

0 comments on commit 7e57384

Please # to comment.