Skip to content

Commit

Permalink
Merge pull request #1057 from multiversx/SERVICES-1959-add-marketplac…
Browse files Browse the repository at this point in the history
…e-disable-state

Services 1959 add marketplace disable state
  • Loading branch information
danielailie authored Dec 12, 2023
2 parents f40a629 + 98fd42a commit 0b6a8d9
Show file tree
Hide file tree
Showing 36 changed files with 558 additions and 115 deletions.
13 changes: 13 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ type Marketplace {
key: ID!
marketplaceCutPercentage: String
name: String!
state: MarketplaceState!
type: MarketplaceTypeEnum!
url: String!
}
Expand Down Expand Up @@ -870,6 +871,11 @@ input MarketplaceReindexDataArgs {
marketplaceAddress: String!
}

enum MarketplaceState {
Disable
Enable
}

enum MarketplaceTypeEnum {
External
Internal
Expand Down Expand Up @@ -969,6 +975,8 @@ type Mutation {
createNft(file: Upload!, input: CreateNftArgs!): TransactionNode!
createNftWithMultipleFiles(files: [Upload!]!, input: CreateNftArgs!): TransactionNode!
deployMinter(input: DeployMinterArgs!): TransactionNode!
disableMarketplace(input: UpdateMarketplaceStateArgs!): Boolean!
enableMarketplace(input: UpdateMarketplaceStateArgs!): Boolean!
endAuction(auctionId: Int!): TransactionNode!
flagCollection(input: FlagCollectionInput!): Boolean!
flagNft(input: FlagNftInput!): Boolean!
Expand Down Expand Up @@ -1494,6 +1502,11 @@ input UpdateMarketplaceArgs {
marketplaceUrl: String
}

input UpdateMarketplaceStateArgs {
"""Smart Contract Address"""
marketplaceScAddress: String!
}

enum UpdateNftTraitsResponse {
CollectionTraitsUpdated
NftTraitsUpdated
Expand Down
8 changes: 8 additions & 0 deletions src/common/persistence/persistence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ export class PersistenceService {
return await this.execute(this.saveMarketplace.name, this.marketplaceRepository.saveMarketplace(entity));
}

async saveMarketplaces(entity: MarketplaceEntity[]): Promise<MarketplaceEntity[]> {
return await this.execute(this.saveMarketplaces.name, this.marketplaceRepository.saveMarketplaces(entity));
}

async updateMarketplace(entity: MarketplaceEntity): Promise<boolean> {
return await this.execute(this.updateMarketplace.name, this.marketplaceRepository.updateMarketplace(entity));
}
Expand All @@ -309,6 +313,10 @@ export class PersistenceService {
return await this.execute(this.getMarketplaceByAddress.name, this.marketplaceRepository.getMarketplaceByAddress(address));
}

async getMarketplacesByAddress(address: string): Promise<MarketplaceEntity[]> {
return await this.execute(this.getMarketplaceByAddress.name, this.marketplaceRepository.getMarketplacesByAddress(address));
}

async getMarketplacesByKeys(marketplaceKeys: string[]): Promise<MarketplaceEntity[]> {
return await this.execute(this.getMarketplacesByKeys.name, this.marketplaceRepository.getMarketplacesByKeys(marketplaceKeys));
}
Expand Down
5 changes: 5 additions & 0 deletions src/common/services/caching/entities/cache.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,9 @@ export class CacheInfo {
key: 'account_likes_count',
ttl: 5 * Constants.oneSecond(),
};

static MarketplaceEvents: CacheInfo = {
key: 'marketplace_events',
ttl: 12 * Constants.oneMonth(),
};
}
5 changes: 4 additions & 1 deletion src/db/marketplaces/marketplace.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum';
import { MarketplaceState, MarketplaceTypeEnum } from 'src/modules/marketplaces/models/MarketplaceType.enum';
import { Column, Entity, Index, JoinTable, ManyToMany } from 'typeorm';
import { BaseEntity } from '../base-entity';
import { MarketplaceCollectionEntity } from './marketplace-collection.entity';
Expand All @@ -12,6 +12,9 @@ export class MarketplaceEntity extends BaseEntity {
@Column({ length: 62 })
name: string;

@Column({ length: 10 })
state: MarketplaceState;

@Column({ length: 62, unique: true })
key: string;

Expand Down
9 changes: 9 additions & 0 deletions src/db/marketplaces/marketplaces.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class MarketplaceRepository {
return this.marketplaceRepository.findOne({ where: { address } });
}

async getMarketplacesByAddress(address: string): Promise<MarketplaceEntity[]> {
return this.marketplaceRepository.find({ where: { address } });
}

async getMarketplacesByKeys(marketplaceKeys: string[]): Promise<MarketplaceEntity[]> {
return this.marketplaceRepository
.createQueryBuilder('marketplaces')
Expand All @@ -35,6 +39,7 @@ export class MarketplaceRepository {
.addSelect('fm.url as url')
.addSelect('fm.name as name')
.addSelect('fm.key as `key`')
.addSelect('fm.state as `state`')
.where('fm.address IN(:...addresses)', {
addresses: addresses,
})
Expand All @@ -45,6 +50,10 @@ export class MarketplaceRepository {
return this.marketplaceRepository.save(entity);
}

async saveMarketplaces(entities: MarketplaceEntity[]): Promise<MarketplaceEntity[]> {
return this.marketplaceRepository.save(entities);
}

async updateMarketplace(entity: MarketplaceEntity): Promise<boolean> {
const result = await this.marketplaceRepository.update({ key: entity.key }, entity);
return result?.affected === 1;
Expand Down
13 changes: 13 additions & 0 deletions src/db/migrations/1700660634671-AddMarketplaceState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`marketplaces\` ADD \`state\` varchar(10) NOT NULL`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`marketplaces\` DROP COLUMN \`state\``);
}
}
18 changes: 8 additions & 10 deletions src/modules/account-stats/accounts-stats.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import { MxCommunicationModule } from 'src/common';
import { AccountsStatsResolver } from './accounts-stats.resolver';
import { AccountsStatsService } from './accounts-stats.service';
import { AccountsStatsCachingService } from './accounts-stats.caching.service';
import { MarketplacesService } from '../marketplaces/marketplaces.service';
import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service';
import { CollectionsModuleGraph } from '../nftCollections/collections.module';
import { OffersModuleGraph } from '../offers/offers.module';
import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module';
import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module';

@Module({
providers: [
Logger,
AccountsStatsService,
AccountsStatsCachingService,
AccountsStatsResolver,
MarketplacesService,
MarketplacesCachingService,
providers: [Logger, AccountsStatsService, AccountsStatsCachingService, AccountsStatsResolver],
imports: [
MxCommunicationModule,
forwardRef(() => CollectionsModuleGraph),
forwardRef(() => OffersModuleGraph),
PubSubListenerModule,
MarketplacesModuleGraph,
],
imports: [MxCommunicationModule, forwardRef(() => CollectionsModuleGraph), forwardRef(() => OffersModuleGraph), PubSubListenerModule],
exports: [AccountsStatsService],
})
export class AccountsStatsModuleGraph {}
6 changes: 2 additions & 4 deletions src/modules/analytics/analytics.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { forwardRef, Module } from '@nestjs/common';
import { MxCommunicationModule } from 'src/common';
import { MarketplacesService } from '../marketplaces/marketplaces.service';
import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service';
import { AuctionsModuleGraph } from '../auctions/auctions.module';
import { CommonModule } from 'src/common.module';
import { TrendingCollectionsService } from './trending/trending-collections.service';
Expand Down Expand Up @@ -30,11 +28,10 @@ import { HoldersResolver } from './holders.resolver';
import { AccountsProvider } from '../account-stats/loaders/accounts.loader';
import { AccountsRedisHandler } from '../account-stats/loaders/accounts.redis-handler';
import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module';
import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module';

@Module({
providers: [
MarketplacesService,
MarketplacesCachingService,
TrendingCollectionsService,
ElasticAnalyticsService,
BuyEventParser,
Expand Down Expand Up @@ -66,6 +63,7 @@ import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module';
CommonModule,
forwardRef(() => AuctionsModuleGraph),
forwardRef(() => CollectionsModuleGraph),
forwardRef(() => MarketplacesModuleGraph),
TimescaleDbModule,
],
exports: [TrendingCollectionsService, ElasticAnalyticsService, AnalyticsService, GeneralAnalyticsService, CollectionsAnalyticsService],
Expand Down
7 changes: 3 additions & 4 deletions src/modules/artists/artists.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Module } from '@nestjs/common';
import { MxCommunicationModule } from 'src/common';
import { ArtistsResolver } from './artists.resolver';
import { MarketplacesService } from '../marketplaces/marketplaces.service';
import { MarketplacesCachingService } from '../marketplaces/marketplaces-caching.service';
import { ArtistsService } from './artists.service';
import { CollectionsModuleGraph } from '../nftCollections/collections.module';
import { CommonModule } from 'src/common.module';
import { PubSubListenerModule } from 'src/pubsub/pub.sub.listener.module';
import { MarketplacesModuleGraph } from '../marketplaces/marketplaces.module';

@Module({
providers: [ArtistsService, ArtistsResolver, MarketplacesService, MarketplacesCachingService],
imports: [MxCommunicationModule, CollectionsModuleGraph, CommonModule, PubSubListenerModule],
providers: [ArtistsService, ArtistsResolver],
imports: [MxCommunicationModule, CollectionsModuleGraph, CommonModule, PubSubListenerModule, MarketplacesModuleGraph],
exports: [ArtistsService],
})
export class ArtistsModuleGraph {}
21 changes: 2 additions & 19 deletions src/modules/assets/assets-getter.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common';
import { MxApiService, MxElasticService } from 'src/common';
import '../../utils/extensions';
import { AssetsLikesService } from './assets-likes.service';
Expand All @@ -19,18 +19,15 @@ import { ElasticQuery, ElasticSortOrder, QueryConditionOptions, QueryOperator, Q
import { Constants } from '@multiversx/sdk-nestjs-common';
import { RedisCacheService } from '@multiversx/sdk-nestjs-cache';
import { QueryPagination } from 'src/common/services/mx-communication/models/query-pagination';
import { FeaturedService } from '../featured/featured.service';
import { FeaturedCollectionsFilter } from '../featured/Featured-Collections.Filter';
import { FeaturedCollectionTypeEnum } from '../featured/FeatureCollectionType.enum';
import { constants } from 'src/config';
import { ELASTIC_TOKENS_INDEX } from 'src/utils/constants';

@Injectable()
export class AssetsGetterService {
constructor(
private apiService: MxApiService,
@Inject(forwardRef(() => CollectionsGetterService))
private collectionsService: CollectionsGetterService,
private featuredCollectionsService: FeaturedService,
private elasticService: MxElasticService,
private assetByIdentifierService: AssetByIdentifierService,
private assetScamLoader: AssetScamInfoProvider,
Expand Down Expand Up @@ -65,20 +62,6 @@ export class AssetsGetterService {
: this.getApiQuery(filters, offset, limit);
const apiCountQuery = this.getApiQueryForCount(filters);

if (filters.ownerAddress && filters.customFilters) {
const [ticketsCollections] = await this.featuredCollectionsService.getFeaturedCollections(
new FeaturedCollectionsFilter({ type: FeaturedCollectionTypeEnum.Tickets }),
);
if (!ticketsCollections || ticketsCollections?.length === 0) return new CollectionType<Asset>();

const ticketCollectionIdentifiers = ticketsCollections.map((x) => x.collection).toString();
return await this.getAssetsForUser(
filters.ownerAddress,
`?identifiers=${ticketCollectionIdentifiers}&from=${offset}&size=${limit}`,
`?identifiers=${ticketCollectionIdentifiers}`,
);
}

if (sorting === AssetsSortingEnum.MostLikes) {
const assets = await this.assetsLikedService.getMostLikedAssets();
return new CollectionType({
Expand Down
8 changes: 0 additions & 8 deletions src/modules/assets/models/NftTypes.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ export enum ScamInfoTypeEnum {
registerEnumType(ScamInfoTypeEnum, {
name: 'ScamInfoTypeEnum',
});

export enum CustomFiltersEnum {
Tickets = 'Tickets',
}

registerEnumType(CustomFiltersEnum, {
name: 'CustomFiltersEnum',
});
3 changes: 2 additions & 1 deletion src/modules/auctions/nft-marketplace.abi.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Logger } from '@nestjs/common';
import { Inject, Injectable, Logger, forwardRef } from '@nestjs/common';
import '../../utils/extensions';
import { AuctionAbi, BuySftActionArgs, ExternalAuctionAbi } from './models';
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -50,6 +50,7 @@ export class NftMarketplaceAbiService {
private readonly offersService: OffersService,
private readonly logger: Logger,
private readonly redisCacheService: RedisCacheService,
@Inject(forwardRef(() => MarketplacesService))
private readonly marketplaceService: MarketplacesService,
) {
this.parser = new ResultsParser();
Expand Down
6 changes: 1 addition & 5 deletions src/modules/common/filters/filtersTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NFT_IDENTIFIER_ERROR,
NFT_IDENTIFIER_RGX,
} from 'src/utils/constants';
import { CustomFiltersEnum, NftTypeEnum } from '../../assets/models/NftTypes.enum';
import { NftTypeEnum } from '../../assets/models/NftTypes.enum';

export enum Operator {
AND,
Expand Down Expand Up @@ -178,10 +178,6 @@ export class AssetsFilter {
@Field(() => NftTypeEnum, { nullable: true })
type: NftTypeEnum;

@IsOptional()
@Field(() => CustomFiltersEnum, { nullable: true })
customFilters: CustomFiltersEnum;

@Field(() => [NftTrait], { nullable: 'itemsAndList' })
traits: NftTrait[];

Expand Down
14 changes: 14 additions & 0 deletions src/modules/marketplaces/marketplaces-mutations.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { GqlAdminAuthGuard } from '../auth/gql-admin.auth-guard';
import { JwtOrNativeAuthGuard } from '../auth/jwt.or.native.auth-guard';
import { UpdateMarketplaceArgs } from './models/UpdateMarketplaceArgs';
import { UpdateMarketplaceRequest } from './models/requests/UpdateMarketplaceRequest';
import { UpdateMarketplaceStateArgs } from './models/UpdateMarketplaceStateArgs';
import { MarketplaceState } from './models/MarketplaceType.enum';

@Resolver(() => Marketplace)
export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) {
Expand Down Expand Up @@ -41,4 +43,16 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) {
async whitelistMarketplace(@Args('input') input: WhitelistMarketplaceArgs): Promise<Boolean> {
return this.marketplaceService.whitelistMarketplace(WhitelistMarketplaceRequest.fromArgs(input));
}

@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard)
async disableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise<Boolean> {
return this.marketplaceService.disableMarketplace(input.marketplaceScAddress, MarketplaceState.Disable);
}

@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard)
async enableMarketplace(@Args('input') input: UpdateMarketplaceStateArgs): Promise<Boolean> {
return this.marketplaceService.enableMarketplace(input.marketplaceScAddress, MarketplaceState.Enable);
}
}
2 changes: 2 additions & 0 deletions src/modules/marketplaces/marketplaces.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ReindexAuctionPriceUpdatedHandler } from './marketplaces-reindex-handle
import { ReindexGlobalOfferAcceptedHandler } from './marketplaces-reindex-handlers/reindex-global-offer-accepted.handler';
import { ReindexAuctionUpdatedHandler } from './marketplaces-reindex-handlers/reindex-auction-updated.handler';
import { MarketplacesMutationsResolver } from './marketplaces-mutations.resolver';
import { DisabledMarketplaceEventsModule } from '../rabbitmq/blockchain-events/disable-marketplace/disable-marketplace-events.module';

@Module({
providers: [
Expand Down Expand Up @@ -59,6 +60,7 @@ import { MarketplacesMutationsResolver } from './marketplaces-mutations.resolver
forwardRef(() => CommonModule),
forwardRef(() => AuctionsModuleGraph),
forwardRef(() => OffersModuleGraph),
forwardRef(() => DisabledMarketplaceEventsModule),
],
exports: [MarketplacesService, MarketplaceEventsIndexingService, MarketplacesReindexService],
})
Expand Down
Loading

0 comments on commit 0b6a8d9

Please sign in to comment.