From 1b1e9bf1cb06c0fd7f2ceb5f3b2c8f326d4342c7 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 9 Oct 2023 15:35:01 +0300 Subject: [PATCH 1/2] Update marketplace key and add contraints --- src/db/marketplaces/marketplace.entity.ts | 2 +- .../1696854100026-UpdateMarketplaceKeyLength.ts | 13 +++++++++++++ src/modules/marketplaces/marketplaces.service.ts | 3 ++- .../marketplaces/models/UpdateMarketplaceArgs.ts | 5 +++++ .../marketplaces/models/WhitelistCollectionArgs.ts | 3 ++- .../marketplaces/models/WhitelistMarketplaceArgs.ts | 5 +++++ 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/db/migrations/1696854100026-UpdateMarketplaceKeyLength.ts diff --git a/src/db/marketplaces/marketplace.entity.ts b/src/db/marketplaces/marketplace.entity.ts index aec7fc2b6..fc3c12847 100644 --- a/src/db/marketplaces/marketplace.entity.ts +++ b/src/db/marketplaces/marketplace.entity.ts @@ -12,7 +12,7 @@ export class MarketplaceEntity extends BaseEntity { @Column({ length: 62 }) name: string; - @Column({ length: 20, unique: true }) + @Column({ length: 62, unique: true }) key: string; @Column() diff --git a/src/db/migrations/1696854100026-UpdateMarketplaceKeyLength.ts b/src/db/migrations/1696854100026-UpdateMarketplaceKeyLength.ts new file mode 100644 index 000000000..fb5935cf8 --- /dev/null +++ b/src/db/migrations/1696854100026-UpdateMarketplaceKeyLength.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class UpdateMarketplaceKeyLength1696854100026 implements MigrationInterface { + name = 'UpdateMarketplaceKeyLength1696854100026'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`marketplaces\` MODIFY COLUMN \`key\` varchar(62) NOT NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`marketplaces\` MODIFY COLUMN \`key\` varchar(20) NOT NULL`); + } +} diff --git a/src/modules/marketplaces/marketplaces.service.ts b/src/modules/marketplaces/marketplaces.service.ts index dc26cb6ed..d65ca3c1f 100644 --- a/src/modules/marketplaces/marketplaces.service.ts +++ b/src/modules/marketplaces/marketplaces.service.ts @@ -13,6 +13,7 @@ import { WhitelistMarketplaceRequest } from './models/requests/WhitelistMarketpl import { UpdateMarketplaceRequest } from './models/requests/UpdateMarketplaceRequest'; import { CacheEventsPublisherService } from '../rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service'; import { ChangedEvent, CacheEventTypeEnum } from '../rabbitmq/cache-invalidation/events/changed.event'; +import { mxConfig } from 'src/config'; @Injectable() export class MarketplacesService { @@ -189,7 +190,7 @@ export class MarketplacesService { const savedMarketplace = await this.persistenceService.saveMarketplace( new MarketplaceEntity({ key: request.marketplaceKey, - address: request.marketplaceScAddress, + address: request.marketplaceScAddress ?? mxConfig.nftMarketplaceAddress, name: request.marketplaceName, url: request.marketplaceUrl, type: MarketplaceTypeEnum.Internal, diff --git a/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts b/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts index 9c22c1fb6..6ab9aab47 100644 --- a/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts +++ b/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts @@ -1,7 +1,10 @@ import { Field, InputType } from '@nestjs/graphql'; +import { IsOptional, Matches, Max } from 'class-validator'; +import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; @InputType() export class UpdateMarketplaceArgs { + @Max(62) @Field({ description: 'This field will be shown on external apps like xSpothlight, xPortal!', nullable: true }) marketplaceName: string; @@ -12,5 +15,7 @@ export class UpdateMarketplaceArgs { marketplaceUrl: string; @Field({ description: 'Smart Contract Address, if not sent the default one will be used', nullable: true }) + @IsOptional() + @Matches(RegExp(ADDRESS_RGX), { message: ADDRESS_ERROR }) marketplaceScAddress: string; } diff --git a/src/modules/marketplaces/models/WhitelistCollectionArgs.ts b/src/modules/marketplaces/models/WhitelistCollectionArgs.ts index 009d9859f..7ce5e33b1 100644 --- a/src/modules/marketplaces/models/WhitelistCollectionArgs.ts +++ b/src/modules/marketplaces/models/WhitelistCollectionArgs.ts @@ -1,5 +1,5 @@ import { Field, InputType } from '@nestjs/graphql'; -import { Matches } from 'class-validator'; +import { Matches, Max } from 'class-validator'; import { COLLECTION_IDENTIFIER_ERROR, COLLECTION_IDENTIFIER_RGX } from 'src/utils/constants'; @InputType() @@ -10,6 +10,7 @@ export class WhitelistCollectionArgs { @Field() collection: string; + @Max(62) @Field() marketplaceKey: string; } diff --git a/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts b/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts index 7edce9bed..36d03578b 100644 --- a/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts +++ b/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts @@ -1,10 +1,13 @@ import { Field, InputType } from '@nestjs/graphql'; +import { IsOptional, Matches, Max } from 'class-validator'; +import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; @InputType() export class WhitelistMarketplaceArgs { @Field({ description: 'This field will be shown on external apps like xSpothlight, xPortal!' }) marketplaceName: string; + @Max(62) @Field({ description: 'This should de a unique key, so choose wisely!' }) marketplaceKey: string; @@ -12,5 +15,7 @@ export class WhitelistMarketplaceArgs { marketplaceUrl: string; @Field({ description: 'Smart Contract Address, if not sent the default one will be used', nullable: true }) + @IsOptional() + @Matches(RegExp(ADDRESS_RGX), { message: ADDRESS_ERROR }) marketplaceScAddress: string; } From 95d7b49f3666b6b2c0e500442956dd651db8eff1 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 9 Oct 2023 16:10:38 +0300 Subject: [PATCH 2/2] Fix max validation --- src/modules/marketplaces/models/UpdateMarketplaceArgs.ts | 5 +++-- src/modules/marketplaces/models/WhitelistCollectionArgs.ts | 4 ++-- src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts b/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts index 6ab9aab47..fd8c8f481 100644 --- a/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts +++ b/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts @@ -1,10 +1,11 @@ import { Field, InputType } from '@nestjs/graphql'; -import { IsOptional, Matches, Max } from 'class-validator'; +import { IsOptional, Matches, Max, MaxLength } from 'class-validator'; import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; @InputType() export class UpdateMarketplaceArgs { - @Max(62) + @IsOptional() + @MaxLength(62) @Field({ description: 'This field will be shown on external apps like xSpothlight, xPortal!', nullable: true }) marketplaceName: string; diff --git a/src/modules/marketplaces/models/WhitelistCollectionArgs.ts b/src/modules/marketplaces/models/WhitelistCollectionArgs.ts index 7ce5e33b1..33a042071 100644 --- a/src/modules/marketplaces/models/WhitelistCollectionArgs.ts +++ b/src/modules/marketplaces/models/WhitelistCollectionArgs.ts @@ -1,5 +1,5 @@ import { Field, InputType } from '@nestjs/graphql'; -import { Matches, Max } from 'class-validator'; +import { Matches, MaxLength } from 'class-validator'; import { COLLECTION_IDENTIFIER_ERROR, COLLECTION_IDENTIFIER_RGX } from 'src/utils/constants'; @InputType() @@ -10,7 +10,7 @@ export class WhitelistCollectionArgs { @Field() collection: string; - @Max(62) + @MaxLength(62) @Field() marketplaceKey: string; } diff --git a/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts b/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts index 36d03578b..9d21593d7 100644 --- a/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts +++ b/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts @@ -1,5 +1,5 @@ import { Field, InputType } from '@nestjs/graphql'; -import { IsOptional, Matches, Max } from 'class-validator'; +import { IsOptional, Matches, MaxLength } from 'class-validator'; import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; @InputType() @@ -7,7 +7,7 @@ export class WhitelistMarketplaceArgs { @Field({ description: 'This field will be shown on external apps like xSpothlight, xPortal!' }) marketplaceName: string; - @Max(62) + @MaxLength(62) @Field({ description: 'This should de a unique key, so choose wisely!' }) marketplaceKey: string;