diff --git a/src/controllers/bmdashboard/__tests__/toolAvailabilityController.test.js b/src/controllers/bmdashboard/__tests__/toolAvailabilityController.test.js new file mode 100644 index 0000000000..9f4aa6e359 --- /dev/null +++ b/src/controllers/bmdashboard/__tests__/toolAvailabilityController.test.js @@ -0,0 +1,245 @@ +const mongoose = require('mongoose'); +const BuildingProject = require('../../../models/bmdashboard/buildingProject'); +const toolAvailabilityController = require('../toolAvailabilityController'); + +const projectId = '65419e61105441587e2dec99'; + +const makeResponse = () => ({ + status: jest.fn().mockReturnThis(), + json: jest.fn().mockReturnThis(), +}); + +describe('Tool Availability Controller', () => { + let ToolAvailability; + let controller; + + beforeEach(() => { + jest.restoreAllMocks(); + + jest.spyOn(BuildingProject, 'find'); + + ToolAvailability = { + aggregate: jest.fn(), + distinct: jest.fn(), + }; + + controller = toolAvailabilityController(ToolAvailability); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + describe('getToolsAvailability', () => { + it('returns 400 for an invalid project ID', async () => { + const req = { params: { id: 'invalid-id' }, query: {} }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + expect(res.status).toHaveBeenCalledWith(400); + expect(res.json).toHaveBeenCalledWith({ + error: 'Invalid project ID format', + }); + expect(ToolAvailability.aggregate).not.toHaveBeenCalled(); + }); + + it('returns aggregated tool availability data', async () => { + const data = [ + { + toolName: 'Hammer', + inUse: 5, + needsReplacement: 2, + yetToReceive: 1, + }, + ]; + + ToolAvailability.aggregate.mockResolvedValue(data); + + const req = { params: { id: projectId }, query: {} }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + expect(ToolAvailability.aggregate).toHaveBeenCalledWith( + expect.arrayContaining([ + expect.objectContaining({ + $match: { + projectId: new mongoose.Types.ObjectId(projectId), + }, + }), + ]), + ); + expect(res.json).toHaveBeenCalledWith(data); + }); + + it('applies both start and end date filters', async () => { + ToolAvailability.aggregate.mockResolvedValue([]); + + const req = { + params: { id: projectId }, + query: { + startDate: '2026-01-01', + endDate: '2026-01-31', + }, + }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + const pipeline = ToolAvailability.aggregate.mock.calls[0][0]; + + expect(pipeline[0].$match.date).toEqual({ + $gte: new Date('2026-01-01'), + $lte: new Date('2026-01-31'), + }); + }); + + it('applies only the start date when end date is absent', async () => { + ToolAvailability.aggregate.mockResolvedValue([]); + + const req = { + params: { id: projectId }, + query: { startDate: '2026-01-01' }, + }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + const pipeline = ToolAvailability.aggregate.mock.calls[0][0]; + + expect(pipeline[0].$match.date).toEqual({ + $gte: new Date('2026-01-01'), + }); + }); + + it('applies only the end date when start date is absent', async () => { + ToolAvailability.aggregate.mockResolvedValue([]); + + const req = { + params: { id: projectId }, + query: { endDate: '2026-01-31' }, + }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + const pipeline = ToolAvailability.aggregate.mock.calls[0][0]; + + expect(pipeline[0].$match.date).toEqual({ + $lte: new Date('2026-01-31'), + }); + }); + + it('returns an empty array when no data exists', async () => { + ToolAvailability.aggregate.mockResolvedValue([]); + + const req = { params: { id: projectId }, query: {} }; + const res = makeResponse(); + + await controller.getToolsAvailability(req, res); + + expect(res.json).toHaveBeenCalledWith([]); + }); + + it('handles database aggregation failures', async () => { + ToolAvailability.aggregate.mockRejectedValue(new Error('Database failure')); + + const req = { params: { id: projectId }, query: {} }; + const res = makeResponse(); + + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + try { + await controller.getToolsAvailability(req, res); + + expect(res.status).toHaveBeenCalledWith(500); + expect(res.json).toHaveBeenCalledWith({ + error: 'Internal server error', + }); + } finally { + consoleSpy.mockRestore(); + } + }); + }); + + describe('getUniqueProjectIds', () => { + it('returns project names for valid project IDs', async () => { + ToolAvailability.distinct.mockResolvedValue([new mongoose.Types.ObjectId(projectId)]); + + const projects = [ + { + _id: new mongoose.Types.ObjectId(projectId), + name: 'Building 1', + }, + ]; + + const query = { + select: jest.fn().mockReturnThis(), + sort: jest.fn().mockReturnThis(), + lean: jest.fn().mockResolvedValue(projects), + }; + + BuildingProject.find.mockReturnValue(query); + + const req = {}; + const res = makeResponse(); + + await controller.getUniqueProjectIds(req, res); + + expect(BuildingProject.find).toHaveBeenCalledWith({ + _id: { + $in: [new mongoose.Types.ObjectId(projectId)], + }, + }); + + expect(res.json).toHaveBeenCalledWith([ + { + projectId: projects[0]._id, + projectName: 'Building 1', + }, + ]); + }); + + it('returns an empty array when no project IDs exist', async () => { + ToolAvailability.distinct.mockResolvedValue([]); + + const res = makeResponse(); + + await controller.getUniqueProjectIds({}, res); + + expect(res.json).toHaveBeenCalledWith([]); + expect(BuildingProject.find).not.toHaveBeenCalled(); + }); + + it('ignores invalid project IDs', async () => { + ToolAvailability.distinct.mockResolvedValue(['invalid-id']); + + const res = makeResponse(); + + await controller.getUniqueProjectIds({}, res); + + expect(res.json).toHaveBeenCalledWith([]); + expect(BuildingProject.find).not.toHaveBeenCalled(); + }); + + it('handles project lookup failures', async () => { + ToolAvailability.distinct.mockRejectedValue(new Error('Database failure')); + + const res = makeResponse(); + + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + + try { + await controller.getUniqueProjectIds({}, res); + + expect(res.status).toHaveBeenCalledWith(500); + expect(res.json).toHaveBeenCalledWith({ + error: 'Internal server error', + }); + } finally { + consoleSpy.mockRestore(); + } + }); + }); +}); diff --git a/src/controllers/bmdashboard/toolAvailabilityController.js b/src/controllers/bmdashboard/toolAvailabilityController.js index 64e9527fd9..ead1deec98 100644 --- a/src/controllers/bmdashboard/toolAvailabilityController.js +++ b/src/controllers/bmdashboard/toolAvailabilityController.js @@ -1,5 +1,7 @@ -const { ObjectId } = require('mongoose').Types; +const mongoose = require('mongoose'); +const BuildingProject = require('../../models/bmdashboard/buildingProject'); +const { ObjectId } = mongoose.Types; const toolAvailabilityController = function (ToolAvailability) { const getToolsAvailability = async (req, res) => { try { @@ -124,36 +126,26 @@ const toolAvailabilityController = function (ToolAvailability) { const getUniqueProjectIds = async (req, res) => { try { - // Use aggregation to get distinct project IDs and lookup their names - const results = await ToolAvailability.aggregate([ - { - $group: { - _id: '$projectId', - }, - }, - { - $lookup: { - from: 'buildingProject', - localField: '_id', - foreignField: '_id', - as: 'projectDetails', - }, - }, - { - $project: { - _id: 1, - projectName: { $arrayElemAt: ['$projectDetails.projectName', 0] }, - }, - }, - { - $sort: { projectName: 1 }, - }, - ]); + const projectIds = await ToolAvailability.distinct('projectId'); + + const validProjectIds = projectIds + .filter((id) => ObjectId.isValid(id)) + .map((id) => new ObjectId(String(id))); + + if (validProjectIds.length === 0) { + return res.json([]); + } + + const projects = await BuildingProject.find({ + _id: { $in: validProjectIds }, + }) + .select('_id name') + .sort({ name: 1 }) + .lean(); - // Format the response - const formattedResults = results.map((item) => ({ - projectId: item._id, - projectName: item.projectName || 'Unknown Project', + const formattedResults = projects.map((project) => ({ + projectId: project._id, + projectName: project.name, })); return res.json(formattedResults); diff --git a/src/controllers/summaryDashboard/__tests__/supplierPerformance.test.js b/src/controllers/summaryDashboard/__tests__/supplierPerformance.test.js new file mode 100644 index 0000000000..6588cd1665 --- /dev/null +++ b/src/controllers/summaryDashboard/__tests__/supplierPerformance.test.js @@ -0,0 +1,347 @@ +const mongoose = require('mongoose'); +const Project = require('../../../models/project'); +const SupplierPerformance = require('../../../models/summaryDashboard/supplierPerformance'); +const logger = require('../../../startup/logger'); +const supplierPerformanceController = require('../supplierPerformance'); + +const projectId = '64acb5d8a5f9ed4ca45d87df'; +const missingProjectId = '507f1f77bcf86cd799439011'; + +const makeResponse = () => ({ + status: jest.fn().mockReturnThis(), + send: jest.fn().mockReturnThis(), +}); + +describe('Supplier Performance Controller', () => { + let controller; + + beforeEach(() => { + jest.restoreAllMocks(); + jest.clearAllMocks(); + + jest.spyOn(SupplierPerformance, 'aggregate'); + jest.spyOn(SupplierPerformance, 'distinct'); + jest.spyOn(Project, 'find'); + jest.spyOn(logger, 'logException').mockImplementation(() => {}); + + controller = supplierPerformanceController(); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + describe('getSupplierPerformance', () => { + it('returns 400 when required dates are missing', async () => { + const res = makeResponse(); + + await controller.getSupplierPerformance({ query: { projectId: 'all' } }, res); + + expect(res.status).toHaveBeenCalledWith(400); + expect(res.send).toHaveBeenCalledWith( + 'Missing required query parameters: startDate, endDate', + ); + expect(SupplierPerformance.aggregate).not.toHaveBeenCalled(); + }); + + it('returns 400 for an invalid project ID', async () => { + const res = makeResponse(); + + await controller.getSupplierPerformance( + { + query: { + projectId: 'invalid-project', + startDate: '2026-01-01', + endDate: '2026-01-31', + }, + }, + res, + ); + + expect(res.status).toHaveBeenCalledWith(400); + expect(res.send).toHaveBeenCalledWith('Invalid projectId.'); + expect(SupplierPerformance.aggregate).not.toHaveBeenCalled(); + }); + + it('returns aggregated supplier data for all projects', async () => { + const data = [ + { + supplierName: 'Supplier A', + onTimeDeliveryPercentage: 95.8, + }, + ]; + + SupplierPerformance.aggregate.mockResolvedValue(data); + + const res = makeResponse(); + + await controller.getSupplierPerformance( + { + query: { + projectId: 'all', + startDate: '2026-01-01', + endDate: '2026-01-31', + }, + }, + res, + ); + + const pipeline = SupplierPerformance.aggregate.mock.calls[0][0]; + + expect(pipeline[0].$match).toEqual({ + startDate: { $lte: new Date('2026-01-31') }, + endDate: { $gte: new Date('2026-01-01') }, + }); + + expect(res.status).toHaveBeenCalledWith(200); + expect(res.send).toHaveBeenCalledWith(data); + }); + + it('filters supplier data by a specific project ID', async () => { + SupplierPerformance.aggregate.mockResolvedValue([]); + + const res = makeResponse(); + + await controller.getSupplierPerformance( + { + query: { + projectId, + startDate: '2026-01-01', + endDate: '2026-01-31', + }, + }, + res, + ); + + const pipeline = SupplierPerformance.aggregate.mock.calls[0][0]; + + expect(String(pipeline[0].$match.projectId)).toBe(projectId); + expect(res.status).toHaveBeenCalledWith(200); + expect(res.send).toHaveBeenCalledWith([]); + }); + + it('handles aggregation failures', async () => { + SupplierPerformance.aggregate.mockRejectedValue(new Error('Aggregation failed')); + + const res = makeResponse(); + + await controller.getSupplierPerformance( + { + query: { + projectId: 'all', + startDate: '2026-01-01', + endDate: '2026-01-31', + }, + }, + res, + ); + + expect(logger.logException).toHaveBeenCalled(); + expect(res.status).toHaveBeenCalledWith(500); + expect(res.send).toHaveBeenCalledWith( + 'Error fetching supplier performance data. Please try again.', + ); + }); + }); + + describe('getProjectsWithSupplierData', () => { + it('returns resolved project names and preserves missing IDs', async () => { + SupplierPerformance.distinct.mockResolvedValue([ + new mongoose.Types.ObjectId(projectId), + new mongoose.Types.ObjectId(missingProjectId), + ]); + + const query = { + select: jest.fn().mockReturnThis(), + lean: jest.fn().mockResolvedValue([ + { + _id: new mongoose.Types.ObjectId(projectId), + projectName: 'SiddharthTest', + }, + ]), + }; + + Project.find.mockReturnValue(query); + + const res = makeResponse(); + + await controller.getProjectsWithSupplierData({}, res); + + expect(res.status).toHaveBeenCalledWith(200); + + const results = res.send.mock.calls[0][0]; + + expect(results).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + _id: new mongoose.Types.ObjectId(projectId), + projectName: 'SiddharthTest', + }), + expect.objectContaining({ + _id: new mongoose.Types.ObjectId(missingProjectId), + projectName: 'Unknown project (…9011)', + }), + ]), + ); + + expect(results).toHaveLength(2); + }); + + it('returns an empty array when there are no project IDs', async () => { + SupplierPerformance.distinct.mockResolvedValue([]); + + const res = makeResponse(); + + await controller.getProjectsWithSupplierData({}, res); + + expect(res.status).toHaveBeenCalledWith(200); + expect(res.send).toHaveBeenCalledWith([]); + expect(Project.find).not.toHaveBeenCalled(); + }); + + it('ignores malformed project IDs', async () => { + SupplierPerformance.distinct.mockResolvedValue(['invalid-id']); + + const res = makeResponse(); + + await controller.getProjectsWithSupplierData({}, res); + + expect(res.status).toHaveBeenCalledWith(200); + expect(res.send).toHaveBeenCalledWith([]); + expect(Project.find).not.toHaveBeenCalled(); + }); + + it('handles project lookup failures', async () => { + SupplierPerformance.distinct.mockRejectedValue(new Error('Lookup failed')); + + const res = makeResponse(); + + await controller.getProjectsWithSupplierData({}, res); + + expect(logger.logException).toHaveBeenCalled(); + expect(res.status).toHaveBeenCalledWith(500); + expect(res.send).toHaveBeenCalledWith( + 'Error fetching projects with supplier data. Please try again.', + ); + }); + }); + + describe('postSupplierPerformance', () => { + const validBody = { + supplierName: 'Supplier A', + onTimeDeliveryPercentage: 95.8, + projectId, + startDate: '2026-01-01', + endDate: '2026-01-31', + }; + + it('creates a supplier performance record successfully', async () => { + const saveSpy = jest.spyOn(SupplierPerformance.prototype, 'save').mockResolvedValue({}); + + const res = makeResponse(); + + await controller.postSupplierPerformance({ body: validBody }, res); + + expect(saveSpy).toHaveBeenCalledTimes(1); + expect(res.status).toHaveBeenCalledWith(201); + expect(res.send).toHaveBeenCalledWith('Supplier performance record created successfully.'); + }); + + it('returns 400 when required fields are missing', async () => { + const saveSpy = jest.spyOn(SupplierPerformance.prototype, 'save'); + + const res = makeResponse(); + + await controller.postSupplierPerformance( + { + body: { + supplierName: 'Supplier A', + projectId, + }, + }, + res, + ); + + expect(res.status).toHaveBeenCalledWith(400); + expect(res.send).toHaveBeenCalledWith( + 'All fields are required: supplierName, onTimeDeliveryPercentage, projectId, startDate, endDate', + ); + expect(saveSpy).not.toHaveBeenCalled(); + }); + + it('returns 500 when saving a record fails', async () => { + jest + .spyOn(SupplierPerformance.prototype, 'save') + .mockRejectedValue(new Error('Database failure')); + + const res = makeResponse(); + + await controller.postSupplierPerformance({ body: validBody }, res); + + expect(logger.logException).toHaveBeenCalled(); + expect(res.status).toHaveBeenCalledWith(500); + expect(res.send).toHaveBeenCalledWith( + 'Error saving supplier performance data. Please try again.', + ); + }); + }); + + describe('deleteSupplierPerformanceByProject', () => { + it('deletes supplier records successfully', async () => { + jest.spyOn(SupplierPerformance, 'deleteMany').mockResolvedValue({ + deletedCount: 2, + }); + + const res = makeResponse(); + + await controller.deleteSupplierPerformanceByProject({ params: { projectId } }, res); + + expect(SupplierPerformance.deleteMany).toHaveBeenCalledWith({ + projectId: new mongoose.Types.ObjectId(projectId), + }); + expect(res.status).toHaveBeenCalledWith(200); + expect(res.send).toHaveBeenCalledWith('Successfully deleted 2 record(s).'); + }); + + it('returns 404 when no matching records exist', async () => { + jest.spyOn(SupplierPerformance, 'deleteMany').mockResolvedValue({ + deletedCount: 0, + }); + + const res = makeResponse(); + + await controller.deleteSupplierPerformanceByProject({ params: { projectId } }, res); + + expect(res.status).toHaveBeenCalledWith(404); + expect(res.send).toHaveBeenCalledWith('No records found for the specified project.'); + }); + + it('returns 400 when project ID is missing', async () => { + const deleteSpy = jest.spyOn(SupplierPerformance, 'deleteMany'); + + const res = makeResponse(); + + await controller.deleteSupplierPerformanceByProject({ params: {} }, res); + + expect(res.status).toHaveBeenCalledWith(400); + expect(res.send).toHaveBeenCalledWith('Project ID is required.'); + expect(deleteSpy).not.toHaveBeenCalled(); + }); + + it('returns 500 when deletion fails', async () => { + jest + .spyOn(SupplierPerformance, 'deleteMany') + .mockRejectedValue(new Error('Database failure')); + + const res = makeResponse(); + + await controller.deleteSupplierPerformanceByProject({ params: { projectId } }, res); + + expect(logger.logException).toHaveBeenCalled(); + expect(res.status).toHaveBeenCalledWith(500); + expect(res.send).toHaveBeenCalledWith( + 'Error deleting supplier performance data. Please try again.', + ); + }); + }); +}); diff --git a/src/controllers/summaryDashboard/supplierPerformance.js b/src/controllers/summaryDashboard/supplierPerformance.js index 7761f75d91..f3811ad492 100644 --- a/src/controllers/summaryDashboard/supplierPerformance.js +++ b/src/controllers/summaryDashboard/supplierPerformance.js @@ -1,10 +1,12 @@ const mongoose = require('mongoose'); +const Project = require('../../models/project'); const SupplierPerformance = require('../../models/summaryDashboard/supplierPerformance'); const logger = require('../../startup/logger'); const supplierPerformanceController = function () { /** - * Get supplier performance records for a specific project and date range, or all projects + * Get supplier performance records for a specific project and date range, + * or all projects. */ const getSupplierPerformance = async function (req, res) { try { @@ -14,10 +16,15 @@ const supplierPerformanceController = function () { return res.status(400).send('Missing required query parameters: startDate, endDate'); } + // Validate projectId before converting it to a MongoDB ObjectId. + // "all" is a valid special value used by the frontend. + if (projectId && projectId !== 'all' && !mongoose.Types.ObjectId.isValid(projectId)) { + return res.status(400).send('Invalid projectId.'); + } + const start = new Date(startDate); const end = new Date(endDate); - // Build match criteria - if projectId is not provided or is 'all', get data for all projects const matchCriteria = { startDate: { $lte: end }, endDate: { $gte: start }, @@ -25,15 +32,8 @@ const supplierPerformanceController = function () { if (projectId && projectId !== 'all') { matchCriteria.projectId = mongoose.Types.ObjectId(projectId); - console.log('Fetching data for specific project:', projectId); - } else { - console.log('Fetching data for all projects'); } - console.log('Query params:', { projectId, startDate, endDate, start, end }); - console.log('Match criteria:', matchCriteria); - - // MongoDB Aggregation Pipeline const supplierData = await SupplierPerformance.aggregate([ { $match: matchCriteria, @@ -41,59 +41,81 @@ const supplierPerformanceController = function () { { $group: { _id: '$supplierName', - onTimeDeliveryPercentage: { $avg: '$onTimeDeliveryPercentage' }, + onTimeDeliveryPercentage: { + $avg: '$onTimeDeliveryPercentage', + }, }, }, { $project: { supplierName: '$_id', - onTimeDeliveryPercentage: { $round: ['$onTimeDeliveryPercentage', 2] }, + onTimeDeliveryPercentage: { + $round: ['$onTimeDeliveryPercentage', 2], + }, + }, + }, + { + $sort: { + onTimeDeliveryPercentage: -1, }, }, - { $sort: { onTimeDeliveryPercentage: -1 } }, ]); - console.log('Aggregation result:', supplierData); - res.status(200).send(supplierData); + return res.status(200).send(supplierData); } catch (error) { logger.logException(error); - res.status(500).send('Error fetching supplier performance data. Please try again.'); + return res.status(500).send('Error fetching supplier performance data. Please try again.'); } }; /** - * Get all unique projects that have supplier performance data + * Get all unique projects that have supplier performance data. + * Project names are returned along with their IDs so that the + * frontend dropdown can display project names instead of raw IDs. */ const getProjectsWithSupplierData = async function (req, res) { try { - console.log('Fetching projects with supplier performance data'); + const projectIds = await SupplierPerformance.distinct('projectId'); - // Get distinct project IDs from supplier performance records only - const projectsWithData = await SupplierPerformance.aggregate([ - { - $group: { - _id: '$projectId', - }, - }, - { - $project: { - _id: 1, - projectId: '$_id', - }, - }, - { $sort: { _id: 1 } }, - ]); + const validProjectIds = projectIds + .filter((id) => mongoose.Types.ObjectId.isValid(id)) + .map((id) => new mongoose.Types.ObjectId(String(id))); + + if (validProjectIds.length === 0) { + return res.status(200).send([]); + } + + const projects = await Project.find({ + _id: { $in: validProjectIds }, + }) + .select('_id projectName') + .lean(); + + const projectNames = new Map( + projects.map((project) => [String(project._id), project.projectName]), + ); - console.log(`Found ${projectsWithData.length} projects with supplier data`); - res.status(200).send(projectsWithData); + const results = validProjectIds.map((id) => { + const idString = String(id); + const projectName = projectNames.get(idString); + + return { + _id: id, + projectName: projectName || `Unknown project (…${idString.slice(-4)})`, + }; + }); + + results.sort((a, b) => a.projectName.localeCompare(b.projectName)); + + return res.status(200).send(results); } catch (error) { logger.logException(error); - res.status(500).send('Error fetching projects with supplier data. Please try again.'); + return res.status(500).send('Error fetching projects with supplier data. Please try again.'); } }; /** - * Add a new supplier performance record + * Add a new supplier performance record. */ const postSupplierPerformance = async function (req, res) { try { @@ -116,15 +138,16 @@ const supplierPerformanceController = function () { }); await newRecord.save(); - res.status(201).send('Supplier performance record created successfully.'); + + return res.status(201).send('Supplier performance record created successfully.'); } catch (error) { logger.logException(error); - res.status(500).send('Error saving supplier performance data. Please try again.'); + return res.status(500).send('Error saving supplier performance data. Please try again.'); } }; /** - * Delete supplier performance records by Project ID + * Delete supplier performance records by Project ID. */ const deleteSupplierPerformanceByProject = async function (req, res) { try { @@ -139,13 +162,13 @@ const supplierPerformanceController = function () { }); if (result.deletedCount > 0) { - res.status(200).send(`Successfully deleted ${result.deletedCount} record(s).`); - } else { - res.status(404).send('No records found for the specified project.'); + return res.status(200).send(`Successfully deleted ${result.deletedCount} record(s).`); } + + return res.status(404).send('No records found for the specified project.'); } catch (error) { logger.logException(error); - res.status(500).send('Error deleting supplier performance data. Please try again.'); + return res.status(500).send('Error deleting supplier performance data. Please try again.'); } }; diff --git a/src/routes/bmdashboard/toolAvailabilityRouter.js b/src/routes/bmdashboard/toolAvailabilityRouter.js index 309bc8de85..6afe219d4b 100644 --- a/src/routes/bmdashboard/toolAvailabilityRouter.js +++ b/src/routes/bmdashboard/toolAvailabilityRouter.js @@ -1,17 +1,20 @@ const express = require('express'); +const ToolAvailability = require('../../models/bmdashboard/toolAvailability'); +const toolAvailabilityController = require('../../controllers/bmdashboard/toolAvailabilityController'); const routes = function () { const toolAvailabilityRouter = express.Router(); + const controller = toolAvailabilityController(ToolAvailability); // GET /api/bm/projects/:id/tools-availability toolAvailabilityRouter .route('/bm/projects/:id/tools-availability') - .get((req, res) => res.json({ message: 'Get tools availability' })); + .get(controller.getToolsAvailability); // GET /api/bm/tools-availability/projects toolAvailabilityRouter .route('/bm/tools-availability/projects') - .get((req, res) => res.json({ message: 'Get unique project IDs' })); + .get(controller.getUniqueProjectIds); return toolAvailabilityRouter; };