Skip to content

Commit

Permalink
Update AbstractRepository.php (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming authored May 10, 2024
1 parent 336e8b0 commit aa7276a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Discord/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ public function save(Part $part, ?string $reason = null): ExtendedPromiseInterfa
$headers['X-Audit-Log-Reason'] = $reason;
}

return $this->http->{$method}($endpoint, $attributes, $headers)->then(function ($response) use ($part) {
$part->created = true;
$part->fill((array) $response);

return $this->cache->set($part->{$this->discrim}, $part)->then(fn ($success) => $part);
return $this->http->{$method}($endpoint, $attributes, $headers)->then(function ($response) use ($method, $part) {
switch ($method) {
case 'patch': // Update old part
$part->created = true;
$part->fill((array) $response);
return $this->cache->set($part->{$this->discrim}, $part)->then(fn ($success) => $part);
default: // Create new part
$newPart = $this->factory->create($this->class, (array) $response, true);
return $this->cache->set($newPart->{$this->discrim}, $this->factory->create($this->class, (array) $response, true))->then(fn ($success) => $newPart);
}
});
}

Expand Down

0 comments on commit aa7276a

Please sign in to comment.