Skip to content

Commit

Permalink
feat: separate update events into update, soft-remove, and recover (#…
Browse files Browse the repository at this point in the history
…8403)

Closes: #8398

BREAKING CHANGE: update listeners and subscriber no longer triggered by soft-remove and recover
  • Loading branch information
spotykatch committed Feb 15, 2022
1 parent f7c1f7d commit 93383bd
Show file tree
Hide file tree
Showing 29 changed files with 1,063 additions and 107 deletions.
155 changes: 118 additions & 37 deletions docs/decorator-reference.md
@@ -1,42 +1,47 @@
# Decorator reference

* [Entity decorators](#entity-decorators)
* [`@Entity`](#entity)
* [`@ViewEntity`](#viewentity)
* [Column decorators](#column-decorators)
* [`@Column`](#column)
* [`@PrimaryColumn`](#primarycolumn)
* [`@PrimaryGeneratedColumn`](#primarygeneratedcolumn)
* [`@ObjectIdColumn`](#objectidcolumn)
* [`@CreateDateColumn`](#createdatecolumn)
* [`@UpdateDateColumn`](#updatedatecolumn)
* [`@DeleteDateColumn`](#deletedatecolumn)
* [`@VersionColumn`](#versioncolumn)
* [`@Generated`](#generated)
* [Relation decorators](#relation-decorators)
* [`@OneToOne`](#onetoone)
* [`@ManyToOne`](#manytoone)
* [`@OneToMany`](#onetomany)
* [`@ManyToMany`](#manytomany)
* [`@JoinColumn`](#joincolumn)
* [`@JoinTable`](#jointable)
* [`@RelationId`](#relationid)
* [Subscriber and listener decorators](#subscriber-and-listener-decorators)
* [`@AfterLoad`](#afterload)
* [`@BeforeInsert`](#beforeinsert)
* [`@AfterInsert`](#afterinsert)
* [`@BeforeUpdate`](#beforeupdate)
* [`@AfterUpdate`](#afterupdate)
* [`@BeforeRemove`](#beforeremove)
* [`@AfterRemove`](#afterremove)
* [`@EventSubscriber`](#eventsubscriber)
* [Other decorators](#other-decorators)
* [`@Index`](#index)
* [`@Unique`](#unique)
* [`@Check`](#check)
* [`@Exclusion`](#exclusion)
* [`@Transaction`, `@TransactionManager` and `@TransactionRepository`](#transaction-transactionmanager-and-transactionrepository)
* [`@EntityRepository`](#entityrepository)
- [Decorators reference](#decorators-reference)
- [Entity decorators](#entity-decorators)
- [`@Entity`](#entity)
- [`@ViewEntity`](#viewentity)
- [Column decorators](#column-decorators)
- [`@Column`](#column)
- [`@PrimaryColumn`](#primarycolumn)
- [`@PrimaryGeneratedColumn`](#primarygeneratedcolumn)
- [`@ObjectIdColumn`](#objectidcolumn)
- [`@CreateDateColumn`](#createdatecolumn)
- [`@UpdateDateColumn`](#updatedatecolumn)
- [`@DeleteDateColumn`](#deletedatecolumn)
- [`@VersionColumn`](#versioncolumn)
- [`@Generated`](#generated)
- [Relation decorators](#relation-decorators)
- [`@OneToOne`](#onetoone)
- [`@ManyToOne`](#manytoone)
- [`@OneToMany`](#onetomany)
- [`@ManyToMany`](#manytomany)
- [`@JoinColumn`](#joincolumn)
- [`@JoinTable`](#jointable)
- [`@RelationId`](#relationid)
- [Subscriber and listener decorators](#subscriber-and-listener-decorators)
- [`@AfterLoad`](#afterload)
- [`@BeforeInsert`](#beforeinsert)
- [`@AfterInsert`](#afterinsert)
- [`@BeforeUpdate`](#beforeupdate)
- [`@AfterUpdate`](#afterupdate)
- [`@BeforeRemove`](#beforeremove)
- [`@AfterRemove`](#afterremove)
- [`@BeforeSoftRemove`](#beforesoftremove)
- [`@AfterSoftRemove`](#aftersoftremove)
- [`@BeforeRecover`](#beforerecover)
- [`@AfterRecover`](#afterrecover)
- [`@EventSubscriber`](#eventsubscriber)
- [Other decorators](#other-decorators)
- [`@Index`](#index)
- [`@Unique`](#unique)
- [`@Check`](#check)
- [`@Exclusion`](#exclusion)
- [`@Transaction`, `@TransactionManager` and `@TransactionRepository`](#transaction-transactionmanager-and-transactionrepository)
- [`@EntityRepository`](#entityrepository)

## Entity decorators

Expand Down Expand Up @@ -700,6 +705,82 @@ export class Post {
Learn more about [listeners](listeners-and-subscribers.md).
#### `@BeforeSoftRemove`
You can define a method with any name in the entity and mark it with `@BeforeSoftRemove`
and TypeORM will call it before a entity is soft removed using repository/manager `softRemove`.
Example:
```typescript
@Entity()
export class Post {

@BeforeSoftRemove()
updateStatus() {
this.status = "soft-removed";
}
}
```
Learn more about [listeners](listeners-and-subscribers.md).
#### `@AfterSoftRemove`
You can define a method with any name in the entity and mark it with `@AfterSoftRemove`
and TypeORM will call it after the entity is soft removed using repository/manager `softRemove`.
Example:
```typescript
@Entity()
export class Post {

@AfterSoftRemove()
updateStatus() {
this.status = "soft-removed";
}
}
```
Learn more about [listeners](listeners-and-subscribers.md).
#### `@BeforeRecover`
You can define a method with any name in the entity and mark it with `@BeforeRecover`
and TypeORM will call it before a entity is recovered using repository/manager `recover`.
Example:
```typescript
@Entity()
export class Post {

@BeforeRecover()
updateStatus() {
this.status = "recovered";
}
}
```
Learn more about [listeners](listeners-and-subscribers.md).
#### `@AfterRecover`
You can define a method with any name in the entity and mark it with `@AfterRecover`
and TypeORM will call it after the entity is recovered using repository/manager `recover`.
Example:
```typescript
@Entity()
export class Post {

@AfterRecover()
updateStatus() {
this.status = "recovered";
}
}
```
Learn more about [listeners](listeners-and-subscribers.md).
#### `@EventSubscriber`
Marks a class as an event subscriber which can listen to specific entity events or any entity's events.
Expand Down

0 comments on commit 93383bd

Please sign in to comment.