API patch improvements
- add PatchObject.CheckIsValid - use transaction when creating member, as to not create a member if the patch is invalid - return edited system in `PATCH /s` endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -140,13 +141,18 @@ namespace PluralKit.API
|
||||
try
|
||||
{
|
||||
patch = JsonModelExt.ToSystemPatch(changes);
|
||||
patch.CheckIsValid();
|
||||
}
|
||||
catch (JsonModelParseError e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
catch (InvalidPatchException e)
|
||||
{
|
||||
return BadRequest($"Request field '{e.Message}' is invalid.");
|
||||
}
|
||||
|
||||
await _repo.UpdateSystem(conn, system!.Id, patch);
|
||||
system = await _repo.UpdateSystem(conn, system!.Id, patch);
|
||||
return Ok(system.ToJson(User.ContextFor(system)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user