Test for Update support

This commit is contained in:
Jesse Wierzbinski 2023-09-13 20:12:54 -10:00
parent d92764d81a
commit aad3ee78d1
No known key found for this signature in database
GPG key ID: F9A1E418934E40B0
2 changed files with 79 additions and 5 deletions

View file

@ -78,17 +78,26 @@ export default async (
// Replace the object in database with the new provided object
// TODO: Add authentication
const object = await RawObject.findOneBy({
data: {
id: (body.object as RawObject).id,
},
});
const object = await RawObject.createQueryBuilder("object")
.where("object.data->>'id' = :id", {
id: (body.object as APObject).id,
})
.getOne();
if (!object) return errorResponse("Object not found", 404);
object.data = body.object as APObject;
// Store the Update event in database
const activity = new RawActivity();
activity.data = {
...body,
object: undefined,
};
activity.objects = [object];
await object.save();
await activity.save();
break;
}
case "Delete" as APDelete: {