Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { FileHandler } from './services/file-handler.js';
- const reader = new FileHandler();
- reader
- .read('./data/tasks.all.json')
- .then(data => JSON.parse(data))
- .then(data => {
- const done = data.tasks.filter(x => x.status === 'done')
- const pending = data.tasks.filter(x => x.status === 'pending')
- const promise1 = reader.write('./data/tasks.done.json', JSON.stringify(done, null, 2));
- const promise2 = reader.write('./data/tasks.pending.json', JSON.stringify(pending, null, 2));
- Promise.allSettled([promise1, promise2]).then(errors => {
- const error = errors.filter(x => x.status === 'rejected').map(x => x.reason)
- if (error.length > 0) {
- console.log('There is an Error/s, check the log.')
- }
- reader.read('./logs/default.log')
- .then(data => {
- reader
- .write('./logs/default.log', data + '\n' + error.join('\n'))
- .catch(err => console.log(err));
- })
- .catch(err => console.log(err))
- }).catch(err => console.log(err));
- }).catch(err => {
- reader
- .read('./logs/default.log')
- .then(data => {
- reader
- .write('./logs/default.log', data + '\n' + err)
- .catch(err => console.log(err));
- }).catch(err => console.log(err))
- console.log('There is an Error thrown, check the log.')
- });
Advertisement
Add Comment
Please, Sign In to add comment