- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
"use strict";
|
|
exports.constructFrom = constructFrom;
|
|
|
|
/**
|
|
* @name constructFrom
|
|
* @category Generic Helpers
|
|
* @summary Constructs a date using the reference date and the value
|
|
*
|
|
* @description
|
|
* The function constructs a new date using the constructor from the reference
|
|
* date and the given value. It helps to build generic functions that accept
|
|
* date extensions.
|
|
*
|
|
* It defaults to `Date` if the passed reference date is a number or a string.
|
|
*
|
|
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
|
*
|
|
* @param date - The reference date to take constructor from
|
|
* @param value - The value to create the date
|
|
*
|
|
* @returns Date initialized using the given date and value
|
|
*
|
|
* @example
|
|
* import { constructFrom } from 'date-fns'
|
|
*
|
|
* // A function that clones a date preserving the original type
|
|
* function cloneDate<DateType extends Date(date: DateType): DateType {
|
|
* return constructFrom(
|
|
* date, // Use contrustor from the given date
|
|
* date.getTime() // Use the date value to create a new date
|
|
* )
|
|
* }
|
|
*/
|
|
function constructFrom(date, value) {
|
|
if (date instanceof Date) {
|
|
return new date.constructor(value);
|
|
} else {
|
|
return new Date(value);
|
|
}
|
|
}
|