Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(dashboard): merge owned and member organizations in dashboard data
Richie McIlroyf72c23518035
diff --git a/apps/web/app/(org)/dashboard/dashboard-data.ts b/apps/web/app/(org)/dashboard/dashboard-data.tsindex 7300ecf80..c208ba248 100644--- a/apps/web/app/(org)/dashboard/dashboard-data.ts+++ b/apps/web/app/(org)/dashboard/dashboard-data.ts@@ -63,25 +63,57 @@ export type Spaces = Omit<export type UserPreferences = (typeof users.$inferSelect)["preferences"];+function mergeUserOrganizations(+ ownedOrganizations: (typeof organizations.$inferSelect)[],+ memberOrganizations: { organization: typeof organizations.$inferSelect }[],+) {+ const organizationsById = new Map<+ string,+ typeof organizations.$inferSelect+ >();++ for (const organization of ownedOrganizations) {+ organizationsById.set(organization.id, organization);+ }++ for (const { organization } of memberOrganizations) {+ organizationsById.set(organization.id, organization);+ }++ return Array.from(organizationsById.values());+}+export async function getDashboardData(user: typeof userSelectProps) {try {- const memberOrgIds = db()- .select({ id: organizationMembers.organizationId })- .from(organizationMembers)- .where(eq(organizationMembers.userId, user.id));-- const userOrganizations = await db()- .select()- .from(organizations)- .where(- and(- isNull(organizations.tombstoneAt),- or(+ const [ownedOrganizations, memberOrganizations] = await Promise.all([+ db()+ .select()+ .from(organizations)+ .where(+ and(+ isNull(organizations.tombstoneAt),eq(organizations.ownerId, user.id),- inArray(organizations.id, memberOrgIds),),),- );+ db()+ .select({ organization: organizations })+ .from(organizationMembers)+ .innerJoin(+ organizations,+ eq(organizations.id, organizationMembers.organizationId),+ )+ .where(+ and(+ eq(organizationMembers.userId, user.id),+ isNull(organizations.tombstoneAt),+ ),+ ),+ ]);++ const userOrganizations = mergeUserOrganizations(+ ownedOrganizations,+ memberOrganizations,+ );const organizationIds = userOrganizations.map((org) => org.id);