Skip to content

Commit

Permalink
Merge pull request #626 from bcgov/2.0.6
Browse files Browse the repository at this point in the history
2.0.7: fix of TH-121015
  • Loading branch information
bcgov-brwang authored Oct 9, 2024
2 parents 2692bef + c12e5c2 commit bfa6eb5
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Server/SchoolBusAPI/SchoolBusAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Company>Ministry of Transportation and Infrastructure</Company>
<Description>The API server for the schoolbus inspection application.</Description>
<Copyright>Copyright© 2017, Province of British Columbia.</Copyright>
<Version>2.0.6</Version>
<Version>2.0.7</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
13 changes: 13 additions & 0 deletions Server/SchoolBusAPI/Services/CCWDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ public CCWData GetCCW(string regi, string plate, string vin, string userId, stri
}
}

// TH-121015
DateTime dateFetched = DateTime.SpecifyKind(ccwdata.DateFetched.GetValueOrDefault(), DateTimeKind.Unspecified);
DateTime icbcVipExpiry = DateTime.SpecifyKind(ccwdata.ICBCCVIPExpiry.GetValueOrDefault(), DateTimeKind.Unspecified);
DateTime nscPolicyEffectiveDate = DateTime.SpecifyKind(ccwdata.NSCPolicyEffectiveDate.GetValueOrDefault(), DateTimeKind.Unspecified);
DateTime nscPolicyExpiryDate = DateTime.SpecifyKind(ccwdata.NSCPolicyExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified);
DateTime nscPolicyStatusDate = DateTime.SpecifyKind(ccwdata.NSCPolicyStatusDate.GetValueOrDefault(), DateTimeKind.Unspecified);
ccwdata.DateFetched = dateFetched;
ccwdata.ICBCCVIPExpiry = icbcVipExpiry;
ccwdata.NSCPolicyEffectiveDate = nscPolicyEffectiveDate;
ccwdata.NSCPolicyExpiryDate = nscPolicyExpiryDate;
ccwdata.NSCPolicyStatusDate = nscPolicyStatusDate;


if (ccwdata.Id > 0)
{
var bus = _context.SchoolBuss.FirstOrDefault(x => x.CCWDataId == ccwdata.Id);
Expand Down
2 changes: 2 additions & 0 deletions Server/SchoolBusAPI/Services/CurrentUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ public virtual IActionResult UsersCurrentGetAsync()

DateTime today = DateUtils.ConvertPacificToUtcTime(
new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0));
// TH-120363
today = DateTime.SpecifyKind(today, DateTimeKind.Unspecified);

DateTime utcDateTo = today.AddDays(31).AddSeconds(-1);
DateTime dateTo = DateTime.SpecifyKind(utcDateTo, DateTimeKind.Unspecified);
Expand Down
6 changes: 6 additions & 0 deletions Server/SchoolBusAPI/Services/InspectionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public virtual IActionResult InspectionsIdPutAsync(int id, Inspection item)
var exists = _context.Inspections.Any(a => a.Id == id);
if (exists && id == item.Id)
{
item.CreatedDate = DateTime.SpecifyKind(item.CreatedDate, DateTimeKind.Unspecified);
item.InspectionDate = DateTime.SpecifyKind(item.InspectionDate, DateTimeKind.Unspecified);
item.PreviousNextInspectionDate = DateTime.SpecifyKind(item.PreviousNextInspectionDate.GetValueOrDefault(), DateTimeKind.Unspecified);
_context.Inspections.Update(item);
// Save the changes
_context.SaveChanges();
Expand Down Expand Up @@ -258,6 +261,7 @@ public virtual IActionResult InspectionsPostAsync(Inspection item)
}

var exists = _context.Inspections.Any(a => a.Id == item.Id);
item.InspectionDate = DateTime.SpecifyKind(item.InspectionDate, DateTimeKind.Unspecified);
if (exists)
{
_context.Inspections.Update(item);
Expand All @@ -269,6 +273,8 @@ public virtual IActionResult InspectionsPostAsync(Inspection item)
{
// Inspection has a special field, createdDate which is set to now.
item.CreatedDate = DateTime.UtcNow;
// TH-120363
item.CreatedDate = DateTime.SpecifyKind(item.CreatedDate, DateTimeKind.Unspecified);
_context.Inspections.Add(item);
}
_context.SaveChanges();
Expand Down
2 changes: 2 additions & 0 deletions Server/SchoolBusAPI/Services/SchoolBusOwnerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public virtual IActionResult SchoolbusownersIdPutAsync(int id, SchoolBusOwner bo
.OrderByDescending(x => x.NextInspectionDate)
.First();
result = schoolbus.NextInspectionDate;
if (schoolbus.NextInspectionDate != null && schoolbus.NextInspectionDate.Value.Year == 1) { result = null; }
}
return result;
}
Expand Down Expand Up @@ -531,6 +532,7 @@ public virtual IActionResult SchoolbusownersPostAsync(SchoolBusOwner body)
{
AdjustSchoolBusOwner(body);
body.DateCreated = DateTime.UtcNow;
body.DateCreated = DateTime.SpecifyKind(body.DateCreated, DateTimeKind.Unspecified);
_context.SchoolBusOwners.Add(body);
_context.SaveChanges();
return new ObjectResult(body);
Expand Down
27 changes: 27 additions & 0 deletions Server/SchoolBusAPI/Services/SchoolBusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ private void AdjustSchoolBus(SchoolBus item)
item.CCWData = null;
}
}

item.NextInspectionDate = DateTime.SpecifyKind(item.NextInspectionDate.GetValueOrDefault(), DateTimeKind.Unspecified);
item.PermitIssueDate = DateTime.SpecifyKind(item.PermitIssueDate.GetValueOrDefault(), DateTimeKind.Unspecified);
}
}

Expand All @@ -316,6 +319,14 @@ public virtual IActionResult SchoolbusesIdGetAsync(int id)
.Include(x => x.Inspector)
.Include(x => x.CCWData)
.First(a => a.Id == id);
if (result.PermitIssueDate != null && result.PermitIssueDate.Value.Year == 1)
{
result.PermitIssueDate = null;
}
if (result.NextInspectionDate != null && result.NextInspectionDate.Value.Year == 1)
{
result.NextInspectionDate = null;
}
return new ObjectResult(result);
}
else
Expand Down Expand Up @@ -844,6 +855,7 @@ public virtual IActionResult SchoolbusesIdNewpermitPutAsync(int id)

item.PermitNumber = permit;
item.PermitIssueDate = DateTime.UtcNow;
item.PermitIssueDate = DateTime.SpecifyKind(item.PermitIssueDate.GetValueOrDefault(), DateTimeKind.Unspecified);

_context.SchoolBuss.Update(item);
_context.SaveChanges();
Expand Down Expand Up @@ -964,6 +976,8 @@ public IActionResult SchoolbusesSearchGetAsync(int?[] districts, int?[] inspecto
{
var dateFrom = DateUtils.ConvertPacificToUtcTime(
new DateTime(sDate.Year, sDate.Month, sDate.Day, 0, 0, 0));
// TH-120363
dateFrom = DateTime.SpecifyKind(dateFrom, DateTimeKind.Unspecified);

data = data.Where(x => x.NextInspectionDate >= dateFrom);
}
Expand All @@ -974,12 +988,25 @@ public IActionResult SchoolbusesSearchGetAsync(int?[] districts, int?[] inspecto
new DateTime(eDate.Year, eDate.Month, eDate.Day, 0, 0, 0))
.AddDays(1)
.AddSeconds(-1);
// TH-120363
dateTo = DateTime.SpecifyKind(dateTo, DateTimeKind.Unspecified);

data = data.Where(x => x.NextInspectionDate <= dateTo);
}
}

var result = data.ToList();
foreach (var item in result)
{
if (item.NextInspectionDate.HasValue && item.NextInspectionDate.Value.Year == 1)
{
item.NextInspectionDate = null;
}
if (item.PermitIssueDate.HasValue && item.PermitIssueDate.Value.Year == 1)
{
item.PermitIssueDate = null;
}
}
return new ObjectResult(result);
}

Expand Down
15 changes: 10 additions & 5 deletions Server/SchoolBusAPI/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,16 @@ public virtual IActionResult CreateUserRole(int userId, UserRoleViewModel item)
user.UserRoles = new List<UserRole>();
}

// TH - 121015
DateTime effectiveDate = DateTime.SpecifyKind(item.EffectiveDate, DateTimeKind.Unspecified);
DateTime expiryDate = DateTime.SpecifyKind(item.ExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified);

// create a new UserRole based on the view model.
user.UserRoles.Add(new UserRole
{
Role = _context.Roles.First(x => x.Id == item.RoleId),
EffectiveDate = item.EffectiveDate,
ExpiryDate = item.ExpiryDate
EffectiveDate = effectiveDate,
ExpiryDate = expiryDate
}
);

Expand All @@ -352,9 +356,10 @@ public virtual IActionResult UpdateUserRole(int userId, int userRoleId, UserRole

var userRole = _context.UserRoles
.Include(x => x.Role)
.First(x => x.Id == item.Id);

userRole.ExpiryDate = item.ExpiryDate;
.First(x => x.Id == item.Id);
// TH-121015
DateTime expiryDate = DateTime.SpecifyKind(item.ExpiryDate.GetValueOrDefault(), DateTimeKind.Unspecified);
userRole.ExpiryDate = expiryDate;

_context.SaveChanges();
return new StatusCodeResult(201);
Expand Down
11 changes: 10 additions & 1 deletion client/src/js/Keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ const keycloakConfig = {
export const keycloak = Keycloak(keycloakConfig);

export const init = (onSuccess) => {
keycloak.init({ onLoad: 'login-required', promiseType: 'native', pkceMethod: 'S256' }).then((authenticated) => {
keycloak.init({
onLoad: 'login-required',
promiseType: 'native',
pkceMethod: 'S256',
}).then((authenticated) => {
if (authenticated && onSuccess) {
// Clean up the URL by removing any unwanted query parameters like 'iss'
const url = window.location.href;
const cleanUrl = url.split('&iss=')[0]; // Remove everything after &iss=
// clean the URL without refreshing the page
window.history.replaceState(null, null, cleanUrl);
onSuccess();
}
});
Expand Down
46 changes: 41 additions & 5 deletions client/src/js/views/SchoolBusesDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,14 @@ class SchoolBusesDetail extends React.Component {
</Button>
)}
{bus.permitIssueDate && (
// <small id="issued-date">
// &nbsp;(Issued: {formatDateTime(bus.permitIssueDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)})
// </small>

<small id="issued-date">
&nbsp;(Issued: {formatDateTime(bus.permitIssueDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)})
&nbsp;{bus.permitIssueDate && bus.permitIssueDate.includes("0001-01-01")
? ""
: "(Issued: " + formatDateTime(bus.permitIssueDate, Constant.DATE_SHORT_MONTH_DAY_YEAR) + ")"}
</small>
)}
</h1>
Expand Down Expand Up @@ -693,20 +699,48 @@ class SchoolBusesDetail extends React.Component {
<ColDisplay md={4} label="Policy #">
{ccw.nscPolicyNumber}
</ColDisplay>
<ColDisplay md={4} label="Status Date">
{/* <ColDisplay md={4} label="Status Date">
{formatDateTime(ccw.nscPolicyStatusDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay> */}
<ColDisplay md={4} label="Status Date">
{ccw.nscPolicyStatusDate && ccw.nscPolicyStatusDate.includes("0001-01-01")
? ""
: formatDateTime(ccw.nscPolicyStatusDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay>


<ColDisplay md={4} label="Status">
{ccw.nscPolicyStatus}
</ColDisplay>
</Row>
<Row>
<ColDisplay md={4} label="Effective Date">
{/* <ColDisplay md={4} label="Effective Date">
{formatDateTime(ccw.nscPolicyEffectiveDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay> */}


<ColDisplay md={4} label="Effective Date">
{ccw.nscPolicyEffectiveDate && ccw.nscPolicyEffectiveDate.includes("0001-01-01")
? ""
: formatDateTime(ccw.nscPolicyEffectiveDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay>
<ColDisplay md={4} label="Expiry Date">




{/* <ColDisplay md={4} label="Expiry Date">
{formatDateTime(ccw.nscPolicyExpiryDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay> */}

<ColDisplay md={4} label="Expiry Date">
{ccw.nscPolicyExpiryDate && ccw.nscPolicyExpiryDate.includes("0001-01-01")
? ""
: formatDateTime(ccw.nscPolicyExpiryDate, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay>




<ColDisplay md={4} label="Plate Decal #">
{ccw.nscPlateDecal}
</ColDisplay>
Expand Down Expand Up @@ -913,7 +947,9 @@ class SchoolBusesDetail extends React.Component {
{ccw.icbcFleetUnitNo}
</ColDisplay>
<ColDisplay md={3} label="CVIP Expiry">
{formatDateTime(ccw.icbccvipExpiry, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
{ccw.icbccvipExpiry && ccw.icbccvipExpiry.includes("0001-01-01")
? ""
: formatDateTime(ccw.icbccvipExpiry, Constant.DATE_SHORT_MONTH_DAY_YEAR)}
</ColDisplay>
<ColDisplay md={3} label="N&amp;O">
{ccw.icbcNotesAndOrders}
Expand Down

0 comments on commit bfa6eb5

Please sign in to comment.