1
0
Fork 0
mirror of synced 2024-06-01 18:39:57 +12:00

fix(memberships): logic for decremmenting membership count

This commit is contained in:
Christy Jacob 2021-05-29 01:51:56 +05:30
parent 4b006a1be0
commit 5a469ab362
2 changed files with 25 additions and 4 deletions

View file

@ -310,6 +310,8 @@ App::post('/v1/teams/:teamId/memberships')
],
]);
var_dump($invitee);
if (empty($invitee)) { // Create new user if no user with same email found
$limit = $project->getAttribute('usersAuthLimit', 0);
@ -419,6 +421,8 @@ App::post('/v1/teams/:teamId/memberships')
$membership = $projectDB->createDocument($membership->getArrayCopy());
}
var_dump($membership);
if (false === $membership) {
throw new Exception('Failed saving membership to DB', 500);
}
@ -764,6 +768,8 @@ App::delete('/v1/teams/:teamId/memberships/:membershipId')
$membership = $projectDB->getDocument($membershipId);
var_dump($membership);
if (empty($membership->getId()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) {
throw new Exception('Invite not found', 404);
}

View file

@ -5,6 +5,7 @@ use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
use Appwrite\Database\Adapter\Redis as RedisAdapter;
use Appwrite\Database\Document;
use Appwrite\Database\Validator\Authorization;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use Utopia\Storage\Device\Local;
use Utopia\Abuse\Abuse;
use Utopia\Abuse\Adapters\TimeLimit;
@ -31,8 +32,8 @@ class DeletesV1
}
public function perform()
{
$projectId = $this->args['projectId'];
{
$projectId = isset($this->args['projectId']) ? $this->args['projectId'] : '';
$type = $this->args['type'];
switch (strval($type)) {
@ -127,11 +128,25 @@ class DeletesV1
}
}
// Delete Memberships
var_dump("Hi there! Gonna delete memberships");
// Delete Memberships and update the team membership counts
$this->deleteByGroup([
'$collection='.Database::SYSTEM_COLLECTION_MEMBERSHIPS,
'userId='.$document->getId(),
], $this->getProjectDB($projectId));
], $this->getProjectDB($projectId), function(Document $document) use ($projectId,){
var_dump("In call back ");
print_r($document);
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,
// ]));
}
});
}
protected function deleteExecutionLogs($timestamp)