first commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using App.Core.Entities.Maintenance;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace App.Infrastructure.Data.Configurations;
|
||||
|
||||
public class WorkOrderConfiguration : IEntityTypeConfiguration<WorkOrder>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<WorkOrder> builder)
|
||||
{
|
||||
builder.Property(w => w.GeneratedForOccurrenceKey).HasMaxLength(50);
|
||||
|
||||
// Anti-doublon de génération du MaintenanceSchedulingEngine : un seul OT par occurrence
|
||||
// d'une gamme donnée, quel que soit son statut. Filtré (pas d'index sur les OT curatifs,
|
||||
// qui ont MaintenancePlanId = null).
|
||||
builder.HasIndex(w => new { w.MaintenancePlanId, w.GeneratedForOccurrenceKey })
|
||||
.IsUnique()
|
||||
.HasFilter("MaintenancePlanId IS NOT NULL");
|
||||
|
||||
builder.HasIndex(w => new { w.Status, w.ScheduledDate }); // vue calendrier / dashboard
|
||||
|
||||
builder.HasOne<App.Core.Entities.Team.User>()
|
||||
.WithMany()
|
||||
.HasForeignKey(w => w.AssignedTechnicianUserId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasMany(w => w.TaskResults)
|
||||
.WithOne(r => r.WorkOrder)
|
||||
.HasForeignKey(r => r.WorkOrderId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.HasMany(w => w.PartsUsed)
|
||||
.WithOne()
|
||||
.HasForeignKey(p => p.WorkOrderId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkOrderTaskResultConfiguration : IEntityTypeConfiguration<WorkOrderTaskResult>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<WorkOrderTaskResult> builder)
|
||||
{
|
||||
builder.HasOne<MaintenanceTask>()
|
||||
.WithMany()
|
||||
.HasForeignKey(r => r.MaintenanceTaskId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
|
||||
public class WorkOrderPartUsedConfiguration : IEntityTypeConfiguration<WorkOrderPartUsed>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<WorkOrderPartUsed> builder)
|
||||
{
|
||||
builder.HasOne<App.Core.Entities.Inventory.Part>()
|
||||
.WithMany()
|
||||
.HasForeignKey(p => p.PartId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user