refacto user connexion
This commit is contained in:
parent
95606f3e5f
commit
844eac4bcd
@ -46,29 +46,6 @@ export default class UserController extends ApiController {
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/idnot/user/login/:idnot")
|
||||
protected async login(req: Request, response: Response) {
|
||||
try {
|
||||
const id = req.params["idnot"];
|
||||
if (!id) throw new Error("idnot is required");
|
||||
|
||||
const payload = await this.authService.getUserJwtPayload(id);
|
||||
if (!payload) {
|
||||
this.httpNotFoundRequest(response);
|
||||
return;
|
||||
}
|
||||
const accessToken = this.authService.generateAccessToken(payload);
|
||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||
|
||||
//success
|
||||
this.httpSuccess(response, { accessToken, refreshToken });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
this.httpInternalError(response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Post("/api/v1/idnot/user/auth/refresh-token")
|
||||
protected async refreshToken(req: Request, response: Response) {
|
||||
try {
|
||||
|
@ -320,6 +320,8 @@ export default class IdNotService extends BaseService {
|
||||
await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, { method: "GET" })
|
||||
).json()) as IOfficeLocation;
|
||||
|
||||
const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } });
|
||||
|
||||
// if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") {
|
||||
// return null;
|
||||
// }
|
||||
@ -362,6 +364,7 @@ export default class IdNotService extends BaseService {
|
||||
userHydrated = User.hydrate<User>(user);
|
||||
const userOfficeHydrated = Office.hydrate<Office>(userOffice!);
|
||||
|
||||
if(office.length === 0) {
|
||||
const officeRoles = await this.officeRolesService.get({
|
||||
where: { office: { idNot: "0000" } },
|
||||
include: { office: true, rules: true },
|
||||
@ -383,6 +386,7 @@ export default class IdNotService extends BaseService {
|
||||
await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated);
|
||||
const documentTypesCreated = await this.duplicateDocumentTypes(documentTypesHydrated, userOfficeHydrated);
|
||||
await this.duplicateDeedTypes(deedTypesHydrated, documentTypesCreated, userOfficeHydrated);
|
||||
}
|
||||
|
||||
const officeRole = await this.getOfficeRole(userData.typeLien.name, user.office_uid);
|
||||
|
||||
@ -412,6 +416,7 @@ export default class IdNotService extends BaseService {
|
||||
let newDocumentTypes: DocumentType[] = [];
|
||||
for (const document of deedType.document_types!) {
|
||||
const newDocumentType = documentTypes.find((documentType) => documentType.name === document.name);
|
||||
if(!newDocumentType) continue;
|
||||
newDocumentTypes.push(newDocumentType!);
|
||||
};
|
||||
deedType.document_types = newDocumentTypes;
|
||||
|
Loading…
x
Reference in New Issue
Block a user