Skip to content

Commit

Permalink
avniproject/avni-client#1524 - removed default init of duration unit.…
Browse files Browse the repository at this point in the history
… removed get recent input duration default value from getter. realm initialises list to empty array by default. initialise with default values for duration input standard report card types.
  • Loading branch information
petmongrels committed Sep 30, 2024
1 parent a2c01b4 commit 94f81d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import moment from "moment";
class Duration {
constructor(durationValue, durationUnit) {
this._durationValue = durationValue;
this.durationUnit = durationUnit || Duration.Day;
this.durationUnit = durationUnit;
}

static inDay(value) {
Expand Down
3 changes: 0 additions & 3 deletions src/ReportCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ class ReportCard extends BaseEntity {
}

getStandardReportCardInputRecentDuration() {
if (_.isEmpty(this.that.standardReportCardInputRecentDurationJSON)) {
return new Duration(1, Duration.Day);
}
const duration = JSON.parse(this.that.standardReportCardInputRecentDurationJSON);
return new Duration(duration.value, duration.unit);
}
Expand Down
16 changes: 10 additions & 6 deletions src/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,16 @@ function createRealmConfig() {
newDB.delete(newDB.objects("CustomDashboardCache"));
}
if (oldDB.schemaVersion < 197) {
_.forEach(newDB.objects("ReportCard"), (reportCard) => {
if (reportCard.standardReportCardType &&
['Last 24 hours registrations', 'Last 24 hours enrolments', 'Last 24 hours visits']
.includes(reportCard.standardReportCardType.name))
reportCard.standardReportCardInputRecentDurationJSON = JSON.stringify({
value: "1",
unit: "days"
});
});

_.forEach(newDB.objects("StandardReportCardType"), (standardReportCardType) => {
if (standardReportCardType.name === 'Last 24 hours registrations') {
standardReportCardType.description = 'Recent registrations';
Expand All @@ -935,12 +945,6 @@ function createRealmConfig() {
standardReportCardType.type = _.replace(_.startCase(standardReportCardType.description), new RegExp(' ', 'g'), '');
});

_.forEach(newDB.objects(ReportCard.schema.name), (card) => {
card.standardReportCardInputSubjectTypes = [];
card.standardReportCardInputPrograms = [];
card.standardReportCardInputEncounterTypes = [];
});

//Reset MyDashboard cache because shape of filterJSON in cache has changed
const dashboardCache = newDB.objects("DashboardCache");
newDB.delete(dashboardCache);
Expand Down

0 comments on commit 94f81d0

Please sign in to comment.