@ApiFunctionUpdate
Adds update semantics to a service method, including DTO validation, repository writes, and before/after subscriber hooks. The decorator also ensures the entity exists before mutation by reusing @ApiFunctionGet.
Signature
@ApiFunctionUpdate<E extends IApiBaseEntity>(
properties: IApiFunctionProperties<E>
)Decorated methods gain the shape update(criteria: TApiFunctionUpdateCriteria<E>, dto: TApiFunctionUpdateProperties<E>, eventManager?: EntityManager): Promise<E>.
Behavior
- Runs
onBeforeUpdatesubscribers with the incoming DTO; returning a DTO overrides the update payload. - Lazily decorates a helper
getmethod (via@ApiFunctionGet) to fetch the entity and raise 404 errors if missing. - Merges the existing entity with provided properties and saves via the repository or transaction manager.
- Executes
onAfterUpdatesubscribers; their return value can replace the final response. - Fires
onBeforeErrorUpdateandonAfterErrorUpdatesubscribers when repositories or validation fail.
Example
export class PostService {
constructor(public repository: Repository<PostEntity>) {}
@ApiFunctionUpdate<PostEntity>({ entity: PostEntity })
async updatePost(criteria: TApiFunctionUpdateCriteria<PostEntity>, dto: TApiFunctionUpdateProperties<PostEntity>) {
return {} as PostEntity;
}
}Related resources
Last updated on