Skip to content

Commit

Permalink
Merge pull request #78 from madisvain/invoices-dates-fix
Browse files Browse the repository at this point in the history
convert moment objects before save
  • Loading branch information
madisvain authored Oct 4, 2020
2 parents 963ed83 + 3219996 commit d8d134d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/services/invoices.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assign, has } from 'lodash';
import moment from 'moment';

import db from '../db';

Expand Down Expand Up @@ -34,6 +35,14 @@ export async function details(id) {
}

export async function save(data) {
// Convert the moment objects to date strings
if (has(data, 'date') && moment.isMoment(data['date'])) {
data['date'] = data['date'].format('YYYY-MM-DD');
}
if (has(data, 'due_date') && moment.isMoment(data['due_date'])) {
data['due_date'] = data['due_date'].format('YYYY-MM-DD');
}

try {
if (has(data, '_id')) {
const original = await db.get(data._id);
Expand Down

0 comments on commit d8d134d

Please sign in to comment.