Skip to content

Commit

Permalink
Sync MQ audit history
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Jan 9, 2024
1 parent 6d074cc commit 98d9157
Show file tree
Hide file tree
Showing 17 changed files with 1,340 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using TeachingRecordSystem.Core.Dqt;
using TeachingRecordSystem.Core.Events;
using TeachingRecordSystem.Core.Services.TrsDataSync;

namespace TeachingRecordSystem.Core.DataStore.Postgres.Models;

Expand All @@ -19,51 +19,6 @@ public static async Task<MandatoryQualification> MapFromDqtQualification(dfeta_q
var mqEstablishments = await referenceDataCache.GetMqEstablishments();
var mqSpecialisms = await referenceDataCache.GetMqSpecialisms();

return MapFromDqtQualification(qualification, mqEstablishments, mqSpecialisms);
}

public static MandatoryQualification MapFromDqtQualification(
dfeta_qualification qualification,
IEnumerable<dfeta_mqestablishment> mqEstablishments,
IEnumerable<dfeta_specialism> mqSpecialisms)
{
if (qualification.dfeta_Type != dfeta_qualification_dfeta_Type.MandatoryQualification)
{
throw new ArgumentException("Qualification is not a mandatory qualification.", nameof(qualification));
}

var deletedEvent = qualification.dfeta_TrsDeletedEvent is not null and not "{}" ?
EventInfo.Deserialize<MandatoryQualificationDeletedEvent>(qualification.dfeta_TrsDeletedEvent).Event :
null;

MandatoryQualificationProvider.TryMapFromDqtMqEstablishment(
mqEstablishments.SingleOrDefault(e => e.Id == qualification.dfeta_MQ_MQEstablishmentId!?.Id), out var provider);

MandatoryQualificationSpecialism? specialism = qualification.dfeta_MQ_SpecialismId is not null ?
mqSpecialisms.Single(s => s.Id == qualification.dfeta_MQ_SpecialismId.Id).ToMandatoryQualificationSpecialism() :
null;

MandatoryQualificationStatus? status = qualification.dfeta_MQ_Status?.ToMandatoryQualificationStatus() ??
(qualification.dfeta_MQ_Date.HasValue ? MandatoryQualificationStatus.Passed : null);

return new MandatoryQualification()
{
QualificationId = qualification.Id,
CreatedOn = qualification.CreatedOn!.Value,
UpdatedOn = qualification.ModifiedOn!.Value,
DeletedOn = deletedEvent?.CreatedUtc,
PersonId = qualification.dfeta_PersonId.Id,
DqtQualificationId = qualification.Id,
DqtState = (int)qualification.StateCode!,
DqtCreatedOn = qualification.CreatedOn!.Value,
DqtModifiedOn = qualification.ModifiedOn!.Value,
ProviderId = provider?.MandatoryQualificationProviderId,
Specialism = specialism,
Status = status,
StartDate = qualification.dfeta_MQStartDate.ToDateOnlyWithDqtBstFix(isLocalTime: true),
EndDate = qualification.dfeta_MQ_Date.ToDateOnlyWithDqtBstFix(isLocalTime: true),
DqtMqEstablishmentId = qualification.dfeta_MQ_MQEstablishmentId?.Id,
DqtSpecialismId = qualification.dfeta_MQ_SpecialismId?.Id
};
return TrsDataSyncHelper.MapMandatoryQualificationFromDqtQualification(qualification, mqEstablishments, mqSpecialisms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static DateOnly ToDateOnlyWithDqtBstFix(this DateTime dateTime, bool isLo
public static DateOnly? ToDateOnlyWithDqtBstFix(this DateTime? dateTime, bool isLocalTime) =>
dateTime.HasValue ? ToDateOnlyWithDqtBstFix(dateTime.Value, isLocalTime) : null;

public static DateTime? WithDqtBstFix(this DateTime? dateTime, bool isLocalTime) =>
dateTime.HasValue ? (isLocalTime ? TimeZoneInfo.ConvertTimeFromUtc(dateTime.Value, _gmt) : dateTime.Value) : null;
public static DateTime? ToUtc(this DateTime dateTime) =>
TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified), _gmt);

public static DateTime? ToUtc(this DateTime? dateTime) =>
dateTime.HasValue ? ToUtc(dateTime.Value) : null;
}
Loading

0 comments on commit 98d9157

Please sign in to comment.