MicroOrm adapter for JsonApi Plugin for NestJs
npm install @klerick/json-api-nestjs-typeormTypeOrm adapter for json-api-nestjs
``bash `
$ npm install @klerick/json-api-nestjs-typeorm
The following interface is using for the configuration:
`typescript`
export type TypeOrmParam = {
useSoftDelete?: boolean // Use soft delete
runInTransaction?:
isolationLevel: IsolationLevel,
fn: Func
) => ReturnType
};
To enable automatic resource linkage (data field in relationships) for to-one relations, use the @RelationId decorator from TypeORM.
Example:
`typescript
import {
Entity,
PrimaryGeneratedColumn,
ManyToOne,
JoinColumn,
RelationId,
} from 'typeorm';
@Entity('comments')
export class Comments {
@PrimaryGeneratedColumn()
public id!: number;
@ManyToOne(() => Users)
@JoinColumn({ name: 'user_id' })
public user!: Users;
// This field will be used for resource linkage
@RelationId((comment: Comments) => comment.user)
public userId!: number;
}
`
The @RelationId decorator creates a virtual field that contains the FK value. The library automatically detects these fields and uses them to populate relationships.{relation}.data` in API responses.