18 lines
520 B
TypeScript
18 lines
520 B
TypeScript
/**
|
|
* Take the plain javascript object from a mongo document.
|
|
* I wrote this because I could not for the life of me get class-transformer to
|
|
* play along with mongo documents.
|
|
* @param mongoObj Mongo database response
|
|
* @returns Plain javascript object
|
|
*/
|
|
export default function takeMongoObject<T>(mongoObj: T): T {
|
|
const dirty = (mongoObj as Record<string, unknown>)._doc as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
dirty.id = dirty._id.toString();
|
|
delete dirty._id;
|
|
delete dirty.__v;
|
|
return dirty as T;
|
|
}
|