@exweiv/weiv-data
Version:
Custom API Library for Wix sites to connect MongoDB. Designed to easily switch from wix-data APIs.
23 lines (21 loc) • 659 B
text/typescript
import { ObjectId } from "mongodb";
import { convertToStringId } from "../Helpers/internal_id_converter";
import { kaptanLogar } from "../Errors/error_manager";
export function convertIdToString(id: string | ObjectId, encoding?: "base64" | "hex",): string {
try {
return convertToStringId(id, encoding);
} catch (err) {
kaptanLogar("00010", `${err}`);
}
}
export function convertIdToObjectId(id: string | ObjectId): ObjectId {
try {
if (id instanceof ObjectId) {
return id;
} else {
return new ObjectId(id);
}
} catch (err) {
kaptanLogar("00010", `${err}`);
}
}