Skip to content

Commit

Permalink
fix: graficos
Browse files Browse the repository at this point in the history
  • Loading branch information
alanagabriele committed Jul 15, 2024
1 parent cd265f3 commit ecd54dd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/modules/dados/dados.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export class DadosService {
take: limit,
skip: (page - 1) * limit,
orderBy: { createdAt: 'asc' },
select: {
id: true,
rpmMotorDir: true,
rpmMotorEsq: true,
aceleracaoInstantanea: true,
velocidadeInstantanea: true,
tensao: true,
},
}),
await this.prismaService.dados.count(),
]);
Expand All @@ -70,8 +78,6 @@ export class DadosService {

item.velocidadeInstantaneaFormatted =
item.velocidadeInstantanea?.toFixed(2) || 0;

item.createdAtFormatted = new Date(item.createdAt).toLocaleString();
});

return new ResponseMessageDto({
Expand Down
35 changes: 31 additions & 4 deletions src/modules/trilha/trilha.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export class TrilhaService {
where: { id: trilhaId },
take: limit,
skip: (page - 1) * limit,
select: {
id: true,
isMoving: true,
startMovingDatetime: true,
endMovingDatetime: true,
failed: true,
},
}),
await this.prismaService.trilha.count({
where: { id: trilhaId },
Expand All @@ -94,12 +101,13 @@ export class TrilhaService {
(item.failed ? 'Falhado' : 'Bem-sucedido');

item.isMovingFormatted = item.isMoving ? 'Sim' : 'Não';
item.startMovingDatetimeFormatted = new Date(
item.startMovingDatetimeFormatted = this.formatarDataHora(
item.startMovingDatetime,
).toLocaleString();
);

item.endMovingDatetimeFormatted =
item?.endMovingDatetime?.toLocaleString();
item.endMovingDatetimeFormatted = this.formatarDataHora(
item.endMovingDatetime,
);
});

return new ResponseMessageDto({
Expand Down Expand Up @@ -163,4 +171,23 @@ export class TrilhaService {
);
}
}

formatarDataHora(isoString: string): string {
const data = new Date(isoString);

const dia = data.getDate().toString().padStart(2, '0');
const mes = (data.getMonth() + 1).toString().padStart(2, '0');
const ano = data.getFullYear();

let horas = data.getHours();
const minutos = data.getMinutes().toString().padStart(2, '0');
const segundos = data.getSeconds().toString().padStart(2, '0');

const periodo = horas >= 12 ? 'PM' : 'AM';
horas = horas % 12 || 12; // Converte 0 para 12 para formato 12h

const horaFormatada = horas.toString().padStart(2, '0');

return `${dia}/${mes}/${ano}, ${horaFormatada}:${minutos}:${segundos} ${periodo}`;
}
}

0 comments on commit ecd54dd

Please sign in to comment.