forked from swapnil.bendal/TypeScript-Backend-Template
[update] - latest code
This commit is contained in:
17
src/utils/handler/pick.handler.ts
Normal file
17
src/utils/handler/pick.handler.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Create an object composed of the picked object properties.
|
||||
* @function pick
|
||||
*
|
||||
* @param object - The source object to pick properties from.
|
||||
* @param keys - The array of property names to pick from the source object.
|
||||
* @returns New object with only the picked properties.
|
||||
*/
|
||||
export const pick = <T extends object, K extends keyof T>(object: T, keys: K[]): Pick<T, K> => {
|
||||
return keys.reduce((result, key) => {
|
||||
// Check if the object has the specified property
|
||||
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
||||
result[key] = object[key]; // Assign the property to the result object
|
||||
}
|
||||
return result;
|
||||
}, {} as Pick<T, K>); // Type the accumulator as Pick<T, K>
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class ApiError extends Error {
|
||||
constructor(statusCode, message = 'Something went wrong', errors = [], isOperational = true, stack = '') {
|
||||
super(message);
|
||||
this.statusCode = statusCode;
|
||||
this.data = null;
|
||||
this.message = message;
|
||||
this.success = false;
|
||||
this.errors = errors;
|
||||
this.isOperational = isOperational;
|
||||
if (stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
else {
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = ApiError;
|
||||
//# sourceMappingURL=ApiError.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"ApiError.js","sourceRoot":"","sources":["ApiError.ts"],"names":[],"mappings":";;AAAA,MAAM,QAAkB,SAAQ,KAAK;IASjC,YACI,UAAkB,EAClB,UAAkB,sBAAsB,EACxC,SAAqB,EAAE,EACvB,gBAAyB,IAAI,EAC7B,QAAgB,EAAE;QAElB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QAEnC,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;SACtB;aAAM;YACH,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;SACnD;IACL,CAAC;CACJ;AACD,kBAAe,QAAQ,CAAC"}
|
||||
@@ -1,12 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class ApiResponse {
|
||||
constructor(statusCode, data, message = 'Success') {
|
||||
this.statusCode = statusCode;
|
||||
this.data = data;
|
||||
this.message = message;
|
||||
this.success = statusCode < 400;
|
||||
}
|
||||
}
|
||||
exports.default = ApiResponse;
|
||||
//# sourceMappingURL=ApiResponse.js.map
|
||||
@@ -1 +0,0 @@
|
||||
{"version":3,"file":"ApiResponse.js","sourceRoot":"","sources":["ApiResponse.ts"],"names":[],"mappings":";;AAAA,MAAM,WAAW;IAMb,YAAY,UAAkB,EAAE,IAAc,EAAE,UAAkB,SAAS;QACvE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,UAAU,GAAG,GAAG,CAAC;IACpC,CAAC;CACJ;AAED,kBAAe,WAAW,CAAC"}
|
||||
Reference in New Issue
Block a user