diff --git a/src/app/api/idnot/OfficeController.ts b/src/app/api/idnot/OfficeController.ts new file mode 100644 index 00000000..3e00e7bf --- /dev/null +++ b/src/app/api/idnot/OfficeController.ts @@ -0,0 +1,34 @@ +import { Response, Request } from "express"; +import { Controller, Get } from "@ControllerPattern/index"; +import ApiController from "@Common/system/controller-pattern/ApiController"; +import { Service } from "typedi"; +import IdNotService from "@Services/common/IdNotService/IdNotService"; + +@Controller() +@Service() +export default class UserController extends ApiController { + constructor (private idNotService: IdNotService) { + super(); + } + + @Get("/api/v1/idnot/office/:uid/office-memberships") + protected async getOfficeMemberships(req: Request, response: Response) { + try { + const uid = req.params["uid"]; + if (!uid) { + this.httpBadRequest(response, "uid is required"); + return; + } + + const officeMemberships = await this.idNotService.getOfficeMemberships(uid); + this.httpSuccess(response, officeMemberships); + } catch (error) { + console.log(error); + this.httpInternalError(response); + return; + } + } +} + + + diff --git a/src/app/index.ts b/src/app/index.ts index 510d903d..20343be2 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -48,7 +48,7 @@ import UserNotificationController from "./api/notary/UserNotificationController" import AuthController from "./api/customer/AuthController"; import NotaryOfficeRibController from "./api/notary/OfficeRibController"; import CustomerOfficeRibController from "./api/customer/OfficeRibController"; - +import IdNotOfficeController from "./api/idnot/OfficeController"; /** * @description This allow to declare all controllers used in the application */ @@ -104,5 +104,6 @@ export default { Container.get(AuthController); Container.get(NotaryOfficeRibController); Container.get(CustomerOfficeRibController); + Container.get(IdNotOfficeController) }, }; diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 047868af..051132aa 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -173,6 +173,19 @@ export default class IdNotService extends BaseService { } } + public async getOfficeMemberships(officeId: string) { + const officeInfos = await this.officeService.getByUid(officeId); + const office = Office.hydrate(officeInfos!); + const searchParams = new URLSearchParams({ + key: this.variables.IDNOT_API_KEY, + }); + return (await ( + await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/entites/${office.idNot}/personnes?` + searchParams, { + method: "GET", + }) + ).json()) as any; + } + public getOfficeStatus(statusName: string) { switch (statusName) { case "Pourvu":