Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
fix registerVolunteer, modified volunteersModel
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxiSalguero committed Dec 8, 2024
1 parent f3edfd7 commit ca12e18
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/controllers/volunteersController.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/models/refugeeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const refugeeSchema = new Schema<IRefugee>({
},
opportunities: {
type: [Schema.Types.ObjectId],
ref: "Volunteer",
ref: "VolunteerOpportunity",
default: []
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/models/volunteersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ const VolunteerOpportunitySchema: Schema = new Schema({
},
});

const Volunteer = mongoose.model<IVolunteerOpportunity>('VolunteerOpportunity', VolunteerOpportunitySchema);
const VolunteerOpportunity = mongoose.model<IVolunteerOpportunity>('VolunteerOpportunity', VolunteerOpportunitySchema);

export default Volunteer;
export default VolunteerOpportunity;
9 changes: 4 additions & 5 deletions src/services/adminService.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

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';

export const getDashboardData = async () => {
try {
const [totalUsers, totalOpportunities, totalActivities] = await Promise.all([
Usuario.countDocuments(),
VolunteersModel.countDocuments(),
VolunteerOpportunity.countDocuments(),
ActivityLog.countDocuments(),
]);

Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand Down
15 changes: 7 additions & 8 deletions src/services/volunteersServices.ts
Original file line number Diff line number Diff line change
@@ -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 ({
Expand All @@ -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,
Expand All @@ -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");
}
Expand All @@ -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 }
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit ca12e18

Please sign in to comment.