Skip to content

Commit

Permalink
Merge pull request #1754 from bakaphp/feat-light-cache
Browse files Browse the repository at this point in the history
refact: message cache
  • Loading branch information
kaioken committed Jul 31, 2024
2 parents 59a778e + fa2dab6 commit c1ce35c
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 c1ce35c

Please sign in to comment.