Skip to content

Commit

Permalink
feat: permitir filtro de produtos com horas
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBellas committed Sep 9, 2024
1 parent 0f3f8d4 commit 51581cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/entities/@shared/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +37,6 @@ export abstract class Entity {
return param
}

return convertDateToString(param)
return convertDateToString(param, includeTime)
}
}
12 changes: 8 additions & 4 deletions src/entities/produtos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/helpers/functions/convert-date-to-string.ts
Original file line number Diff line number Diff line change
@@ -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()}`
}

0 comments on commit 51581cf

Please sign in to comment.