pushy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-28 11:29:07 +08:00
parent 463a8d3978
commit 89acdfc239
67 changed files with 2736 additions and 306 deletions
+15 -1
View File
@@ -286,14 +286,28 @@ exports.getUsersNotInGroup = async (req, res) => {
try {
const { gid: group_id } = req.params;
// Exclude users already in THIS group
const members = await mdl_UserGroupMembers.findAll({ where: { group_id }, attributes: ['user_id'] });
const memberIds = members.map((m) => m.user_id);
const users = await mdl_Users.findAll({
where: { user_id: { [Op.notIn]: memberIds.length ? memberIds : [0] } },
where: { user_id: { [Op.notIn]: memberIds.length ? memberIds : [0] } },
attributes: [
'user_id',
[Sequelize.literal(`("User"."personal_info"->'name'->>'full_name')`), 'full_name'],
// All active groups this user belongs to (excluding NOGRP), comma-separated
[
Sequelize.literal(`(
SELECT STRING_AGG(ug.name || ' (' || ug.group_code || ')', ', ' ORDER BY ug.name)
FROM user_group_members ugm
JOIN user_groups ug ON ug.group_id = ugm.group_id
WHERE ugm.user_id = "User".user_id
AND ugm."deletedAt" IS NULL
AND ug."deletedAt" IS NULL
AND ug.group_code != 'NOGRP'
)`),
'current_group',
],
],
});