ride reconcilation with driver profile update
This commit is contained in:
@@ -98,6 +98,56 @@ public class DriverProfileService(IDriverProfileRepository repo, IUnitOfWork uow
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<DriverComplianceConfigResponse?> GetComplianceConfigAsync()
|
||||
{
|
||||
var config = await repo.GetComplianceConfigAsync();
|
||||
return config is null ? null
|
||||
: new DriverComplianceConfigResponse(
|
||||
config.Id, config.EnforceLicenseExpiry, config.EnforceMedicalClearance,
|
||||
config.UpdatedAt, config.UpdatedBy);
|
||||
}
|
||||
|
||||
public async Task<DriverComplianceConfigResponse> UpsertComplianceConfigAsync(
|
||||
UpdateDriverComplianceConfigRequest request, Guid updatedBy, CancellationToken ct = default)
|
||||
{
|
||||
var config = await repo.GetComplianceConfigAsync();
|
||||
|
||||
await uow.BeginAsync(ct);
|
||||
try
|
||||
{
|
||||
if (config is null)
|
||||
{
|
||||
config = new global::Distribution.Models.DriverComplianceConfig
|
||||
{
|
||||
EnforceLicenseExpiry = request.EnforceLicenseExpiry,
|
||||
EnforceMedicalClearance = request.EnforceMedicalClearance,
|
||||
UpdatedBy = updatedBy,
|
||||
UpdatedAt = DateTime.Now
|
||||
};
|
||||
await repo.AddComplianceConfigAsync(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
config.EnforceLicenseExpiry = request.EnforceLicenseExpiry;
|
||||
config.EnforceMedicalClearance = request.EnforceMedicalClearance;
|
||||
config.UpdatedBy = updatedBy;
|
||||
config.UpdatedAt = DateTime.Now;
|
||||
repo.UpdateComplianceConfig(config);
|
||||
}
|
||||
|
||||
await uow.CommitAsync(ct);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await uow.RollbackAsync(ct);
|
||||
throw;
|
||||
}
|
||||
|
||||
return new DriverComplianceConfigResponse(
|
||||
config.Id, config.EnforceLicenseExpiry, config.EnforceMedicalClearance,
|
||||
config.UpdatedAt, config.UpdatedBy);
|
||||
}
|
||||
|
||||
private static DriverProfileResponse ToResponse(global::Distribution.Models.DriverProfile p) =>
|
||||
new(p.Id, p.FK_UserId, p.User?.FullName ?? string.Empty,
|
||||
p.LicenseNumber, p.LicenseExpiry, p.MedicalClearanceExpiry,
|
||||
|
||||
Reference in New Issue
Block a user