Skip to content

Commit

Permalink
Add remove whitelist collection
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Oct 25, 2023
1 parent 606bf50 commit 34e63f3
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 14 deletions.
6 changes: 6 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ type Mutation {
removeBlacklistedCollection(collection: String!): Boolean!
removeFeaturedCollection(input: FeaturedCollectionsArgs!): Boolean!
removeLike(input: RemoveLikeArgs!): Boolean!
removeWhitelistCollection(input: RemoveWhitelistCollectionArgs!): Boolean!
reportCollection(
"""This endpoint can be used to report a Collection"""
input: ReportCollectionInput!
Expand Down Expand Up @@ -1341,6 +1342,11 @@ input RemoveLikeArgs {
identifier: String!
}

input RemoveWhitelistCollectionArgs {
collection: String!
marketplaceKey: String!
}

input ReportCollectionInput {
collectionIdentifier: String!
}
Expand Down
18 changes: 13 additions & 5 deletions src/common/persistence/persistence.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ export class PersistenceService {
this.marketplaceCollectionsRepository.getMarketplaceByKeyAndCollection(collection, key),
);
}

async getCollectionByKeyAndCollection(collection: string, key: string): Promise<MarketplaceCollectionEntity> {
return await this.execute(

Check warning on line 264 in src/common/persistence/persistence.service.ts

View check run for this annotation

Codecov / codecov/patch

src/common/persistence/persistence.service.ts#L264

Added line #L264 was not covered by tests
this.getCollectionByKeyAndCollection.name,
this.marketplaceCollectionsRepository.getCollectionByKeyAndCollection(collection, key),
);
}
async getAllMarketplaceCollections(): Promise<MarketplaceCollectionEntity[]> {
return await this.execute(this.getAllMarketplaceCollections.name, this.marketplaceCollectionsRepository.getAllCollections());
}
Expand All @@ -277,11 +284,12 @@ export class PersistenceService {
);
}

async saveMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<MarketplaceCollectionEntity> {
return await this.execute(
this.getCollectionsByMarketplace.name,
this.marketplaceCollectionsRepository.saveMarketplaceCollection(entity),
);
async saveMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<boolean> {
return await this.execute(this.saveMarketplaceCollection.name, this.marketplaceCollectionsRepository.saveMarketplaceCollection(entity));

Check warning on line 288 in src/common/persistence/persistence.service.ts

View check run for this annotation

Codecov / codecov/patch

src/common/persistence/persistence.service.ts#L288

Added line #L288 was not covered by tests
}

async deleteMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<MarketplaceCollectionEntity> {
return this.execute(this.deleteMarketplaceCollection.name, this.marketplaceCollectionsRepository.deleteMarketplaceCollection(entity));

Check warning on line 292 in src/common/persistence/persistence.service.ts

View check run for this annotation

Codecov / codecov/patch

src/common/persistence/persistence.service.ts#L292

Added line #L292 was not covered by tests
}

async saveMarketplace(entity: MarketplaceEntity): Promise<MarketplaceEntity> {
Expand Down
26 changes: 23 additions & 3 deletions src/db/marketplaces/marketplace-collections.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { DeleteResult, Repository } from 'typeorm';
import { MarketplaceCollectionEntity } from './marketplace-collection.entity';
import { MarketplaceEntity } from './marketplace.entity';

Expand Down Expand Up @@ -87,7 +87,27 @@ export class MarketplaceCollectionsRepository {
.execute();
}

async saveMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<MarketplaceCollectionEntity> {
return await this.marketplaceCollectionRepository.save(entity);
async getCollectionByIdentifier(collectionIdentifier: string): Promise<MarketplaceCollectionEntity> {
return this.marketplaceCollectionRepository.findOne({

Check warning on line 91 in src/db/marketplaces/marketplace-collections.repository.ts

View check run for this annotation

Codecov / codecov/patch

src/db/marketplaces/marketplace-collections.repository.ts#L91

Added line #L91 was not covered by tests
where: [{ collectionIdentifier: collectionIdentifier }],
});
}

async getCollectionByKeyAndCollection(collection: string, key: string): Promise<MarketplaceCollectionEntity> {
return this.marketplaceCollectionRepository

Check warning on line 97 in src/db/marketplaces/marketplace-collections.repository.ts

View check run for this annotation

Codecov / codecov/patch

src/db/marketplaces/marketplace-collections.repository.ts#L97

Added line #L97 was not covered by tests
.createQueryBuilder('mc')
.select('mc.*')
.leftJoin('mc.marketplaces', 'm')
.where(`collectionIdentifier = '${collection}' and m.key= '${key}'`)
.execute();
}

async saveMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<boolean> {
const result = await this.marketplaceCollectionRepository.save(entity);

Check warning on line 106 in src/db/marketplaces/marketplace-collections.repository.ts

View check run for this annotation

Codecov / codecov/patch

src/db/marketplaces/marketplace-collections.repository.ts#L106

Added line #L106 was not covered by tests
return result ? true : false;
}

async deleteMarketplaceCollection(entity: MarketplaceCollectionEntity): Promise<MarketplaceCollectionEntity> {
return await this.marketplaceCollectionRepository.remove(entity);

Check warning on line 111 in src/db/marketplaces/marketplace-collections.repository.ts

View check run for this annotation

Codecov / codecov/patch

src/db/marketplaces/marketplace-collections.repository.ts#L111

Added line #L111 was not covered by tests
}
}
6 changes: 5 additions & 1 deletion src/modules/analytics/collections-analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export class CollectionsAnalyticsService {
return await this.analyticsGetter.getVolumeDataForTimePeriod(time, series, metric);
}

public async getFloorPriceVolumeForTimePeriod(time: string, series: string, metric: string): Promise<AnalyticsAggregateValue[]> {
public async getFloorPriceVolumeForTimePeriod(
time: string,
series: string,
metric: string = 'floorPriceUSD',
): Promise<AnalyticsAggregateValue[]> {
return await this.analyticsGetter.getFloorPriceForTimePeriod(time, series, metric);
}

Expand Down
10 changes: 8 additions & 2 deletions src/modules/marketplaces/marketplaces-mutations.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Resolver, Args, Mutation } from '@nestjs/graphql';
import { BaseResolver } from '../common/base.resolver';
import { Marketplace } from './models';
import { MarketplacesService } from './marketplaces.service';
import { WhitelistCollectionArgs } from './models/WhitelistCollectionArgs';
import { WhitelistCollectionRequest } from './models/requests/WhitelistCollectionOnMarketplaceRequest';
import { RemoveWhitelistCollectionArgs, WhitelistCollectionArgs } from './models/WhitelistCollectionArgs';
import { RemoveWhitelistCollectionRequest, WhitelistCollectionRequest } from './models/requests/WhitelistCollectionOnMarketplaceRequest';
import { WhitelistMarketplaceArgs } from './models/WhitelistMarketplaceArgs';
import { WhitelistMarketplaceRequest } from './models/requests/WhitelistMarketplaceRequest';
import { UseGuards } from '@nestjs/common';
Expand All @@ -24,6 +24,12 @@ export class MarketplacesMutationsResolver extends BaseResolver(Marketplace) {
return this.marketplaceService.whitelistCollectionOnMarketplace(WhitelistCollectionRequest.fromArgs(input));
}

@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard)
async removeWhitelistCollection(@Args('input') input: RemoveWhitelistCollectionArgs): Promise<Boolean> {
return this.marketplaceService.removeWhitelistCollection(RemoveWhitelistCollectionRequest.fromArgs(input));
}

@Mutation(() => Boolean)
@UseGuards(JwtOrNativeAuthGuard, GqlAdminAuthGuard)
async updateMarketplace(@Args('input') input: UpdateMarketplaceArgs): Promise<Boolean> {
Expand Down
30 changes: 28 additions & 2 deletions src/modules/marketplaces/marketplaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MarketplaceCollectionEntity, MarketplaceEntity } from 'src/db/marketpla
import { MarketplaceTypeEnum } from './models/MarketplaceType.enum';
import { MarketplaceFilters } from './models/Marketplace.Filter';
import { PersistenceService } from 'src/common/persistence/persistence.service';
import { WhitelistCollectionRequest } from './models/requests/WhitelistCollectionOnMarketplaceRequest';
import { RemoveWhitelistCollectionRequest, WhitelistCollectionRequest } from './models/requests/WhitelistCollectionOnMarketplaceRequest';
import { BadRequestError } from 'src/common/models/errors/bad-request-error';
import { WhitelistMarketplaceRequest } from './models/requests/WhitelistMarketplaceRequest';
import { UpdateMarketplaceRequest } from './models/requests/UpdateMarketplaceRequest';
Expand Down Expand Up @@ -180,7 +180,7 @@ export class MarketplacesService {
if (savedCollection) {
this.triggerCacheInvalidation(request.marketplaceKey, request.collection, marketplace.address);
}
return savedCollection ? true : false;
return savedCollection;
} catch (error) {
this.logger.error('An error has occured while whitelisting collection', {
path: this.whitelistCollectionOnMarketplace.name,
Expand All @@ -192,6 +192,32 @@ export class MarketplacesService {
}
}

async removeWhitelistCollection(request: RemoveWhitelistCollectionRequest): Promise<Boolean> {
const collection = await this.persistenceService.getCollectionByKeyAndCollection(request.collection, request.marketplaceKey);
const marketplace = await this.persistenceService.getMarketplaceByKey(request.marketplaceKey);

Check warning on line 197 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L196-L197

Added lines #L196 - L197 were not covered by tests

if (!collection || !marketplace) {
throw new BadRequestError('Marketplace not available for this key, choose another key if this is not your marketplace');

Check warning on line 200 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L200

Added line #L200 was not covered by tests
}
try {
const removedCollection = await this.persistenceService.deleteMarketplaceCollection(collection);

Check warning on line 203 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L202-L203

Added lines #L202 - L203 were not covered by tests

if (removedCollection) {
this.triggerCacheInvalidation(request.marketplaceKey, request.collection, marketplace.address);

Check warning on line 206 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L206

Added line #L206 was not covered by tests
}
return removedCollection ? true : false;
} catch (error) {
console.log({ error });
this.logger.error('An error has occured while remove whitelist for collection', {

Check warning on line 211 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L210-L211

Added lines #L210 - L211 were not covered by tests
path: this.whitelistCollectionOnMarketplace.name,
collection: request?.collection,
marketplace: request?.marketplaceKey,
exception: error,
});
return false;

Check warning on line 217 in src/modules/marketplaces/marketplaces.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/marketplaces.service.ts#L217

Added line #L217 was not covered by tests
}
}

async whitelistMarketplace(request: WhitelistMarketplaceRequest): Promise<Boolean> {
const marketplace = await this.persistenceService.getMarketplaceByKey(request.marketplaceKey);
if (marketplace) {
Expand Down
13 changes: 13 additions & 0 deletions src/modules/marketplaces/models/WhitelistCollectionArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ export class WhitelistCollectionArgs {
@Field()
marketplaceKey: string;
}

@InputType()
export class RemoveWhitelistCollectionArgs {
@Matches(RegExp(COLLECTION_IDENTIFIER_RGX), {
message: COLLECTION_IDENTIFIER_ERROR,
})
@Field()
collection: string;

@MaxLength(62)
@Field()
marketplaceKey: string;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WhitelistCollectionArgs } from '../WhitelistCollectionArgs';
import { RemoveWhitelistCollectionArgs, WhitelistCollectionArgs } from '../WhitelistCollectionArgs';

export class WhitelistCollectionRequest {
collection: string;
Expand All @@ -14,3 +14,18 @@ export class WhitelistCollectionRequest {
});
}
}

export class RemoveWhitelistCollectionRequest {
collection: string;
marketplaceKey: string;
constructor(init?: Partial<RemoveWhitelistCollectionRequest>) {
Object.assign(this, init);

Check warning on line 22 in src/modules/marketplaces/models/requests/WhitelistCollectionOnMarketplaceRequest.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/models/requests/WhitelistCollectionOnMarketplaceRequest.ts#L22

Added line #L22 was not covered by tests
}

static fromArgs(args: RemoveWhitelistCollectionArgs) {
return new RemoveWhitelistCollectionRequest({

Check warning on line 26 in src/modules/marketplaces/models/requests/WhitelistCollectionOnMarketplaceRequest.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/marketplaces/models/requests/WhitelistCollectionOnMarketplaceRequest.ts#L26

Added line #L26 was not covered by tests
collection: args.collection,
marketplaceKey: args.marketplaceKey,
});
}
}

0 comments on commit 34e63f3

Please sign in to comment.