Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions src/image/api/domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface RepositoryImage {
SetPatientImageProfile(image: string, patientEmail : string): Promise<string>;
GetPatientImageProfile(patientEmail: string): Promise<string>;
GetProfessionalImageProfile(professionalEmail: string): Promise<string>;
SetProfessionalImageProfile(image: string, professionalEmail : string): Promise<string>;
}
15 changes: 15 additions & 0 deletions src/image/api/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,19 @@ export async function resolverGetPatientImageProfile(
patientEmail: string,
): Promise<string> {
return image.GetPatientImageProfile(patientEmail);
}

export async function resolverGetProfessionalImageProfile(
image: RepositoryImage,
professionalEmail: string,
): Promise<string> {
return image.GetProfessionalImageProfile(professionalEmail);
}

export async function resolverSetProfessionalImageProfile(
image: RepositoryImage,
data: string,
professionalEmail: string,
): Promise<string> {
return image.SetProfessionalImageProfile(data, professionalEmail);
}
39 changes: 39 additions & 0 deletions src/image/repository/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,43 @@ export class Image implements RepositoryImage {
}
return img.data.toString("base64");
};

public async GetProfessionalImageProfile(
professionalEmail: string,
): Promise<string> {
const professional = await this.dbClient.manager.findOne(PatientEntity, {
where: { email: professionalEmail },
});
if (!professional) {
throw new Error("Professional not found");
}
const img = await this.dbClient.manager.findOne(ImageEntity, {
where: { id: professional.imageProfile },
});
if (!img) {
throw new Error("Image not found");
}
return img.data.toString("base64");
}

public async SetProfessionalImageProfile(
image: string,
professionalEmail: string,
): Promise<string> {
const professional = await this.dbClient.manager.findOne(PatientEntity, {
where: { email: professionalEmail },
});
if (!professional) {
throw new Error("Professional not found");
}
const img = new ImageEntity();
img.data = Buffer.from(image, "base64");
img.filename = name_image("pp");
img.mimetype = "image/png";
img.type = "pp";
await this.dbClient.manager.save(img);
professional.imageProfile = img.id;
await this.dbClient.manager.save(professional);
return "Success";
}
}
97 changes: 96 additions & 1 deletion src/image/routes/routesImage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import express from "express";
import jwtDecode from "jwt-decode";
import { resolverSetPatientImageProfile, resolverGetPatientImageProfile } from "../api/resolver";
import { resolverSetPatientImageProfile, resolverGetPatientImageProfile, resolverGetProfessionalImageProfile, resolverSetProfessionalImageProfile } from "../api/resolver";
import { Image } from "../repository/image";
import { router } from "../../routes/auth/register/register";

const imageRouter = express.Router();
const image = new Image();
Expand Down Expand Up @@ -100,4 +101,98 @@ imageRouter.post("/image/getProfile/patient", async (req, res) => {
}
});

/**
* @swagger
* /image/setProfile/professional:
* post:
* summary: Définit l'image de profil d'un professionnel de santé
* description: Définit l'image de profil d'un professionnel de santé en utilisant le token d'authentification du professionnel de santé
* tags:
* - Professional
* parameters:
* - in: header
* name: Authorization
* schema:
* type: string
* required: true
* description: Token d'authentification JWT (Bearer token) du professionnel de santé
* - in: body
* name: body
* schema:
* type: object
* properties:
* data:
* type: string
* required: true
* description: Données de l'image de profil du professionnel de santé (par exemple, base64)
* responses:
* 201:
* description: Succès - l'image de profil a été définie avec succès
* 401:
* description: Non autorisé - token manquant ou invalide
* 404:
* description: Ressource non trouvée ou autre erreur
*/
imageRouter.post("/image/setProfile/professional", async (req, res) => {
const auth = req.headers["authorization"];
if (!auth) {
res.status(401).send("Unauthorized");
return;
}
const token = auth.split(" ")[1];
if (!token) {
res.status(401).send("Unauthorized");
return;
}
const { data } = req.body;
const professional: any = jwtDecode(token);
try {
res.status(201).send(await resolverSetProfessionalImageProfile(image, data, professional.data.email));
} catch (err: any) {
res.status(404).send(err.message);
}
});

/**
* @swagger
* /image/getProfile/professional:
* post:
* summary: Obtient l'image de profil d'un professionnel de santé
* description: Obtient l'image de profil d'un professionnel de santé en utilisant le token d'authentification du professionnel de santé
* tags:
* - Professional
* parameters:
* - in: header
* name: Authorization
* schema:
* type: string
* required: true
* description: Token d'authentification JWT (Bearer token) du professionnel de santé
* responses:
* 200:
* description: Succès - renvoie l'image de profil du professionnel de santé
* 401:
* description: Non autorisé - token manquant ou invalide
* 404:
* description: Ressource non trouvée ou autre erreur
*/
imageRouter.post("/image/getProfile/professional", async (req, res) => {
const auth = req.headers["authorization"];
if (!auth) {
res.status(401).send("Unauthorized");
return;
}
const token = auth.split(" ")[1];
if (!token) {
res.status(401).send("Unauthorized");
return;
}
const professional: any = jwtDecode(token);
try {
res.status(200).send(await resolverGetProfessionalImageProfile(image, professional.data.email));
} catch (err: any) {
res.status(404).send(err.message);
}
});

module.exports = imageRouter;
9 changes: 6 additions & 3 deletions src/link/api/domain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface RepositoryLink {
LinkPatientToDoctor: (code: number, patientEmail: string) => Promise<string>;
LinkDoctorToPatient: (doctorEmail: string, email: string) => Promise<string>;
LinkPatientToprofessionnal: (code: number, patientEmail: string) => Promise<string>;
LinkprofessionnalToPatient: (professionnalEmail: string, email: string) => Promise<string>;
getLinkPatient: (patientEmail: string) => Promise<any>;
getLinkDoctor: (doctorEmail: string) => Promise<any>;
getLinkprofessionnal: (professionnalEmail: string) => Promise<any>;

removeLinkPatient: (patientEmail: string, professionalEmail : string) => Promise<any>;
removeLinkprofessionnal: (professionnalEmail: string, patientEmail : string) => Promise<any>;
}
32 changes: 24 additions & 8 deletions src/link/api/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { RepositoryLink } from "./domain";

export async function resolverLinkPatientToDoctor(
export async function resolverLinkPatientToprofessionnal(
link: RepositoryLink,
code: number,
patientEmail: string,
): Promise<string> {
return link.LinkPatientToDoctor(code, patientEmail);
return link.LinkPatientToprofessionnal(code, patientEmail);
}

export async function resolverLinkDoctorToPatient(
export async function resolverLinkprofessionnalToPatient(
link: RepositoryLink,
doctorEmail: string,
professionnalEmail: string,
email: string,
): Promise<string> {
return link.LinkDoctorToPatient(doctorEmail, email);
return link.LinkprofessionnalToPatient(professionnalEmail, email);
}

export async function resolverGetLinkPatient(
Expand All @@ -23,9 +23,25 @@ export async function resolverGetLinkPatient(
return link.getLinkPatient(patientEmail);
}

export async function resolverGetLinkDoctor(
export async function resolverGetLinkprofessionnal(
link: RepositoryLink,
doctorEmail: string,
professionnalEmail: string,
): Promise<any> {
return link.getLinkDoctor(doctorEmail);
return link.getLinkprofessionnal(professionnalEmail);
}

export async function resolverRemoveLinkPatient(
link: RepositoryLink,
patientEmail: string,
professionalEmail : string
): Promise<any> {
return link.removeLinkPatient(patientEmail, professionalEmail);
}

export async function resolverRemoveLinkprofessionnal(
link: RepositoryLink,
professionnalEmail: string,
patientEmail : string
): Promise<any> {
return link.removeLinkprofessionnal(professionnalEmail, patientEmail);
}
Loading