feat: Implement privacy preferences for users and agents with new database field, service methods, and API endpoints.
This commit is contained in:
@@ -181,6 +181,52 @@ export class AgentsController {
|
||||
return this.agentsService.updateNotificationPreferences(userId, data);
|
||||
}
|
||||
|
||||
// Privacy preferences endpoints
|
||||
|
||||
@Get('preferences/privacy')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.AGENT)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Get privacy preferences (Agents only)' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Privacy preferences retrieved',
|
||||
schema: {
|
||||
example: {
|
||||
privacySettings: {
|
||||
profile_visibility: 'public',
|
||||
contact_info: 'connections',
|
||||
activity_status: 'public',
|
||||
},
|
||||
dataSettings: {
|
||||
shareAnalytics: false,
|
||||
personalizedAds: false,
|
||||
thirdPartySharing: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
async getPrivacyPreferences(@CurrentUser('id') userId: string) {
|
||||
return this.agentsService.getPrivacyPreferences(userId);
|
||||
}
|
||||
|
||||
@Put('preferences/privacy')
|
||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||
@Roles(UserRole.AGENT)
|
||||
@ApiBearerAuth()
|
||||
@ApiOperation({ summary: 'Update privacy preferences (Agents only)' })
|
||||
@ApiResponse({ status: 200, description: 'Privacy preferences updated' })
|
||||
async updatePrivacyPreferences(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body()
|
||||
data: {
|
||||
privacySettings?: Record<string, string>;
|
||||
dataSettings?: Record<string, boolean>;
|
||||
},
|
||||
) {
|
||||
return this.agentsService.updatePrivacyPreferences(userId, data);
|
||||
}
|
||||
|
||||
// Public parameterized routes - MUST come after specific routes like profile/*
|
||||
@Get(':id')
|
||||
@Public()
|
||||
|
||||
@@ -840,4 +840,57 @@ export class AgentsService {
|
||||
|
||||
return updatedUser.notificationPreferences;
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// PRIVACY PREFERENCES
|
||||
// =============================================
|
||||
|
||||
async getPrivacyPreferences(userId: string) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { privacyPreferences: true, role: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
|
||||
if (user.role !== 'AGENT') {
|
||||
throw new BadRequestException('This endpoint is for agents only');
|
||||
}
|
||||
|
||||
// Return preferences or default empty object
|
||||
return user.privacyPreferences || { privacySettings: {}, dataSettings: {} };
|
||||
}
|
||||
|
||||
async updatePrivacyPreferences(
|
||||
userId: string,
|
||||
preferences: {
|
||||
privacySettings?: Record<string, string>;
|
||||
dataSettings?: Record<string, boolean>;
|
||||
},
|
||||
) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { role: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
|
||||
if (user.role !== 'AGENT') {
|
||||
throw new BadRequestException('This endpoint is for agents only');
|
||||
}
|
||||
|
||||
const updatedUser = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
privacyPreferences: preferences,
|
||||
},
|
||||
select: { privacyPreferences: true },
|
||||
});
|
||||
|
||||
return updatedUser.privacyPreferences;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user