agent and tpe save done

This commit is contained in:
OnlyPapy98
2026-01-06 14:07:09 +01:00
parent 95095016d2
commit 0ae7fa316e
33 changed files with 1910 additions and 525 deletions

View File

@@ -66,7 +66,7 @@ interface AgentApiResponse {
statutMarital?: string;
epoux?: string;
autreTelephone?: string;
tpes?: TpeApiResponse[];
tpes?: TpeDevice;
createdAt?: string;
updatedAt?: string;
createdBy?: string;
@@ -88,44 +88,37 @@ export class AgentService {
}
// Transform API TPE response to TpeDevice
private transformTpe(apiTpe: TpeApiResponse): TpeDevice {
const transformStatut = (apiStatut: string): TpeStatus => {
const upperStatut = apiStatut.toUpperCase() as TpeStatus;
const validStatuses: TpeStatus[] = [
'VALIDE',
'INVALIDE',
'EN_PANNE',
'BLOQUE',
'DISPONIBLE',
'AFFECTE',
'EN_MAINTENANCE',
'HORS_SERVICE',
'VOLE',
];
return validStatuses.includes(upperStatut) ? upperStatut : 'INVALIDE';
};
// private transformTpe(apiTpe: TpeApiResponse): TpeDevice {
// const transformStatut = (apiStatut: string): TpeStatus => {
// const upperStatut = apiStatut.toUpperCase() as TpeStatus;
// const validStatuses: TpeStatus[] = [
// 'ACTIF',
// 'HORS_SERVICE'
// ];
// return validStatuses.includes(upperStatut) ? upperStatut : 'INVALIDE';
// };
// Transform agent if it's an object (not just a string reference)
let transformedAgent: Agent | undefined = undefined;
if (apiTpe.agent && typeof apiTpe.agent === 'object' && apiTpe.agent.id) {
// If agent is a full object, transform it
transformedAgent = this.transformAgent(apiTpe.agent as any);
}
// // Transform agent if it's an object (not just a string reference)
// let transformedAgent: Agent | undefined = undefined;
// if (apiTpe.agent && typeof apiTpe.agent === 'object' && apiTpe.agent.id) {
// // If agent is a full object, transform it
// transformedAgent = this.transformAgent(apiTpe.agent as any);
// }
return {
id: String(apiTpe.id),
imei: apiTpe.imei,
serial: apiTpe.serial,
type: apiTpe.type as TpeType,
marque: apiTpe.marque,
modele: apiTpe.modele,
statut: transformStatut(apiTpe.statut),
agent: transformedAgent,
assigne: apiTpe.assigne,
createdAt: apiTpe.createdAt,
updatedAt: apiTpe.updatedAt,
};
}
// return {
// id: String(apiTpe.id),
// imei: apiTpe.imei,
// serial: apiTpe.serial,
// type: apiTpe.type as TpeType,
// marque: apiTpe.marque,
// modele: apiTpe.modele,
// statut: transformStatut(apiTpe.statut),
// agent: transformedAgent,
// assigne: apiTpe.assigne,
// createdAt: apiTpe.createdAt,
// updatedAt: apiTpe.updatedAt,
// };
// }
// Transform API response to Agent
private transformAgent(apiAgent: AgentApiResponse): Agent {
@@ -166,10 +159,7 @@ export class AgentService {
statutMarital: apiAgent.statutMarital,
epoux: apiAgent.epoux,
autreTelephone: apiAgent.autreTelephone,
tpes: apiAgent.tpes?.map((tpe) => {
const transformed = this.transformTpe(tpe);
return transformed;
}),
tpes: apiAgent.tpes ,
createdAt: apiAgent.createdAt,
updatedAt: apiAgent.updatedAt,
createdBy: apiAgent.createdBy,