mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add OperationHandler for PATCH
This commit is contained in:
26
src/ldp/operations/SimplePatchOperationHandler.ts
Normal file
26
src/ldp/operations/SimplePatchOperationHandler.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Operation } from './Operation';
|
||||
import { OperationHandler } from './OperationHandler';
|
||||
import { Patch } from '../http/Patch';
|
||||
import { ResourceStore } from '../../storage/ResourceStore';
|
||||
import { ResponseDescription } from './ResponseDescription';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
|
||||
export class SimplePatchOperationHandler extends OperationHandler {
|
||||
private readonly store: ResourceStore;
|
||||
|
||||
public constructor(store: ResourceStore) {
|
||||
super();
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public async canHandle(input: Operation): Promise<void> {
|
||||
if (input.method !== 'PATCH') {
|
||||
throw new UnsupportedHttpError('This handler only supports PATCH operations.');
|
||||
}
|
||||
}
|
||||
|
||||
public async handle(input: Operation): Promise<ResponseDescription> {
|
||||
await this.store.modifyResource(input.target, input.body as Patch);
|
||||
return { identifier: input.target };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user