refacto user connexion
This commit is contained in:
parent
95606f3e5f
commit
844eac4bcd
@ -37,30 +37,7 @@ export default class UserController extends ApiController {
|
|||||||
const payload = await this.authService.getUserJwtPayload(user.idNot);
|
const payload = await this.authService.getUserJwtPayload(user.idNot);
|
||||||
const accessToken = this.authService.generateAccessToken(payload);
|
const accessToken = this.authService.generateAccessToken(payload);
|
||||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||||
|
|
||||||
this.httpSuccess(response, { accessToken, refreshToken });
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
this.httpInternalError(response);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 });
|
this.httpSuccess(response, { accessToken, refreshToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
@ -319,6 +319,8 @@ export default class IdNotService extends BaseService {
|
|||||||
const officeLocationData = (await (
|
const officeLocationData = (await (
|
||||||
await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, { method: "GET" })
|
await fetch(`${this.variables.IDNOT_API_BASE_URL + userData.entite.locationsUrl}?` + searchParams, { method: "GET" })
|
||||||
).json()) as IOfficeLocation;
|
).json()) as IOfficeLocation;
|
||||||
|
|
||||||
|
const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } });
|
||||||
|
|
||||||
// if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") {
|
// if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") {
|
||||||
// return null;
|
// return null;
|
||||||
@ -362,28 +364,30 @@ export default class IdNotService extends BaseService {
|
|||||||
userHydrated = User.hydrate<User>(user);
|
userHydrated = User.hydrate<User>(user);
|
||||||
const userOfficeHydrated = Office.hydrate<Office>(userOffice!);
|
const userOfficeHydrated = Office.hydrate<Office>(userOffice!);
|
||||||
|
|
||||||
const officeRoles = await this.officeRolesService.get({
|
if(office.length === 0) {
|
||||||
where: { office: { idNot: "0000" } },
|
const officeRoles = await this.officeRolesService.get({
|
||||||
include: { office: true, rules: true },
|
where: { office: { idNot: "0000" } },
|
||||||
});
|
include: { office: true, rules: true },
|
||||||
const deedTypes = await this.deedTypesService.get({
|
});
|
||||||
where: { office: { idNot: "0000" } },
|
const deedTypes = await this.deedTypesService.get({
|
||||||
include: { office: true, document_types: { include: { office: true } } },
|
where: { office: { idNot: "0000" } },
|
||||||
});
|
include: { office: true, document_types: { include: { office: true } } },
|
||||||
const documentTypes = await this.documentTypesService.get({
|
});
|
||||||
where: { office: { idNot: "0000" } },
|
const documentTypes = await this.documentTypesService.get({
|
||||||
include: { office: true },
|
where: { office: { idNot: "0000" } },
|
||||||
});
|
include: { office: true },
|
||||||
|
});
|
||||||
const officeRolesHydrated = OfficeRole.hydrateArray<OfficeRole>(officeRoles);
|
|
||||||
const deedTypesHydrated = DeedType.hydrateArray<DeedType>(deedTypes);
|
const officeRolesHydrated = OfficeRole.hydrateArray<OfficeRole>(officeRoles);
|
||||||
const documentTypesHydrated = DocumentType.hydrateArray<DocumentType>(documentTypes);
|
const deedTypesHydrated = DeedType.hydrateArray<DeedType>(deedTypes);
|
||||||
|
const documentTypesHydrated = DocumentType.hydrateArray<DocumentType>(documentTypes);
|
||||||
|
|
||||||
await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated);
|
|
||||||
const documentTypesCreated = await this.duplicateDocumentTypes(documentTypesHydrated, userOfficeHydrated);
|
await this.duplicateOfficeRoles(officeRolesHydrated, userOfficeHydrated);
|
||||||
await this.duplicateDeedTypes(deedTypesHydrated, documentTypesCreated, 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);
|
const officeRole = await this.getOfficeRole(userData.typeLien.name, user.office_uid);
|
||||||
|
|
||||||
if (officeRole) {
|
if (officeRole) {
|
||||||
@ -412,6 +416,7 @@ export default class IdNotService extends BaseService {
|
|||||||
let newDocumentTypes: DocumentType[] = [];
|
let newDocumentTypes: DocumentType[] = [];
|
||||||
for (const document of deedType.document_types!) {
|
for (const document of deedType.document_types!) {
|
||||||
const newDocumentType = documentTypes.find((documentType) => documentType.name === document.name);
|
const newDocumentType = documentTypes.find((documentType) => documentType.name === document.name);
|
||||||
|
if(!newDocumentType) continue;
|
||||||
newDocumentTypes.push(newDocumentType!);
|
newDocumentTypes.push(newDocumentType!);
|
||||||
};
|
};
|
||||||
deedType.document_types = newDocumentTypes;
|
deedType.document_types = newDocumentTypes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user