Fix Komodo tag IDs in Mongo Extended JSON responses
This commit is contained in:
@@ -525,13 +525,16 @@ export type KomodoTagResult =
|
||||
| { ok: true; id: string }
|
||||
| { ok: false; message: string };
|
||||
|
||||
// Komodo serializes Mongo ObjectIds as `_id` in the raw mongo docs and as
|
||||
// `id` in the API DTOs (rust serde default). Accept either everywhere.
|
||||
// Accept API string IDs and raw Mongo Extended JSON: { _id: { $oid: "..." } }.
|
||||
function extractTagId(t: unknown): string | null {
|
||||
if (!t || typeof t !== 'object') return null;
|
||||
const o = t as { id?: unknown; _id?: unknown };
|
||||
if (typeof o.id === 'string' && o.id.length > 0) return o.id;
|
||||
if (typeof o._id === 'string' && o._id.length > 0) return o._id;
|
||||
if (o._id && typeof o._id === 'object') {
|
||||
const oid = (o._id as { $oid?: unknown }).$oid;
|
||||
if (typeof oid === 'string' && oid.length > 0) return oid;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user