Skip to content

Commit

Permalink
fix(apis): quick fix on date 馃悰
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 18, 2020
1 parent f4af8bd commit a53082f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/helpers/montaineType.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ const format = (data, action, object) => {
switch (func) {
case 'DATE':
try {
return moment(new Date(data)).format();
let date = '';
date = moment(data).format();
// fixs
if (date === 'Invalid date') {
const dateSplit = data.split('-');
if (dateSplit.length === 3) date = moment(`${dateSplit[0]}-${dateSplit[1]}`).add(Number(dateSplit[2]) - 1, 'days').format(); // Hot Fix if date containe more dats than a month
else throw new AppError(`Typing : date invalid ${data}`, { code: 'HELPERS_ERROR', details: date });
}
return date;
} catch (err) {
throw new AppError('Typing : format DATE error', { code: 'HELPERS_ERROR', details: err });
}
Expand Down
1 change: 1 addition & 0 deletions modules/apis/repositories/apis.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exports.import = (collection, items) => {
const _schema = new mongoose.Schema({}, {
collection,
strict: false,
timestamps: true,
});

let model;
Expand Down

0 comments on commit a53082f

Please sign in to comment.