From 51581cfb992c3fab98b66f899bcded157e6dc8e1 Mon Sep 17 00:00:00 2001 From: Alexandre Batistella Bellas Date: Mon, 9 Sep 2024 20:48:44 -0300 Subject: [PATCH] feat: permitir filtro de produtos com horas --- src/entities/@shared/entity.ts | 6 ++++-- src/entities/produtos/index.ts | 12 ++++++++---- src/helpers/functions/convert-date-to-string.ts | 10 +++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/entities/@shared/entity.ts b/src/entities/@shared/entity.ts index fa56658..48b2ba8 100644 --- a/src/entities/@shared/entity.ts +++ b/src/entities/@shared/entity.ts @@ -21,11 +21,13 @@ export abstract class Entity { * Prepara um parâmetro de data para chamada do repositório. * * @param param Parâmetro do tipo `string`, `Date` ou `undefined` + * @param includeTime Define se horas e minutos são inclusos no resultado * * @returns {string|undefined} */ protected prepareStringOrDateParam( - param?: string | Date + param?: string | Date, + includeTime: boolean = false ): string | undefined { if (param === undefined) { return undefined @@ -35,6 +37,6 @@ export abstract class Entity { return param } - return convertDateToString(param) + return convertDateToString(param, includeTime) } } diff --git a/src/entities/produtos/index.ts b/src/entities/produtos/index.ts index b73b9a3..2d159d6 100644 --- a/src/entities/produtos/index.ts +++ b/src/entities/produtos/index.ts @@ -84,16 +84,20 @@ export class Produtos extends Entity { tipo: params?.tipo, idComponente: params?.idComponente, dataInclusaoInicial: this.prepareStringOrDateParam( - params?.dataInclusaoInicial + params?.dataInclusaoInicial, + true ), dataInclusaoFinal: this.prepareStringOrDateParam( - params?.dataInclusaoFinal + params?.dataInclusaoFinal, + true ), dataAlteracaoInicial: this.prepareStringOrDateParam( - params?.dataAlteracaoInicial + params?.dataAlteracaoInicial, + true ), dataAlteracaoFinal: this.prepareStringOrDateParam( - params?.dataAlteracaoFinal + params?.dataAlteracaoFinal, + true ), idCategoria: params?.idCategoria, idLoja: params?.idLoja, diff --git a/src/helpers/functions/convert-date-to-string.ts b/src/helpers/functions/convert-date-to-string.ts index fd25c8f..391bb35 100644 --- a/src/helpers/functions/convert-date-to-string.ts +++ b/src/helpers/functions/convert-date-to-string.ts @@ -1,5 +1,9 @@ /** - * Converte um objeto `Date` para o formato `YYYY-MM-DD`. + * Converte um objeto `Date` para o formato `YYYY-MM-DD` (opcionalmente `YYYY-MM-DD HH:MM:SS`). */ -export default (date: Date) => - `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}` +export default (date: Date, includeTime: boolean = false) => { + const baseTime = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}` + if (!includeTime) return baseTime + + return `${baseTime} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}` +}