- ✅ 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
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
var Promise = global.Promise;
|
|
|
|
/// encapsulate a method with a node-style callback in a Promise
|
|
/// @param {object} 'this' of the encapsulated function
|
|
/// @param {function} function to be encapsulated
|
|
/// @param {Array-like} args to be passed to the called function
|
|
/// @return {Promise} a Promise encapsulating the function
|
|
module.exports.promise = function (fn, context, args) {
|
|
|
|
if (!Array.isArray(args)) {
|
|
args = Array.prototype.slice.call(args);
|
|
}
|
|
|
|
if (typeof fn !== 'function') {
|
|
return Promise.reject(new Error('fn must be a function'));
|
|
}
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
args.push(function(err, data) {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(data);
|
|
}
|
|
});
|
|
|
|
fn.apply(context, args);
|
|
});
|
|
};
|
|
|
|
/// @param {err} the error to be thrown
|
|
module.exports.reject = function (err) {
|
|
return Promise.reject(err);
|
|
};
|
|
|
|
/// changes the promise implementation that bcrypt uses
|
|
/// @param {Promise} the implementation to use
|
|
module.exports.use = function(promise) {
|
|
Promise = promise;
|
|
};
|