diff --git a/backend/src/db/api/tasks.js b/backend/src/db/api/tasks.js index 37e3f6e..93c5b38 100644 --- a/backend/src/db/api/tasks.js +++ b/backend/src/db/api/tasks.js @@ -1,4 +1,3 @@ - const db = require('../models'); const FileDBApi = require('./file'); const crypto = require('crypto'); @@ -566,6 +565,36 @@ module.exports = class TasksDBApi { })); } - -}; + static async getStats(options) { + const currentUser = (options && options.currentUser) || { id: null }; + const transaction = (options && options.transaction) || undefined; + const total = await db.tasks.count({ + transaction, + }); + + const pending = await db.tasks.count({ + where: { status: 'pending' }, + transaction, + }); + + const in_progress = await db.tasks.count({ + where: { status: 'in_progress' }, + transaction, + }); + + const completed = await db.tasks.count({ + where: { status: 'completed' }, + transaction, + }); + + return { + total, + pending, + in_progress, + completed, + }; + } + + +}; \ No newline at end of file diff --git a/backend/src/routes/tasks.js b/backend/src/routes/tasks.js index 10b165b..1aee571 100644 --- a/backend/src/routes/tasks.js +++ b/backend/src/routes/tasks.js @@ -1,4 +1,3 @@ - const express = require('express'); const TasksService = require('../services/tasks'); @@ -350,6 +349,11 @@ router.get('/count', wrapAsync(async (req, res) => { res.status(200).send(payload); })); +router.get('/stats', wrapAsync(async (req, res) => { + const payload = await TasksService.getStats(req.currentUser); + res.status(200).send(payload); +})); + /** * @swagger * /api/tasks/autocomplete: @@ -431,4 +435,4 @@ router.get('/:id', wrapAsync(async (req, res) => { router.use('/', require('../helpers').commonErrorHandler); -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/backend/src/services/tasks.js b/backend/src/services/tasks.js index e62bdba..cdf2843 100644 --- a/backend/src/services/tasks.js +++ b/backend/src/services/tasks.js @@ -132,7 +132,9 @@ module.exports = class TasksService { } } + static async getStats(currentUser) { + return await TasksDBApi.getStats({ currentUser }); + } + -}; - - +}; \ No newline at end of file diff --git a/frontend/src/components/NavBarItem.tsx b/frontend/src/components/NavBarItem.tsx index eb155e3..1986306 100644 --- a/frontend/src/components/NavBarItem.tsx +++ b/frontend/src/components/NavBarItem.tsx @@ -1,6 +1,5 @@ -import React, {useEffect, useRef} from 'react' +import React, {useEffect, useRef, useState} from 'react' import Link from 'next/link' -import { useState } from 'react' import { mdiChevronUp, mdiChevronDown } from '@mdi/js' import BaseDivider from './BaseDivider' import BaseIcon from './BaseIcon' @@ -129,4 +128,4 @@ export default function NavBarItem({ item }: Props) { } return