AJ Holloway
10/14/2022, 10:54 PMconst scorers = await DBConn.recognition_logger.groupBy({
by: ['receiver_id'],
_sum: {
amount: true,
},
orderBy: {
_sum: { amount: 'desc' },
},
where: {
OR: [{ action: 'gave_points' }, { action: 'approve_claimable_award' }, { action: 'custom_award_send' }],
users_recognition_logger_receiver_idTousers: {
active: true,
},
amount: { gt: 0 },
company_id: res.locals.requestingUser.companies.id,
created: {
gte: DateTime.now().startOf('month').startOf('day').toUnixInteger(),
lte: DateTime.now().endOf('month').endOf('day').toUnixInteger(),
},
hidden_from_leaderboard: false,
valid: true,
type: {
equals: 'Regular',
},
},
});
scorers.map(async (e) => {
const user = await DBConn.users.findUnique({ where: { id: e.receiver_id } });
console.log(user);
});
receiver_id is a user’s id.
SELECT [*] FROM "public"."users" WHERE "public"."users"."id" IN ($1,$2) OFFSET $3
Params: [157359532448138,165341040401209,0]
Duration: 11ms
null
null
Interestingly, when I copy this into pgAdmin, it works just fine. Any idea why this is happening? Apologies for the long message, I removed all the fields for security and length’s sake. (Yes I know that I’m mapping and it returns a new object. But the output from the Query in my console is null,null)Nurul
10/17/2022, 10:17 AMe
in the map callback function and check if the user indeed exists in the database with the id of e.receiver_id
?AJ Holloway
10/17/2022, 4:48 PMe.receiver_id
is a number, the same type that a user.id
is.Nurul
10/19/2022, 11:28 AM