MCPcopy Create free account
hub / github.com/hashintel/hash / constructOrg

Function constructOrg

apps/hash-frontend/src/lib/user-and-org.ts:172–309  ·  view source on GitHub ↗
(params: {
  subgraph: Subgraph<EntityRootType<HashEntity>>;
  orgEntity: Entity<Organization>;
})

Source from the content-addressed store, hash-verified

170 * - hasRightEntity: { incoming: 1 }
171 */
172export const constructOrg = (params: {
173 subgraph: Subgraph<EntityRootType<HashEntity>>;
174 orgEntity: Entity<Organization>;
175}): Org => {
176 const { subgraph, orgEntity } = params;
177
178 const minimalOrg = constructMinimalOrg({
179 orgEntity,
180 });
181
182 let hasAvatar: Org["hasAvatar"];
183 let hasBio: Org["hasBio"];
184 const memberships: Org["memberships"] = [];
185 const invitations: Org["invitations"] = [];
186 const outgoingLinkAndEntities = getOutgoingLinkAndTargetEntities<
187 LinkEntityAndRightEntity<HashEntity, HashLinkEntity>[]
188 >(subgraph, orgEntity.metadata.recordId.entityId);
189
190 for (const { linkEntity, rightEntity } of outgoingLinkAndEntities) {
191 const linkEntityRevision = linkEntity[0];
192
193 if (!linkEntityRevision) {
194 continue;
195 }
196
197 const rightEntityRevision = rightEntity[0];
198
199 if (!rightEntityRevision) {
200 continue;
201 }
202
203 if (
204 linkEntityRevision.metadata.entityTypeIds.includes(
205 systemLinkEntityTypes.hasAvatar.linkEntityTypeId,
206 )
207 ) {
208 hasAvatar = {
209 linkEntity: linkEntityRevision,
210 imageEntity: rightEntityRevision as HashEntity<ImageFile>,
211 };
212 continue;
213 }
214
215 if (
216 linkEntityRevision.metadata.entityTypeIds.includes(
217 systemLinkEntityTypes.hasBio.linkEntityTypeId,
218 )
219 ) {
220 hasBio = {
221 linkEntity: linkEntityRevision,
222 profileBioEntity: rightEntityRevision as HashEntity<ProfileBio>,
223 };
224 continue;
225 }
226
227 if (
228 linkEntityRevision.metadata.entityTypeIds.includes(
229 systemLinkEntityTypes.hasIssuedInvitation.linkEntityTypeId,

Callers 3

useOrgsWithLinksFunction · 0.90
ProfilePageFunction · 0.90
constructUserFunction · 0.85

Calls 10

isInvitationByEmailFunction · 0.90
isInvitationByShortnameFunction · 0.90
getFirstEntityRevisionFunction · 0.90
constructMinimalOrgFunction · 0.85
isEntityUserEntityFunction · 0.85
constructMinimalUserFunction · 0.85
pushMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected