Skip to content

Commit

Permalink
uaAuthenticated route doctors server side added
Browse files Browse the repository at this point in the history
  • Loading branch information
sinanptm committed Sep 12, 2024
1 parent 94ea740 commit 131534b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/src/presentation/controllers/UnauthenticatedControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { StatusCode } from "../../types";
import UnauthenticatedUseCases from "../../use_case/UnauthenticatedUseCases";
import { NextFunction, Request, Response } from "express";

export default class UnathenicatedControllers {
constructor(private unauthenticatedUseCase: UnauthenticatedUseCases) { }

async getDoctors(req: Request, res: Response, next: NextFunction) {
try {
let offset = parseInt(req.query.offset as string);
let limit = parseInt(req.query.limit as string);

offset = isNaN(offset) || offset < 0 ? 0 : offset;
limit = isNaN(limit) || limit < 0 ? 10 : Math.min(limit, 100);
res.status(StatusCode.Success).json(await this.unauthenticatedUseCase.getDoctors(offset, limit))
} catch (error) {
next(error)
}
}
}
9 changes: 9 additions & 0 deletions server/src/presentation/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ import PatientAuthMiddleware from "../middlewares/PatientAuthMiddleware";
import AdminAuthMiddleware from "../middlewares/AdminAuthMiddleware";
import protectedAdminRoutes from "./admin/AdminRoutes";
import doctorAuthentication from "./doctor/AuthenticationRoutes";
import UnathenicatedControllers from "../controllers/UnauthenticatedControllers";
import UnauthenticatedUseCases from "../../use_case/UnauthenticatedUseCases";
import DoctorRepository from "../../infrastructure/repositories/DoctorRepository";

const app = express();
const tokenService = new TokenService();

const authorizePatient = new PatientAuthMiddleware(tokenService);
const authorizeAdmin = new AdminAuthMiddleware(tokenService);

const doctorRepository = new DoctorRepository()
const unauthenticatedUseCase = new UnauthenticatedUseCases(doctorRepository)
const unauthenticatedController = new UnathenicatedControllers(unauthenticatedUseCase)

const errorHandler = new ErrorHandler();

app.use("/patient/auth", patientAuthentication);
Expand All @@ -25,6 +32,8 @@ app.use("/admin", authorizeAdmin.exec.bind(authorizeAdmin), protectedAdminRoutes

app.use("/doctor/auth", doctorAuthentication);

app.get('/doctors', unauthenticatedController.getDoctors.bind(unauthenticatedController))

app.use(errorHandler.exec.bind(errorHandler));

export default app;
18 changes: 18 additions & 0 deletions server/src/use_case/UnauthenticatedUseCases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import IDoctor from "../domain/entities/IDoctor";
import IDoctorRepository from "../domain/interface/repositories/IDoctorRepository";
import { PaginatedResult } from "../types";


export default class UnauthenticatedUseCases {
constructor(private doctorRepository: IDoctorRepository) { }



async getDoctors(offset: number, limit: number): Promise<PaginatedResult<IDoctor>> {
const isVerified = true;
const isBlocked = false
const data = await this.doctorRepository.findMany(offset, limit, isVerified, isBlocked);
data.items = data.items.filter(item=>item.role!=='admin')
return data;
}
}

1 comment on commit 131534b

@vercel
Copy link

@vercel vercel bot commented on 131534b Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.