diff --git a/content/src/controller/handlers/active-entities-ids-handler.ts b/content/src/controller/handlers/active-entities-ids-handler.ts new file mode 100644 index 000000000..304288717 --- /dev/null +++ b/content/src/controller/handlers/active-entities-ids-handler.ts @@ -0,0 +1,38 @@ +import { Entity } from '@dcl/catalyst-api-specs/lib/client' +import { HandlerContextWithPath, InvalidRequestError } from '../../types' +import Joi from 'joi' + +const schema = Joi.alternatives().try( + Joi.object({ + pointers: Joi.array().items(Joi.string()).min(1).required() + }) +) + +// Method: POST +// Body: { pointers: string[]} +export async function getActiveEntitiesIdsHandler( + context: HandlerContextWithPath<'database' | 'activeEntities' | 'denylist', '/entities/active'> +): Promise<{ status: 200; body: Pick[] }> { + const { database, activeEntities, denylist } = context.components + const { error, value: body } = schema.validate(await context.request.json()) + + if (error) { + throw new InvalidRequestError( + 'pointers must be present. They must be arrays and contain at least one element. None of the elements can be empty.' + ) + } + + const entities: Pick[] = (await activeEntities.withPointers(database, body.pointers)) + .filter((result) => !denylist.isDenylisted(result.id)) + .map((entity) => { + return { + id: entity.id, + pointers: entity.pointers + } + }) + + return { + status: 200, + body: entities + } +} diff --git a/content/src/controller/routes.ts b/content/src/controller/routes.ts index 4831fa6db..9213328a4 100644 --- a/content/src/controller/routes.ts +++ b/content/src/controller/routes.ts @@ -20,6 +20,7 @@ import { getERC721EntityHandler } from './handlers/get-erc721-entity-handler' import { getDeploymentsHandler } from './handlers/get-deployments-handler' import { getChallengeHandler } from './handlers/get-challenge-handler' import { getActiveEntityIdsByDeploymentHashHandler } from './handlers/get-active-entities-by-deployment-hash-handler' +import { getActiveEntitiesIdsHandler } from './handlers/active-entities-ids-handler' // We return the entire router because it will be easier to test than a whole server export async function setupRouter({ components }: GlobalContext): Promise> { @@ -42,6 +43,7 @@ export async function setupRouter({ components }: GlobalContext): Promise