-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd789bc
commit 91e8aa5
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
content/src/controller/handlers/active-entities-ids-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Entity, 'id' | 'pointers'>[] }> { | ||
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<Entity, 'id' | 'pointers'>[] = (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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters