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..fd8c8f481 100644 --- a/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts +++ b/src/modules/marketplaces/models/UpdateMarketplaceArgs.ts @@ -1,7 +1,11 @@ import { Field, InputType } from '@nestjs/graphql'; +import { IsOptional, Matches, Max, MaxLength } from 'class-validator'; +import { ADDRESS_RGX, ADDRESS_ERROR } from 'src/utils/constants'; @InputType() export class UpdateMarketplaceArgs { + @IsOptional() + @MaxLength(62) @Field({ description: 'This field will be shown on external apps like xSpothlight, xPortal!', nullable: true }) marketplaceName: string; @@ -12,5 +16,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..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 } from 'class-validator'; +import { Matches, MaxLength } 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; + @MaxLength(62) @Field() marketplaceKey: string; } diff --git a/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts b/src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts index 7edce9bed..9d21593d7 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, MaxLength } 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; + @MaxLength(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; }