@@ -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
4982export async function getBrowsedRelationships ( orm , locals , browsedEntityType ,
5083 getEntityInfoMethod , fetchRelated , filterRelationshipMethod ) {
0 commit comments