You are on page 1of 3

Root reducer -

import { combineReducers } from "redux";


import patientReducer from "./patientReducer";
import userReducer from "./userReducer";
import doctorReducer from "./doctorReducer";

const rootReducer = combineReducers({


patients: patientReducer,
users: userReducer,
doctors: doctorReducer,
});

export default rootReducer;


-----------------------------------------------------------
sagas.js-

import { all } from "redux-saga/effects";


import { fetchPatients } from "./fetchPatientsSaga/fetchPatientsSaga";
import { createPatients } from "./createPatientsSaga/createPatientsSaga";
import { deletePatient } from "./deletePatientsSaga/deletePatientsSaga";
import { updatePatient } from "./updatePatientsSaga/updatePatientsSaga";
import { fetchPatientById } from "./fetchPatientByIdSaga/fetchPatientByIdSaga";
import { fetchDoctors } from "./fetchDoctorsSaga/fetchDoctorsSaga";
import { createDoctors } from "./createDoctorsSaga/createDoctorsSaga";
import { deleteDoctor } from "./deleteDoctorsSaga/deleteDoctorsSaga";
import { updateDoctors } from "./updateDoctorsSaga/updateDoctorsSaga";
import { fetchDoctorById } from "./fetchDoctorByIdSaga/fetchDoctorByIdSaga";

function* rootSaga() {
yield all([
fetchPatients(),
createPatients(),
deletePatient(),
updatePatient(),
fetchPatientById(),
fetchDoctors(),
createDoctors(),
deleteDoctor(),
updateDoctors(),
fetchDoctorById(),
]);
}

export default rootSaga;


-------------------------------------------------------------

appointment controller -
const models = require("../models/index");

const createAppointment = async (req, res) => {


try {
const requiredParams = [
"hospitalId",
"patientId",
"doctorId",
"description",
"disease",
];
const missingParams = requiredParams.filter(
(param) => !(param in req.body)
);
if (missingParams.length > 0) {
return res.status(400).json({
error: `Missing required parameters: ${missingParams.join(", ")}`,
});
}
const appointment = await models.Appointments.create(req.body);
res.status(201).json({ appointment });
} catch (error) {
res.status(500).json({ error: "Failed to create appointment", error });
}
};

module.exports = { createAppointment }

--------------------------------------------------------------
Appointment.js from models -

"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class Appointments extends Model {
static associate(models) {
Appointments.belongsTo(models.Patients, { foreignKey: "patientId" });
Appointments.belongsTo(models.Doctors, { foreignKey: "doctorId" });
}
}
Appointments.init(
{
appointmentsId: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
patientId: {
type: DataTypes.INTEGER,
allowNull: false,
},
doctorId: {
type: DataTypes.INTEGER,
allowNull: false,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
disease: {
type: DataTypes.STRING,
allowNull: false,
},
},

{
sequelize,
modelName: "Appointments",
tableName: "Appointments",
timestamps: true,
}
);
return Appointments;
};

You might also like