| | | 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 PendingRegistrationDbMap |
| | | 8 | | { |
| | | 9 | | public static void Configure(this EntityTypeBuilder<PendingRegistration> pending) |
| | | 10 | | { |
| | 3 | 11 | | pending.ToTable("pending_registration"); |
| | | 12 | | |
| | | 13 | | // Internal bigint Id as the key. The registrant's reference is the mailed token; an |
| | | 14 | | // administrator's is PublicId (UC-49, UC-50; §4.0). |
| | 3 | 15 | | pending.HasKey(x => x.Id); |
| | | 16 | | |
| | 3 | 17 | | pending.Property(x => x.PublicId).IsRequired(); |
| | 3 | 18 | | pending.HasIndex(x => x.PublicId).IsUnique(); |
| | | 19 | | |
| | | 20 | | // Name is bounded at 200 by the entity's [MaxLength]. Both are caller-supplied text stored before |
| | | 21 | | // any person exists, so the column matches the request's bound (PersonFieldRules). |
| | 3 | 22 | | pending.Property(x => x.Name).IsRequired(); |
| | 3 | 23 | | pending.Property(x => x.Email).IsRequired().HasMaxLength(256); |
| | 3 | 24 | | pending.Property(x => x.PasswordHash).IsRequired(); |
| | 3 | 25 | | pending.Property(x => x.Salt).IsRequired(); |
| | 3 | 26 | | pending.Property(x => x.TokenHash).IsRequired(); |
| | 3 | 27 | | pending.HasIndex(x => x.TokenHash).IsUnique(); |
| | 3 | 28 | | pending.Property(x => x.ExpiresAt).IsRequired(); |
| | 3 | 29 | | pending.Property(x => x.CreatedAt).HasDefaultValueSql("now()"); |
| | 3 | 30 | | pending.Property(x => x.FailedAttempts).HasDefaultValue(0); |
| | | 31 | | |
| | | 32 | | // A pending registration means nothing once its scope is gone (UC-05 hard delete). |
| | 3 | 33 | | pending.HasOne(x => x.Scope) |
| | 3 | 34 | | .WithMany() |
| | 3 | 35 | | .HasForeignKey(x => x.ScopeId) |
| | 3 | 36 | | .IsRequired() |
| | 3 | 37 | | .OnDelete(DeleteBehavior.Cascade); |
| | 3 | 38 | | } |
| | | 39 | | } |