MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / getMe

Method getMe

apps/api/src/api/users/users.service.ts:52–119  ·  view source on GitHub ↗
(userId: string, accountId: string)

Source from the content-addressed store, hash-verified

50 }
51
52 async getMe(userId: string, accountId: string): Promise<IMeResponse> {
53 const [user, account, activeMembership, allMemberships] = await Promise.all(
54 [
55 this.getById(userId),
56 db.query.accounts.findFirst({
57 where: and(eq(accounts.id, accountId), isNull(accounts.deletedAt)),
58 }),
59 accountsService.getActiveMembership(userId, accountId),
60 accountsService.getMembershipsForUser(userId),
61 ]
62 );
63
64 if (!user) {
65 throw ApiErrors.notFound("User");
66 }
67
68 if (!account) {
69 throw ApiErrors.notFound("Account");
70 }
71
72 if (!activeMembership) {
73 throw ApiErrors.forbidden("No active membership for the JWT account");
74 }
75
76 const features = await resolveAccountFeatures(accountId);
77 const [authProviders, hasPasswordLogin] = await Promise.all([
78 oauthAuthService.getLinkedProviders(userId),
79 oauthAuthService.hasPasswordLogin(userId),
80 ]);
81
82 const accountIds = allMemberships.map((membership) => membership.accountId);
83 const accountRows =
84 accountIds.length === 0
85 ? []
86 : await db.query.accounts.findMany({
87 where: (table, { and: andOp, inArray, isNull: isNullOp }) =>
88 andOp(inArray(table.id, accountIds), isNullOp(table.deletedAt)),
89 });
90 const accountNameMap = new Map(
91 accountRows.map((row) => [row.id, row.name])
92 );
93
94 const memberships: IMembershipSummary[] = allMemberships.map(
95 (membership) => ({
96 accountId: membership.accountId,
97 accountName: accountNameMap.get(membership.accountId) ?? "",
98 role: membership.role,
99 })
100 );
101
102 return {
103 user: toPublicUserProfile(user),
104 account: { id: account.id, name: account.name },
105 role: activeMembership.role,
106 memberships,
107 features,
108 capabilities: {
109 billing: env.BILLING_ENABLED,

Callers 2

users.routes.tsFile · 0.80

Calls 8

getByIdMethod · 0.95
resolveAccountFeaturesFunction · 0.90
toPublicUserProfileFunction · 0.90
getActiveMembershipMethod · 0.80
getMembershipsForUserMethod · 0.80
getLinkedProvidersMethod · 0.80
hasPasswordLoginMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected