Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure Files #9

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/src/models/appointment.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose, { Document, Schema } from 'mongoose';

interface Appointment {
interface IAppointment {
doctorID: mongoose.Schema.Types.ObjectId;
patientID: mongoose.Schema.Types.ObjectId;
status: 'Upcoming' | 'Completed' | 'Cancelled' | 'Rescheduled';
Expand All @@ -10,8 +10,8 @@ interface Appointment {
isFollowUp: boolean;
previousAppointment?: mongoose.Schema.Types.ObjectId;
}

const appointmentSchema = new Schema<Appointment & Document>({
type IAppointmentDocument = IAppointment & Document;
const appointmentSchema = new Schema<IAppointmentDocument>({
doctorID: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
Expand All @@ -32,6 +32,6 @@ const appointmentSchema = new Schema<Appointment & Document>({
appointmentSchema.index({ doctorID: 1 });
appointmentSchema.index({ patientID: 1 });

const AppointmentModel = mongoose.model<Appointment & Document>('Appointment', appointmentSchema);
const AppointmentModel = mongoose.model<IAppointmentDocument>('Appointment', appointmentSchema);

export default AppointmentModel;
6 changes: 3 additions & 3 deletions server/src/models/chatroom.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface IChatRoom {
messages: ChatMessage[];
date: Date;
}

const chatRoomSchema = new Schema<IChatRoom>({
type IChatRoomDocument = IChatRoom & Document;
const chatRoomSchema = new Schema<IChatRoomDocument>({
patientID: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
Expand All @@ -39,6 +39,6 @@ const chatRoomSchema = new Schema<IChatRoom>({
chatRoomSchema.index({ patientID: 1 });
chatRoomSchema.index({ medicID: 1 });

const ChatRoomModel = mongoose.model<IChatRoom>('ChatRoom', chatRoomSchema);
const ChatRoomModel = mongoose.model<IChatRoomDocument>('ChatRoom', chatRoomSchema);

export default ChatRoomModel;
8 changes: 4 additions & 4 deletions server/src/models/contract.model.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import mongoose, { Document, Schema } from 'mongoose';

interface IContract extends Document {
interface IContract {
doctorID: mongoose.Schema.Types.ObjectId;
start: Date;
state: 'Rejected' | 'Accepted' | 'Pending';
end: Date;
markUpProfit: number;
}

const contractSchema = new Schema<IContract>({
type IContractDocument = IContract & Document;
const contractSchema = new Schema<IContractDocument>({
doctorID: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
Expand All @@ -20,6 +20,6 @@ const contractSchema = new Schema<IContract>({
markUpProfit: { type: Number, required: true }
});
contractSchema.index({ doctorID: 1 });
const ContractModel = mongoose.model<IContract>('Contract', contractSchema);
const ContractModel = mongoose.model<IContractDocument>('Contract', contractSchema);

export default ContractModel;
8 changes: 4 additions & 4 deletions server/src/models/prescription.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface MedicineDosage {
dosage: string;
}

interface IPrescription extends Document {
interface IPrescription {
doctorID: mongoose.Types.ObjectId;
patientID: mongoose.Types.ObjectId;
medicines: MedicineDosage[];
Expand All @@ -14,8 +14,8 @@ interface IPrescription extends Document {
dateIssued: Date;
isSubmitted: boolean;
}

const prescriptionSchema = new Schema<IPrescription>({
type IPrescriptionDocument = IPrescription & Document;
const prescriptionSchema = new Schema<IPrescriptionDocument>({
doctorID: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
Expand All @@ -42,6 +42,6 @@ const prescriptionSchema = new Schema<IPrescription>({
});
prescriptionSchema.index({ doctorID: 1 });
prescriptionSchema.index({ patientID: 1 });
const PrescriptionModel = mongoose.model<IPrescription>('Prescription', prescriptionSchema);
const PrescriptionModel = mongoose.model<IPrescriptionDocument>('Prescription', prescriptionSchema);

export default PrescriptionModel;
8 changes: 4 additions & 4 deletions server/src/models/request.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ interface ILicenses {
licenseID: string;
licenseImage: string;
}
interface IRequest extends Document {
interface IRequest {
medicID: mongoose.Schema.Types.ObjectId;
ID: String;
degree: string[];
licenses: string[];
status: 'Pending' | 'Approved' | 'Rejected';
date: Date;
}

const requestSchema = new Schema<IRequest>({
type IRequestDocument = IRequest & Document;
const requestSchema = new Schema<IRequestDocument>({
medicID: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
ID: { type: String, required: true },
degree: { type: [String], required: true },
Expand All @@ -21,6 +21,6 @@ const requestSchema = new Schema<IRequest>({
date: { type: Date, default: Date.now(), required: true }
});

const Request = mongoose.model<IRequest>('Request', requestSchema);
const Request = mongoose.model<IRequestDocument>('Request', requestSchema);

export default Request;
78 changes: 41 additions & 37 deletions server/src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import mongoose, { Document, Schema } from 'mongoose';

interface FamilyMemberWithID {
userID: mongoose.Types.ObjectId;
relation: "Husband" | "Wife" | "Child";
relation: 'Husband' | 'Wife' | 'Child';
}

interface FamilyMemberWithDetails {
name: string;
nationalID: string;
phone: string;
relation: "Husband" | "Wife" | "Child";
relation: 'Husband' | 'Wife' | 'Child';
}

type FamilyMember = FamilyMemberWithID | FamilyMemberWithDetails;
Expand All @@ -31,10 +31,10 @@ interface ICommonUser {
email: string;
password: string;
birthDate: Date;
gender: "Male" | "Female";
gender: 'Male' | 'Female';
phone: string;
addresses: string[];
role: "Patient" | "Doctor" | "Administrator";
role: 'Patient' | 'Doctor' | 'Administrator';
profileImage: string;
isEmailVerified: boolean;
wallet: number;
Expand Down Expand Up @@ -90,16 +90,16 @@ const dailyScheduleSchema = new mongoose.Schema({
},
maxPatients: {
type: Number,
required: true,
},
required: true
}
});

const userSchema = new Schema<IUserDocument>(
{
name: {
first: { type: String, required: true },
middle: String,
last: { type: String, required: true },
last: { type: String, required: true }
},
email: {
type: String,
Expand All @@ -108,18 +108,18 @@ const userSchema = new Schema<IUserDocument>(
trim: true,
validate(value: string) {
return validator.isEmail(value);
},
}
},
username: { type: String, required: true, unique: true },
password: { type: String, required: true },
birthDate: { type: Date, required: true },
gender: { type: String, enum: ["Male", "Female"], required: true },
gender: { type: String, enum: ['Male', 'Female'], required: true },
phone: { type: String, required: true },
addresses: { type: [String], required: false },
role: {
type: String,
enum: ["Patient", "Doctor", "Administrator"],
required: true,
enum: ['Patient', 'Doctor', 'Administrator'],
required: true
},
profileImage: { type: String, required: true },
isEmailVerified: { type: Boolean, required: true },
Expand All @@ -134,8 +134,8 @@ const userSchema = new Schema<IUserDocument>(
}
],
required: function () {
return this.role === "Patient";
},
return this.role === 'Patient';
}
},
family: {
type: [
Expand All @@ -146,15 +146,16 @@ const userSchema = new Schema<IUserDocument>(
phone: String,
relation: {
type: String,
enum: ["Husband", "Wife", "Child"],
required: true,
},
},
enum: ['Husband', 'Wife', 'Child'],
required: true
}
}
],
required: function () {
return this.role === "Patient";
return this.role === 'Patient';
},
validate: {
//TODO
validator: function (arr: any) {
try {
arr.forEach((elem: any) => {
Expand All @@ -176,43 +177,43 @@ const userSchema = new Schema<IUserDocument>(
}
],
required: function () {
return this.role === "Patient";
},
return this.role === 'Patient';
}
},
package: {
type: {
packageID: {
type: mongoose.Schema.Types.ObjectId,
ref: "Package",
required: true,
ref: 'Package',
required: true
},
packageStatus: {
type: String,
enum: ['subscribed', 'unsubscribed', 'cancelled'],
required: true
},
endDate: { type: Date, required: true },
endDate: { type: Date, required: true }
},
required: false
},

hourRate: {
type: Number,
required: function () {
return this.role === "Doctor";
},
return this.role === 'Doctor';
}
},
hospital: {
type: String,
required: function () {
return this.role === "Doctor";
},
return this.role === 'Doctor';
}
},
specialty: {
type: String,
required: function () {
return this.role === "Doctor";
},
return this.role === 'Doctor';
}
},
weeklySlots: {
type: {
Expand All @@ -222,7 +223,7 @@ const userSchema = new Schema<IUserDocument>(
Wednesday: [dailyScheduleSchema],
Thursday: [dailyScheduleSchema],
Friday: [dailyScheduleSchema],
Saturday: [dailyScheduleSchema],
Saturday: [dailyScheduleSchema]
},
required: function () {
return this.role === 'Doctor';
Expand All @@ -237,11 +238,11 @@ const userSchema = new Schema<IUserDocument>(
},
{
toObject: {
virtuals: true,
virtuals: true
},
toJSON: {
virtuals: true,
},
virtuals: true
}
}
);

Expand Down Expand Up @@ -271,9 +272,7 @@ userSchema.pre<IUserDocument>('save', function (next) {
next();
});

userSchema.methods.isCorrectPassword = function (
enteredPassword: string
): boolean {
userSchema.methods.isCorrectPassword = function (enteredPassword: string): boolean {
return bcrypt.compareSync(enteredPassword, this.password);
};

Expand All @@ -282,7 +281,12 @@ userSchema.methods.isCorrectPassword = function (
// https://docs.mongodb.com/manual/indexes/#default-id-index

const UserModel = mongoose.model<IUserDocument>('User', userSchema);

userSchema.virtual('contract', {
ref: 'Contract',
localField: '_id',
foreignKey: 'doctorID',
justOne: true
});
export default UserModel;
export { FamilyMember, IEmergencyContact };
export { IUser, IUserDocument, IPatient, IDoctor, ICommonUser };
2 changes: 1 addition & 1 deletion server/src/routes/auth.route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express, { Request, Response } from 'express';
import { login, logout, register, changePassword } from '../services/auth';
import { login, logout, register, changePassword } from '../services/auth.service';
import controller from '../controllers/controller';
const loginRouter = express.Router();

Expand Down
4 changes: 0 additions & 4 deletions server/src/routes/chatroom.route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import express from 'express';
const router = express.Router();
// http methods required for this router

//

export default router;

4 changes: 0 additions & 4 deletions server/src/routes/contract.route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import express from 'express';
const router = express.Router();
// http methods required for this router

//

export default router;

6 changes: 3 additions & 3 deletions server/src/routes/general.route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import express, { Request, Response } from 'express';
import { login, logout, register, changePassword } from '../services/auth';
import { login, logout, register, changePassword } from '../services/auth.service';
import controller from '../controllers/controller';
import { viewAllDoctorsForPatient } from '../services/patient';
import { getAllDoctor } from '../services/doctor';
import { viewAllDoctorsForPatient } from '../services/patient.service';
import { getAllDoctor } from '../services/doctor.service';

import { decodeJWTToken } from '../middlewares/authorization';

Expand Down
3 changes: 0 additions & 3 deletions server/src/routes/notification.route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import express from 'express';
const router = express.Router();
// http methods required for this router

//

export default router;
Loading