feat: member portal Sprint 1 — dashboard with MemberShell layout and TowerUser profile fields
- Add avatar, hometown, currentLocation, interests, language, digestPreference, directoryVisible fields to TowerUser - Migration: 20260617200000_add_tower_user_profile_fields - GET /my/dashboard API endpoint with stats (groups, messages, consents) - BFF route /api/my/dashboard - MemberShell 3-column layout (220px nav + flex-1 main + 280px rail) - Dashboard page: hero card, stat cards, group list, interests chips - Sidebar returns null for /my paths (MemberShell owns the nav) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "avatar" TEXT;
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "hometown" TEXT;
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "currentLocation" TEXT;
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "interests" TEXT[] NOT NULL DEFAULT '{}';
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "language" TEXT NOT NULL DEFAULT 'en';
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "digestPreference" TEXT NOT NULL DEFAULT 'daily';
|
||||
ALTER TABLE "TowerUser" ADD COLUMN "directoryVisible" BOOLEAN NOT NULL DEFAULT true;
|
||||
@@ -365,14 +365,21 @@ enum MemberOptOutReason {
|
||||
|
||||
// Hashed identity: SHA-256 of E.164 phone number (pepper via JWT_SECRET).
|
||||
model TowerUser {
|
||||
id String @id @default(cuid())
|
||||
tenantId String
|
||||
tenant Tenant @relation(fields: [tenantId], references: [id])
|
||||
phoneHash String
|
||||
jid String
|
||||
displayName String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
tenantId String
|
||||
tenant Tenant @relation(fields: [tenantId], references: [id])
|
||||
phoneHash String
|
||||
jid String
|
||||
displayName String?
|
||||
avatar String?
|
||||
hometown String?
|
||||
currentLocation String?
|
||||
interests String[]
|
||||
language String @default("en")
|
||||
digestPreference String @default("daily")
|
||||
directoryVisible Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
consents ConsentRecord[]
|
||||
optOuts MemberOptOut[]
|
||||
|
||||
@@ -24,6 +24,11 @@ class OptInDto {
|
||||
export class MyController {
|
||||
constructor(private readonly service: MyService) {}
|
||||
|
||||
@Get('dashboard')
|
||||
dashboard(@CurrentMember() member: MemberJwtPayload) {
|
||||
return this.service.getDashboard(member.sub, member.tenantId);
|
||||
}
|
||||
|
||||
@Get('profile')
|
||||
profile(@CurrentMember() member: MemberJwtPayload) {
|
||||
return this.service.getProfile(member.sub, member.tenantId);
|
||||
|
||||
@@ -26,6 +26,46 @@ export class MyService {
|
||||
};
|
||||
}
|
||||
|
||||
async getDashboard(userId: string, tenantId: string) {
|
||||
const user = await this.prisma.towerUser.findFirst({ where: { id: userId, tenantId } });
|
||||
if (!user) throw new NotFoundException('User not found');
|
||||
|
||||
const [activeConsents, messagesCount] = await Promise.all([
|
||||
this.prisma.consentRecord.findMany({
|
||||
where: { userId, tenantId, status: 'GRANTED' },
|
||||
include: { group: { select: { id: true, name: true } } },
|
||||
}),
|
||||
this.prisma.message.count({ where: { senderTowerUserId: userId, tenantId } }),
|
||||
]);
|
||||
|
||||
return {
|
||||
profile: {
|
||||
id: user.id,
|
||||
jid: user.jid,
|
||||
displayName: user.displayName,
|
||||
avatar: user.avatar,
|
||||
hometown: user.hometown,
|
||||
currentLocation: user.currentLocation,
|
||||
interests: user.interests,
|
||||
language: user.language,
|
||||
digestPreference: user.digestPreference,
|
||||
directoryVisible: user.directoryVisible,
|
||||
createdAt: user.createdAt.toISOString(),
|
||||
},
|
||||
stats: {
|
||||
groupsJoined: activeConsents.length,
|
||||
messagesContributed: messagesCount,
|
||||
activeConsents: activeConsents.length,
|
||||
},
|
||||
groups: activeConsents.map((c) => ({
|
||||
id: c.group.id,
|
||||
name: c.group.name,
|
||||
joinedAt: c.effectiveAt.toISOString(),
|
||||
consentStatus: c.status,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
async listGroups(userId: string, tenantId: string): Promise<MemberGroupSummary[]> {
|
||||
const consents = await this.prisma.consentRecord.findMany({
|
||||
where: { userId, tenantId },
|
||||
|
||||
Reference in New Issue
Block a user