Skip to content

Commit

Permalink
Merge pull request #80 from dscdut/feature/auth
Browse files Browse the repository at this point in the history
feat: add api get auth doctor and patient
  • Loading branch information
LongTCH authored Feb 21, 2024
2 parents 419291e + f04213d commit fd57f98
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/src/core/api/auth/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PhoneVerifiedRegisterDto,
} from 'core/modules/auth';
import { ValidHttpResponse } from 'packages/handler/response/validHttp.response';
import { DoctorDto, PatientDto } from 'core/modules/user';

class Controller {
constructor() {
Expand Down Expand Up @@ -47,6 +48,16 @@ class Controller {
);
return ValidHttpResponse.toOkResponse(data);
};

getAuthDoctor = async req => {
const data = await this.service.getDoctorById(req.user.payload.id);
return ValidHttpResponse.toOkResponse(DoctorDto(data));
};

getAuthPatient = async req => {
const data = await this.service.getPatientById(req.user.payload.id);
return ValidHttpResponse.toOkResponse(PatientDto(data));
};
}

export const AuthController = new Controller();
14 changes: 14 additions & 0 deletions backend/src/core/api/auth/auth.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const AuthResolver = Module.builder()
controller: AuthController.doctorLogin,
model: { $ref: 'DoctorLoginResponseDto' },
},
{
route: '/doctor/profile',
method: 'get',
preAuthorization: true,
controller: AuthController.getAuthDoctor,
model: { $ref: 'DoctorDto' },
},
{
route: '/register/doctor',
method: 'post',
Expand All @@ -40,6 +47,13 @@ export const AuthResolver = Module.builder()
controller: AuthController.patientLogin,
model: { $ref: 'PatientLoginResponseDto' },
},
{
route: '/patient/profile',
method: 'get',
preAuthorization: true,
controller: AuthController.getAuthPatient,
model: { $ref: 'PatientDto' },
},
{
route: '/otp',
method: 'post',
Expand Down
10 changes: 10 additions & 0 deletions backend/src/core/modules/auth/service/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ class Service {
return MessageDto({ message: MESSAGE.VERIFY_SUCCESS });
}

async getDoctorById(id) {
const doctor = await this.userService.findDoctorById(id);
return doctor;
}

async getPatientById(id) {
const patient = await this.userService.findPatientById(id);
return patient;
}

#getUserInfo = user => pick(user, ['_id', 'email', 'username', 'roles']);
}

Expand Down

0 comments on commit fd57f98

Please sign in to comment.