refactor( iam ): replace userId FK with iamUserId on UserPreferences, Device, FraudAlert

This commit is contained in:
Abubeker Yasin
2026-06-08 15:49:42 +03:00
parent c1dcfb04c3
commit 8c377e86d8
6 changed files with 37 additions and 29 deletions

View File

@@ -166,20 +166,21 @@ export class NotificationsService {
private async getUserPreferredChannels(recipient: string): Promise<NotificationChannelType[]> {
const user = await this.prisma.user.findFirst({
where: {
OR: [{ id: recipient }, { email: recipient }, { phone: recipient }],
},
include: { preferences: true },
where: { OR: [{ id: recipient }, { email: recipient }, { phone: recipient }] },
include: { passenger: { select: { iamUserId: true } } },
});
if (!user?.preferences) {
const iamUserId = user?.passenger?.iamUserId ?? recipient;
const preferences = await this.prisma.userPreferences.findUnique({ where: { iamUserId } });
if (!preferences) {
return ['IN_APP', 'EMAIL'];
}
const channels: NotificationChannelType[] = ['IN_APP'];
if (user.preferences.emailEnabled) channels.push('EMAIL');
if (user.preferences.smsEnabled) channels.push('SMS');
if (user.preferences.pushEnabled) channels.push('PUSH');
if (preferences.emailEnabled) channels.push('EMAIL');
if (preferences.smsEnabled) channels.push('SMS');
if (preferences.pushEnabled) channels.push('PUSH');
return channels;
}