Skip to content

Commit

Permalink
refact: message cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jul 31, 2024
1 parent daa8a1c commit 07a850f
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,47 @@ public function attachFile(mixed $rootValue, array $request): string
*/
public function deAttachFile(mixed $rootValue, array $request): bool
{
$app = app(Apps::class);
$user = auth()->user();

$fileEntity = FilesystemEntities::where('uuid', $request['uuid'])
->fromCompany(auth()->user()->getCurrentCompany())
->when(! $user->isAdmin(), function ($query) use ($user) {
$query->fromCompany($user->getCurrentCompany());
})
->notDeleted()
->firstOrFail();

if ($fileEntity->filesystem->apps_id != $app->getId()) {
return false;
}

return $fileEntity->softDelete();
}

public function deAttachFiles(mixed $rootValue, array $request): bool
{
$company = auth()->user()->getCurrentCompany();
$app = app(Apps::class);
$user = auth()->user();
$i = 0;

$fileEntities = FilesystemEntities::whereIn('uuid', $request['uuids'])
->fromCompany($company)
->when(! $user->isAdmin(), function ($query) use ($user) {
$query->fromCompany($user->getCurrentCompany());
})
->notDeleted()
->get();

foreach ($fileEntities as $fileEntity) {
$fileEntity->softDelete();
if ($fileEntity->filesystem->apps_id != $app->getId()) {
continue;
}

if($fileEntity->softDelete()) {
$i++;
}
}

return true;
return $i == count($request['uuids']);
}

/**
Expand Down

0 comments on commit 07a850f

Please sign in to comment.