diff --git a/lib/helpers/montaineType.js b/lib/helpers/montaineType.js index 0ea0e532..188cfda0 100644 --- a/lib/helpers/montaineType.js +++ b/lib/helpers/montaineType.js @@ -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 }); } diff --git a/modules/apis/repositories/apis.repository.js b/modules/apis/repositories/apis.repository.js index a3dc660b..d3d0f58f 100644 --- a/modules/apis/repositories/apis.repository.js +++ b/modules/apis/repositories/apis.repository.js @@ -51,6 +51,7 @@ exports.import = (collection, items) => { const _schema = new mongoose.Schema({}, { collection, strict: false, + timestamps: true, }); let model;