diff --git a/src/controllers/volunteersController.ts b/src/controllers/volunteersController.ts index a0fe916..1398f75 100644 --- a/src/controllers/volunteersController.ts +++ b/src/controllers/volunteersController.ts @@ -1,9 +1,8 @@ import { Request, Response } from 'express'; import jwt from 'jsonwebtoken'; import * as volunteerService from '../services/volunteersServices'; -import mongoose from 'mongoose'; import Refugee from '../models/refugeeModel'; -import Volunteer from '../models/volunteersModel'; +import VolunteerOpportunity from '../models/volunteersModel'; const handleResponse = (res: Response, data: any, success: boolean, message: string, statusCode: number) => { res.status(statusCode).json({ @@ -144,7 +143,7 @@ export const getVolunteerOpportunitiesController = async (req: Request, res: Res return res.status(404).json({ error: 'Refugio no encontrado' }); } - const oportunidades = await Volunteer.find({ _id: { $in: refugio.opportunities } }); + const oportunidades = await VolunteerOpportunity.find({ _id: { $in: refugio.opportunities } }); res.status(200).json({ refugio: refugio.name_refugee, diff --git a/src/models/refugeeModel.ts b/src/models/refugeeModel.ts index fa1b8ef..c58ee9e 100644 --- a/src/models/refugeeModel.ts +++ b/src/models/refugeeModel.ts @@ -41,7 +41,7 @@ const refugeeSchema = new Schema({ }, opportunities: { type: [Schema.Types.ObjectId], - ref: "Volunteer", + ref: "VolunteerOpportunity", default: [] } }); diff --git a/src/models/volunteersModel.ts b/src/models/volunteersModel.ts index 2ae0d73..f9b100e 100644 --- a/src/models/volunteersModel.ts +++ b/src/models/volunteersModel.ts @@ -33,6 +33,6 @@ const VolunteerOpportunitySchema: Schema = new Schema({ }, }); -const Volunteer = mongoose.model('VolunteerOpportunity', VolunteerOpportunitySchema); +const VolunteerOpportunity = mongoose.model('VolunteerOpportunity', VolunteerOpportunitySchema); -export default Volunteer; +export default VolunteerOpportunity; diff --git a/src/services/adminService.ts b/src/services/adminService.ts index d63fe1e..11aff2f 100644 --- a/src/services/adminService.ts +++ b/src/services/adminService.ts @@ -1,12 +1,11 @@ import Usuario from '../models/userModel'; -import VolunteersModel from '../models/volunteersModel'; import ActivityLog from '../models/adminModel'; import AnimalModel from '../models/animalModel'; import AdoptionModel from '../models/adoptionRequests'; import Refugee from '../models/refugeeModel'; import DonationRequest from '../models/donationsRequest'; -import Volunteer from '../models/volunteersModel'; +import VolunteerOpportunity from '../models/volunteersModel'; import AdoptionRequests from '../models/adoptionRequests'; import Animal from '../models/animalModel'; @@ -14,7 +13,7 @@ export const getDashboardData = async () => { try { const [totalUsers, totalOpportunities, totalActivities] = await Promise.all([ Usuario.countDocuments(), - VolunteersModel.countDocuments(), + VolunteerOpportunity.countDocuments(), ActivityLog.countDocuments(), ]); @@ -28,7 +27,7 @@ export const getDashboardData = async () => { const totalRefugees = await Refugee.countDocuments(); const totalDonationsActive = await DonationRequest.countDocuments({ status: 'active' }); const totalDonationsCompleted = await DonationRequest.countDocuments({ status: 'completed' }); - const totalVolunteerOpportunities = await Volunteer.countDocuments(); + const totalVolunteerOpportunities = await VolunteerOpportunity.countDocuments(); const totalLogs = await ActivityLog.countDocuments(); const metrics = await getMetrics(); @@ -82,7 +81,7 @@ export const getMetrics = async () => { const activeDonations = await DonationRequest.countDocuments({ status: 'active' }) || 0; const completedDonations = await DonationRequest.countDocuments({ status: 'completed' }) || 0; - const totalVolunteerOpportunities = await Volunteer.countDocuments() || 0; + const totalVolunteerOpportunities = await VolunteerOpportunity.countDocuments() || 0; const totalLogs = await ActivityLog.countDocuments() || 0; diff --git a/src/services/volunteersServices.ts b/src/services/volunteersServices.ts index a9360a1..8574c63 100644 --- a/src/services/volunteersServices.ts +++ b/src/services/volunteersServices.ts @@ -1,18 +1,17 @@ import mongoose from 'mongoose'; -import VolunteersModel from '../models/volunteersModel'; +import VolunteerOpportunity from '../models/volunteersModel'; import Refugee, { IRefugee } from '../models/refugeeModel'; import Usuario from '../models/userModel'; -import Volunteer from '../models/volunteersModel'; import mailService from './mailService'; export const getVolunteerOpportunities = async () => { - return VolunteersModel.find().populate('refugee_id', 'name'); + return VolunteerOpportunity.find().populate('refugee_id', 'name'); }; export const getOpportunitiesByRefugeeId = async (refugee_id: string) => { const objectIdRefugeeId = new mongoose.Types.ObjectId(refugee_id) - return VolunteersModel.find({ refugee_id: objectIdRefugeeId }).populate('refugee_id', 'name'); + return VolunteerOpportunity.find({ refugee_id: objectIdRefugeeId }).populate('refugee_id', 'name'); }; export const createVolunteerOpportunity = async ({ @@ -32,7 +31,7 @@ export const createVolunteerOpportunity = async ({ throw new Error("Por favor, completa todos los campos requeridos"); } - const opportunity = new VolunteersModel({ + const opportunity = new VolunteerOpportunity({ refugee_id, user_id, description, @@ -44,7 +43,7 @@ export const createVolunteerOpportunity = async ({ }; export const deleteVolunteerOpportunity = async (refugee_id: string) => { - const result = await VolunteersModel.deleteMany({ refugee_id }); + const result = await VolunteerOpportunity.deleteMany({ refugee_id }); if (result.deletedCount === 0) { throw new Error("No se encontrĂ³ ninguna oportunidad de voluntariado para el refugio especificado"); } @@ -62,7 +61,7 @@ export const updateVolunteerOpportunity = async ( throw new Error("Opporunity ID is required"); } - const updatedOpportunity = await VolunteersModel.findByIdAndUpdate( + const updatedOpportunity = await VolunteerOpportunity.findByIdAndUpdate( opportunity_id, updates, { new: true } @@ -99,7 +98,7 @@ export const registerVolunteer = async (input: VolunteerRegistrationInput, userI throw new Error('Oportunidad no encontrada en este refugio'); } - const detalleOportunidad = await Volunteer.findById(oportunidad); + const detalleOportunidad = await VolunteerOpportunity.findById(oportunidad); if (!detalleOportunidad) { throw new Error('Detalles de la oportunidad no encontrados'); }