I have an entity (image) that has a computed property (image path) like that:
@Entity()
export class Image extends BaseEntity {
@PrimaryGeneratedColumn()
@IsInt()
id: number
@Column({ type: 'varchar', length: 255, unique: true })
@IsString()
@IsNotEmpty()
uid: string
protected mainPath: string
@AfterLoad()
@AfterInsert()
@AfterUpdate()
generateMainPath(): void {
this.mainPath = Math.floor(this.id / 10000) + '/' + Math.floor(this.id / 100) + '/' + this.uid
}
}
I use mainPath for storing images in the back-end file system, and also send it to the front-end to build img src path. mainPath successfully generated and send to the client.
The issue is that the front-end uses swagger (nswag openapi2tsclient) generated typescript file built on openApi schema, generated by Nest.JS. There's no mainPath property for IImage interface in the generated file. Is it possible to declare it somehow so it will be defined on the client and filled with provided value from ajax response?
P.S.1. Tried to decorate mainPath with @ApiProperty({ type: String }) - it did not help.
P.S.2. Tried to use @Column({ type: virtual }) but the back-end then gives a warning that this type is not supported by MySQL.
P.S.3. It seems mainPath should be declared as some usual not-computed property at the front-end since it will be prefilled with the data from the back-end (it will not be calculated on the front-end).
P.S.4. The possible way seems to be to use bare models for database and ExtendedImage class that has mainPath property calculated in the constructor if not provided. Is it the best-practice?