Entrypoint get office memberships
This commit is contained in:
parent
2d09e43013
commit
133e3e96ca
34
src/app/api/idnot/OfficeController.ts
Normal file
34
src/app/api/idnot/OfficeController.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
},
|
||||
};
|
||||
|
@ -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<Office>(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":
|
||||
|
Loading…
x
Reference in New Issue
Block a user