## CTE Utils System - Created comprehensive CTE (Common Table Expression) builder utilities - Supports declarative query building with automatic relation handling - Smart strategy selection between JOIN+GROUP BY and subquery patterns - Handles nested relations with automatic optimization - Type-safe query construction with Drizzle ORM ## Platform Users Enhancements - Refactored to use new CTE utils for cleaner query building - Added analytics middleware to Hono pipeline - Improved query param handling with queryStringArray helper - Changed timestamps from ISO strings to milliseconds for consistency - Extracted cleanOrgSlug utility function ## Other Improvements - Added analytics middleware for Hono routes - Enhanced base middleware with better context handling - Fixed template literal linting in initHono.ts - Updated logger for better structured logging - Added test files for CTE development ## File Changes - New: server/src/db/cteUtils/ - Complete CTE builder system - New: server/src/honoMiddlewares/analyticsMiddleware.ts - Modified: handleListPlatformUsers.ts - Refactored with CTE utils - Modified: platformModels.ts - Updated types and validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
795 B
TypeScript
30 lines
795 B
TypeScript
import { relations } from "drizzle-orm";
|
|
import { organizations } from "../models/orgModels/orgTable.js";
|
|
import { invitation, member, user } from "./auth-schema.js";
|
|
|
|
export const userRelations = relations(user, ({ many }) => ({
|
|
memberships: many(member),
|
|
}));
|
|
|
|
export const memberRelations = relations(member, ({ one }) => ({
|
|
organization: one(organizations, {
|
|
fields: [member.organizationId],
|
|
references: [organizations.id],
|
|
}),
|
|
user: one(user, {
|
|
fields: [member.userId],
|
|
references: [user.id],
|
|
}),
|
|
}));
|
|
|
|
export const inviteRelations = relations(invitation, ({ one }) => ({
|
|
organization: one(organizations, {
|
|
fields: [invitation.organizationId],
|
|
references: [organizations.id],
|
|
}),
|
|
inviter: one(user, {
|
|
fields: [invitation.inviterId],
|
|
references: [user.id],
|
|
}),
|
|
}));
|