feat(SPG-773): set item name to unique #53

Merged
firmanr merged 1 commits from fix/bug-firman into development 2024-08-06 05:48:50 +00:00
3 changed files with 31 additions and 2 deletions

View File

@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class UniqueNameItem1722922766205 implements MigrationInterface {
name = 'UniqueNameItem1722922766205';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86"`,
);
await queryRunner.query(
`ALTER TABLE "items" ADD CONSTRAINT "UQ_213736582899b3599acaade2cd1" UNIQUE ("name")`,
);
await queryRunner.query(
`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86" FOREIGN KEY ("item_bundling_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "item_bundlings" DROP CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86"`,
);
await queryRunner.query(
`ALTER TABLE "items" DROP CONSTRAINT "UQ_213736582899b3599acaade2cd1"`,
);
await queryRunner.query(
`ALTER TABLE "item_bundlings" ADD CONSTRAINT "FK_a50e7abf2caba4d0394f3726b86" FOREIGN KEY ("item_bundling_id") REFERENCES "items"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
}
}

View File

@ -22,7 +22,7 @@ export class ItemModel
extends BaseStatusModel<ItemEntity>
implements ItemEntity
{
@Column('varchar', { name: 'name' })
@Column('varchar', { name: 'name', unique: true })
name: string;
@Column('varchar', { name: 'image_url', nullable: true })

View File

@ -33,7 +33,7 @@ export class CreateItemManager extends BaseCreateManager<ItemEntity> {
}
get uniqueColumns(): columnUniques[] {
return [];
return [{ column: 'name' }];
}
get eventTopics(): EventTopics[] {