fixed deletion
This commit is contained in:
parent
b3f064d48d
commit
c855e1b434
|
|
@ -369,20 +369,14 @@ const updateChitGroup = async (req, res) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Delete chit group (only if forming and no members)
|
// Delete chit group (only if forming and no active members)
|
||||||
const deleteChitGroup = async (req, res) => {
|
const deleteChitGroup = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { groupId } = req.params;
|
const { groupId } = req.params;
|
||||||
const managerId = req.user.id;
|
const managerId = req.user.id;
|
||||||
|
|
||||||
const chitGroup = await ChitGroup.findOne({
|
const chitGroup = await ChitGroup.findOne({
|
||||||
where: { id: groupId, manager_id: managerId },
|
where: { id: groupId, manager_id: managerId }
|
||||||
include: [
|
|
||||||
{
|
|
||||||
model: GroupMember,
|
|
||||||
as: 'members'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!chitGroup) {
|
if (!chitGroup) {
|
||||||
|
|
@ -399,10 +393,18 @@ const deleteChitGroup = async (req, res) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chitGroup.members.length > 0) {
|
// Count only ACTIVE members (not removed or inactive)
|
||||||
|
const activeMemberCount = await GroupMember.count({
|
||||||
|
where: {
|
||||||
|
group_id: groupId,
|
||||||
|
status: 'active'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (activeMemberCount > 0) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Cannot delete chit group with existing members'
|
message: `Cannot delete chit group with ${activeMemberCount} active member(s). Please remove all active members first.`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue