I have a query like this :
const rows = await Leaderboard.findAll({
where: {
app_type_id: appId,
...filterWhereQuery,
emp_id: dataProgress.submited
},
include: [
...leaderboardFavouriteInclude,
{
model: UserEmployee,
as: 'user',
attributes: ['emp_id', 'emp_full_name', 'emp_email', 'is_invited', ...empInfo]
},
I want to modify the emp_email
value in UserEmployee
model. The email is would be return like abc@gmail.com
but i want to remove the domain email and the result is should be abc
for the emp_email
.
How to solve case like that ? Thanks
You need to use a getter for a emp_email
field like this:
emp_email: {
type: DataTypes.STRING,
get() {
const rawValue = this.getDataValue('emp_email');
return rawValue ? rawValue.split('@')[0] : null;
}
}