Skip to content

Commit

Permalink
Merge pull request #1039 from multiversx/SERVICES-1882-upgrade-market…
Browse files Browse the repository at this point in the history
…place-key-type

Update marketplace key and add contraints
  • Loading branch information
danielailie authored Oct 10, 2023
2 parents d01bfad + 95d7b49 commit 4f3d467
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/db/marketplaces/marketplace.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions src/db/migrations/1696854100026-UpdateMarketplaceKeyLength.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class UpdateMarketplaceKeyLength1696854100026 implements MigrationInterface {
name = 'UpdateMarketplaceKeyLength1696854100026';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`marketplaces\` MODIFY COLUMN \`key\` varchar(62) NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`marketplaces\` MODIFY COLUMN \`key\` varchar(20) NOT NULL`);
}
}
3 changes: 2 additions & 1 deletion src/modules/marketplaces/marketplaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/modules/marketplaces/models/UpdateMarketplaceArgs.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion src/modules/marketplaces/models/WhitelistCollectionArgs.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -10,6 +10,7 @@ export class WhitelistCollectionArgs {
@Field()
collection: string;

@MaxLength(62)
@Field()
marketplaceKey: string;
}
5 changes: 5 additions & 0 deletions src/modules/marketplaces/models/WhitelistMarketplaceArgs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
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;

@Field({ description: 'This will be used to redirect from external apps!' })
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;
}

0 comments on commit 4f3d467

Please sign in to comment.