agent and tpe save done
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user