Skip to content

Commit

Permalink
Merge pull request #9 from vijayjangid/patch-1
Browse files Browse the repository at this point in the history
Refactored update code
  • Loading branch information
hsbalar authored Oct 18, 2019
2 parents 062d836 + e3a6d46 commit 30d4b10
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/app/services/notes_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ let localDB = {
binNotes : new PouchDB('bin_notes_table')
}

const REPEATITION_TYPE = {
doesNotRepeat : 'doesnotrepeat',
daily : 'daily',
weekly : 'weekly',
monthly : 'monthly',
yearly : 'yearly'
}

@Injectable()
export class NotesTableService {
notes_tables_source = new BehaviorSubject<NotesTable[]>([]);
Expand Down Expand Up @@ -63,13 +71,7 @@ export class NotesTableService {
updateReminderTable(schema: string) {
this.getNotes(schema).then(
alldoc => {
let rows = alldoc.rows;
this.reminderTable[schema] = [];
rows.forEach(row => {
if (row.doc.reminder) {
this.reminderTable[schema].push(row);
}
});
this.reminderTable[schema] = alldoc.rows.filter((row) => row.doc.reminder);
});
}

Expand All @@ -92,7 +94,7 @@ export class NotesTableService {
checkForReminderRepeatation(row, todayDate, schema) {
let reminderDate = new Date(row.doc.reminder.date);
let repeatText = row.doc.reminder.repeat;
if (repeatText === 'doesnotrepeat') {
if (repeatText === REPEATITION_TYPE.doesNotRepeat) {
if (todayDate.getFullYear() === reminderDate.getFullYear() &&
todayDate.getMonth() === reminderDate.getMonth() &&
todayDate.getDate() === reminderDate.getDate() &&
Expand All @@ -101,27 +103,27 @@ export class NotesTableService {
{
this.pushNotification(row);
}
} else if (repeatText === 'daily') {
} else if (repeatText === REPEATITION_TYPE.daily) {
if (todayDate.getHours() === reminderDate.getHours() &&
todayDate.getMinutes() === reminderDate.getMinutes())
{
this.pushNotification(row);
}
} else if (repeatText === 'weekly') {
} else if (repeatText === REPEATITION_TYPE.weekly) {
if (todayDate.getDay() === reminderDate.getDay() &&
todayDate.getHours() === reminderDate.getHours() &&
todayDate.getMinutes() === reminderDate.getMinutes())
{
this.pushNotification(row);
}
} else if (repeatText === 'monthly') {
} else if (repeatText === REPEATITION_TYPE.monthly) {
if (todayDate.getDate() === reminderDate.getDate() &&
todayDate.getHours() === reminderDate.getHours() &&
todayDate.getMinutes() === reminderDate.getMinutes())
{
this.pushNotification(row);
}
} else if (repeatText === 'yearly') {
} else if (repeatText === REPEATITION_TYPE.yearly) {
if (todayDate.getMonth() === reminderDate.getMonth() &&
todayDate.getDate() === reminderDate.getDate() &&
todayDate.getHours() === reminderDate.getHours() &&
Expand Down

0 comments on commit 30d4b10

Please sign in to comment.