diff --git a/packages/common/decorators/http/sse.decorator.ts b/packages/common/decorators/http/sse.decorator.ts index 6f944614316..5dae6aef7a8 100644 --- a/packages/common/decorators/http/sse.decorator.ts +++ b/packages/common/decorators/http/sse.decorator.ts @@ -6,7 +6,12 @@ import { RequestMethod } from '../../enums/request-method.enum'; * * @publicApi */ -export function Sse(path?: string): MethodDecorator { +export function Sse( + path?: string, + options: { [METHOD_METADATA]?: RequestMethod } = { + [METHOD_METADATA]: RequestMethod.GET, + }, +): MethodDecorator { return ( target: object, key: string | symbol, @@ -17,7 +22,7 @@ export function Sse(path?: string): MethodDecorator { Reflect.defineMetadata(PATH_METADATA, path, descriptor.value); Reflect.defineMetadata( METHOD_METADATA, - RequestMethod.GET, + options[METHOD_METADATA], descriptor.value, ); Reflect.defineMetadata(SSE_METADATA, true, descriptor.value); diff --git a/packages/common/test/decorators/sse.decorator.spec.ts b/packages/common/test/decorators/sse.decorator.spec.ts index 85d3a5738e1..0d40e225dba 100644 --- a/packages/common/test/decorators/sse.decorator.spec.ts +++ b/packages/common/test/decorators/sse.decorator.spec.ts @@ -8,6 +8,9 @@ describe('@Sse', () => { class Test { @Sse(prefix) public static test() {} + + @Sse(prefix, { method: RequestMethod.POST }) + public static testUsingOptions() {} } it('should enhance method with expected http status code', () => { @@ -20,4 +23,14 @@ describe('@Sse', () => { const metadata = Reflect.getMetadata(SSE_METADATA, Test.test); expect(metadata).to.be.eql(true); }); + it('should enhance method with expected http status code and method from options', () => { + const path = Reflect.getMetadata(PATH_METADATA, Test.testUsingOptions); + expect(path).to.be.eql('/prefix'); + + const method = Reflect.getMetadata(METHOD_METADATA, Test.testUsingOptions); + expect(method).to.be.eql(RequestMethod.POST); + + const metadata = Reflect.getMetadata(SSE_METADATA, Test.testUsingOptions); + expect(metadata).to.be.eql(true); + }); });