Adding a conditional statement in an afterQuery() Hook

Hi,

I have a field in my dataset that I would like to append brackets too but only if the field is populated e.g. if the field text is ‘blue’, I would like it to be displayed as ‘(blue)’.

I’m using the following code and the hook is working fine but how do I only append the brackets to a field that is populated?

export function Coaches_afterQuery(item, context) {

 if (item.username !== null) {
        item.username = "( " + item.username + " )";
    }
}

The code above will always return (undefined) if the field is blank.
I have also tried the following but with the same result?

if (item.username !== '')

I am also receiving the following in the console log…

Hook afterQuery for collection Coaches result ignored! Expected hook result to resolve to an object with an ‘_id’ property, but got [Undefined]
But the code is actually working ok for a field that is populated so I’m a bit confused by this?!

Thanks,
Rachel