UNPKG

saksh-task-manager

Version:

A Node.js module for managing tasks with caching and event handling capabilities.

70 lines (49 loc) 2.12 kB
const SakshTaskController = require('saksh-tasks'); const mongoose = require('mongoose'); const run = async () => { try { // Connect to MongoDB try { await mongoose.connect('mongodb://localhost:27017/sakshwallet', { useNewUrlParser: true, useUnifiedTopology: true, }); console.log('MongoDB connected'); } catch (error) { console.error('MongoDB connection failed:', error.message); process.exit(1); } // Create an instance of SakshTaskController with a user ID const userId = 'your-user-id-here'; const taskController = new SakshTaskController(userId); // Create a new task const newTask = await taskController.sakshCreateTask({ name: 'Sample Task', fileUrl: 'http://example.com/file.pdf' }); console.log('Task Created:', newTask); // Get all tasks const tasks = await taskController.sakshGetTasks(); console.log('All Tasks:', tasks); // Update a task const updatedTask = await taskController.sakshUpdateTask(newTask._id, { completed: true }); console.log('Task Updated:', updatedTask); // Delete a task const deleteMessage = await taskController.sakshDeleteTask(newTask._id); console.log(deleteMessage); // Event listeners const sakshTaskController = new SakshTaskController('your-user-id-here'); sakshTaskController.on('taskCreated', (task) => { console.log('New task created:', task); }); sakshTaskController.on('taskUpdated', (task) => { console.log('Task updated:', task); }); sakshTaskController.on('taskDeleted', (task) => { console.log('Task deleted:', task); }); sakshTaskController.on('tasksRetrieved', (tasks) => { console.log('Tasks retrieved:', tasks); }); } catch (error) { console.error('Error:', error.message); } }; run();