Skip to content

Commit 48495c8

Browse files
authored
Merge pull request #1203 from garvthakre/add-jsdoc
docs: add missing JSDoc in utils.js
2 parents 69b668f + 7e37f33 commit 48495c8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/api/helpers/utils.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@ export function allowOnlyGetMethod(req, res, next) {
4545
.send({message: `${req.method} method for the "${req.path}" route is not supported. Only GET method is allowed`});
4646
}
4747

48+
/**
49+
* getBrowsedRelationships is a function to fetch and format relationships between entities
50+
* based on a specific entity type being browsed
51+
*
52+
* @param {object} orm - BookBrainz ORM instance
53+
* @param {object} locals - response locals containing entity and relationships data
54+
* @param {string} browsedEntityType - The type of entity being browsed (e.g.,'author','edition','work')
55+
* @param {Function} getEntityInfoMethod - function to format entity data (e.g., getAuthorBasicInfo)
56+
* @param {string[]} fetchRelated - array of relations to fetch for the entity
57+
* @param {Function} filterRelationshipMethod - function to filter relationships based on query parameters
58+
* @returns {Promise<Array>} -list of objects,each with:
59+
* entity: the formatted related entity
60+
* relationships: an array of relationship descriptors :
61+
* { relationshipType:string|null,relationshipTypeId: number|null}
62+
* returns an empty array if no relationships match with filter.
63+
*
64+
* @example
65+
* const authorRelationships = await getBrowsedRelationships(
66+
* orm ,
67+
* res.locals,
68+
* 'Author',
69+
* getAuthorBasicInfo,
70+
* authorBasicRelations,
71+
* (entity) => entity.authorType === 'Person'
72+
* );
73+
* // => [
74+
* // {
75+
* // entity: { bbid: '...', defaultAlias: {...}, ... },
76+
* // relationships: [{ relationshipType: 'Author', relationshipTypeID: 8 }]
77+
* // }
78+
* // ]
79+
*/
80+
4881

4982
export async function getBrowsedRelationships(orm, locals, browsedEntityType,
5083
getEntityInfoMethod, fetchRelated, filterRelationshipMethod) {

0 commit comments

Comments
 (0)