call an api function with any passed as body, need to convert to type but with conditions
the type using is
export type aircraft = {
_id?: ObjectId,
groupid: ObjectId,
reg: string,
type?: string,
desc?: string,
arc?: Date,
}
is there a better way of doing this????
export function addAircraft(newAircraft: any) {
const insertAircraft: aircraft = {
reg: newAircraft.reg,
groupid: new ObjectId(newAircraft.groupid),
type: newAircraft.type,
desc: newAircraft.desc,
arc: new Date(newAircraft.arc)
}
}
I do not want any fields that are missing from newAircraft to be in insertAircraft
I have looked at object.entries but a little lost as i am looking at the input object not the target object
tried the above result _id is generated so that is fine
example:
newAircraft = {
reg: G-ABCD,
groupid: '',
desc: 'Test Description',
}
RESULT
insertAircraft = {
reg: G-ABCD,
groupid: '',
type: null,
desc: 'Test Description',
arc : null
}
so in above field arc and type is null, i would don't want it there at all.
i.e.
insertAircraft = {
reg: G-ABCD,
groupid: '',
desc: 'Test Description'
}
also if there is a date type, needs to convert to date as per the function