1
0
Fork 0
mirror of synced 2024-06-15 09:14:50 +12:00

fix(teams): incorrect membership count in teams

This commit is contained in:
Christy Jacob 2021-05-29 02:25:22 +05:30
parent 3b98feef11
commit b0e74b6d7b
3 changed files with 9 additions and 12 deletions

View file

@ -790,7 +790,7 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId')
if ($membership->getAttribute('confirm')) { // Count only confirmed members
$team = $projectDB->updateDocument(\array_merge($team->getArrayCopy(), [
'sum' => $team->getAttribute('sum', 0) - 1,
'sum' => \max($team->getAttribute('sum', 0) - 1, 0),
]));
}

View file

@ -110,7 +110,7 @@
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Delete User"
data-service="users.deleteUser"
data-service="users.delete"
data-event="submit"
data-param-user-id="{{router.params.id}}"
data-success="alert,trigger,redirect"

View file

@ -128,24 +128,21 @@ class DeletesV1
}
}
var_dump("Hi there! Gonna delete memberships");
// Delete Memberships and update the team membership counts
// Delete Memberships and decrement team membership counts
$this->deleteByGroup([
'$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS,
'userId='.$document->getId(),
], $this->getProjectDB($projectId), function(Document $document) use ($projectId,){
var_dump("In call back ");
print_r($document);
], $this->getProjectDB($projectId), function(Document $document) use ($projectId) {
if ($document->getAttribute('confirm')) { // Count only confirmed members
$teamId = $document->getAttribute('teamId');
$team = $this->getProjectDB($projectId)->getDocument($teamId);
print_r($team);
// $team = $this->getProjectDB($projectId)->updateDocument(\array_merge($team->getArrayCopy(), [
// 'sum' => $team->getAttribute('sum', 0) - 1,
// ]));
if(!$team->isEmpty()) {
$team = $this->getProjectDB($projectId)->updateDocument(\array_merge($team->getArrayCopy(), [
'sum' => \max($team->getAttribute('sum', 0) - 1, 0),
]));
}
}
});
}