feat: Implement notification preferences management for both users and agents.
This commit is contained in:
@@ -400,4 +400,45 @@ export class UsersService {
|
||||
message: `Verification ${data.status.toLowerCase()} successfully`,
|
||||
};
|
||||
}
|
||||
|
||||
// =============================================
|
||||
// NOTIFICATION PREFERENCES
|
||||
// =============================================
|
||||
|
||||
async getNotificationPreferences(userId: string) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { notificationPreferences: true },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
|
||||
// Return preferences or default empty object
|
||||
return user.notificationPreferences || { email: {}, push: {} };
|
||||
}
|
||||
|
||||
async updateNotificationPreferences(
|
||||
userId: string,
|
||||
preferences: { email?: Record<string, boolean>; push?: Record<string, boolean> },
|
||||
) {
|
||||
const user = await this.prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User not found');
|
||||
}
|
||||
|
||||
const updatedUser = await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
notificationPreferences: preferences,
|
||||
},
|
||||
select: { notificationPreferences: true },
|
||||
});
|
||||
|
||||
return updatedUser.notificationPreferences;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user