Description
I was trying to...
I need to transform some file URL's in the response, the file paths need to contain the client id,
The problem:
I have a shared class 'AssetReponseImagesDTO' this is used in lots of other classes, i need to transform the value of filename
from a local path to append the CDN URL and client id and return a proper URL
I can get the CDN URL from the configService as it's just a string, to get the value of ClientId
i have a custom decorator for nest.js - tried to use this decorator to access the same Id within the response but it doesn't work.
I also tried to create a new ClientId
property on my top level response DTO however the lower level Type such as AssetResponseImagesDTO
won't have access to the parent's properties
Is there a way to pass in additional information to class transformer which can then be referenced during the transform process?
export class AssetResponseImagesDTO {
@Expose({ name: 'url' })
@Transform(({ value }) =>
value ? `${configService.getCDNUrl()}${ClientId}/asset/${value}` : null,
)
filename: string;
@Expose()
caption: string;
@Expose({ name: 'link' })
url: string;
}