extract shared mongo mapper utils
This commit is contained in:
1 parent
bd13e9d9c8
commit
825a81d326
16 files changed
+89
-268
No files matched your search
@@ -0,0 +1,15 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
export const toStringId = (value?: mongoose.Types.ObjectId | string | null): string => {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
return value instanceof mongoose.Types.ObjectId ? value.toString() : String(value);
|
||||
};
|
||||
|
||||
export const toDateString = (value?: Date | string | null): string => {
|
||||
if (!value) {
|
||||
return new Date(0).toISOString();
|
||||
}
|
||||
return value instanceof Date ? value.toISOString() : new Date(value).toISOString();
|
||||
};
|
||||
Reference in new issue
Block a user