Joachim Van Herwegen 5613ff9e71 fix: Let Representations always have a body
This is relevant when the request has a content-type
but no data.
2021-10-12 13:30:06 +02:00

28 lines
1.1 KiB
TypeScript

import { getLoggerFor } from '../../../../logging/LogUtil';
import { readJsonStream } from '../../../../util/StreamUtil';
import type { RegistrationManager, RegistrationResponse } from '../util/RegistrationManager';
import type { InteractionResponseResult, InteractionHandlerInput } from './InteractionHandler';
import { InteractionHandler } from './InteractionHandler';
/**
* Supports registration based on the `RegistrationManager` behaviour.
*/
export class RegistrationHandler extends InteractionHandler {
protected readonly logger = getLoggerFor(this);
private readonly registrationManager: RegistrationManager;
public constructor(registrationManager: RegistrationManager) {
super();
this.registrationManager = registrationManager;
}
public async handle({ operation }: InteractionHandlerInput):
Promise<InteractionResponseResult<RegistrationResponse>> {
const data = await readJsonStream(operation.body.data);
const validated = this.registrationManager.validateInput(data, false);
const details = await this.registrationManager.register(validated, false);
return { type: 'response', details };
}
}