homemanager-be/src/shared/decorators/current-storage.decorator.ts

14 lines
447 B
TypeScript

import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { Response } from 'express';
import { Storage } from 'src/objects/storage/entities/storage.entity';
/**
* Get the storage from the response.
*/
export const CurrentStorage = createParamDecorator(
(data: unknown, ctx: ExecutionContext) => {
const response = ctx.switchToHttp().getResponse() as Response;
return response.locals.storage as Storage;
},
);