1.0.8 • Published 6 months ago

nest-typeorm-history v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

Features

  • Provide a way to store entities history
  • Provide easy to use options by default

Installation

$ npm i --save nest-typeorm-history

Usage

In our root module import TypeOrmHistoryModule and add middleware for all paths:

@Module({
  imports: [
    //...our other imports
    TypeOrmHistoryModule,
  ],
  ...
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(RequestContextMiddleware).forRouter({ path: '*', method: RequestMethod.ALL });
  }
}

Now let's define some example entity:

@Entity()
export class User {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  email: string;

  @Column()
  name: string;
}

After that we can create our history entity

@Entity()
@HistoryFor(User)
export class UserHistory extends HistoryEntity {}

By defualt no fields are tracked, so now we need to go to our user entity and modify it accordingly:

@Entity()
export class User {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column()
  @TrackFieldHistory()
  email: string;

  @Column()
  @TrackFieldHistory()
  name: string;
}

Now when using method save on repository it will trigger storying field entries updates, eg: history-record

1.0.8

6 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago