2023-12-14 17:34:15 +01:00
import { IOid } from "@/src/types/commonTypes" ;
2023-06-14 02:26:19 +02:00
import { IInventoryDatabase , IInventoryResponse } from "@/src/types/inventoryTypes/inventoryTypes" ;
2023-12-14 17:34:15 +01:00
import { Types } from "mongoose" ;
2023-06-04 03:06:22 +02:00
2023-12-14 17:34:15 +01:00
//TODO: this needs to be addressed: a schema's toJSON is responsible for changing Oid and Date to their corresponding Response versions __id to "ItemId":{"$oid":"6450f720bc562ebf030222d4"}, and a Date to "date":{"$date":{"$numberLong":"unix timestamp"})
export const toInventoryResponse = ( inventoryDatabase : IInventoryDatabase ) : IInventoryResponse = > {
2023-06-04 03:06:22 +02:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2023-09-11 13:20:07 +02:00
const { accountOwnerId , . . . inventoryResponse } = inventoryDatabase ;
return inventoryResponse as unknown as IInventoryResponse ;
2023-06-04 03:06:22 +02:00
} ;
2023-12-14 17:34:15 +01:00
export const toOid = ( objectId : Types.ObjectId ) = > {
return { $oid : objectId.toString ( ) } satisfies IOid ;
} ;
2024-02-12 14:31:28 +01:00
export const toMongoDate = ( date : Date ) = > {
return { $date : { $numberLong : date.getTime ( ) . toString ( ) } } ;
} ;