| | | 1 | | using ArturRios.Heimdall.Domain.Entities; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Heimdall.Data.EntityMaps; |
| | | 6 | | |
| | | 7 | | internal static class TwoFactorRecoveryCodeDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<TwoFactorRecoveryCode> recoveryCode) |
| | | 10 | | { |
| | 3 | 11 | | recoveryCode.ToTable("two_factor_recovery_code"); |
| | | 12 | | |
| | | 13 | | // Internal bigint Id only; never addressed by ID — reached through the owning |
| | | 14 | | // TwoFactorAuth configuration. |
| | 3 | 15 | | recoveryCode.HasKey(x => x.Id); |
| | | 16 | | |
| | 3 | 17 | | recoveryCode.Property(x => x.CodeHash).IsRequired(); |
| | | 18 | | |
| | 3 | 19 | | recoveryCode.Property(x => x.Used).HasDefaultValue(false); |
| | 3 | 20 | | recoveryCode.Property(x => x.UsedAt); |
| | | 21 | | |
| | 3 | 22 | | recoveryCode.Property(x => x.CreatedAt).HasDefaultValueSql("now()"); |
| | | 23 | | |
| | | 24 | | // Codes are removed when their two-factor configuration is removed. |
| | 3 | 25 | | recoveryCode.HasOne(x => x.TwoFactorAuth) |
| | 3 | 26 | | .WithMany(t => t.RecoveryCodes) |
| | 3 | 27 | | .HasForeignKey(x => x.TwoFactorAuthId) |
| | 3 | 28 | | .IsRequired() |
| | 3 | 29 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 30 | | } |
| | | 31 | | } |