feat: PUT request geabstraheerd naar service-helper.ts
This commit is contained in:
parent
800d52257c
commit
541e8ab2d5
4 changed files with 57 additions and 17 deletions
20
backend/src/services/service-helper.ts
Normal file
20
backend/src/services/service-helper.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { EntityDTO, FromEntityType } from "@mikro-orm/core";
|
||||
import { DwengoEntityRepository } from "../data/dwengo-entity-repository";
|
||||
|
||||
/**
|
||||
* Utility function to perform an PUT on an object.
|
||||
*
|
||||
* @param object The object that needs to be changed
|
||||
* @param data The datafields and their values that will be updated
|
||||
* @param repo The repository on which this action needs to be performed
|
||||
*
|
||||
* @returns Nothing.
|
||||
*/
|
||||
export async function putObject<T extends Object, DTO>(
|
||||
object: T,
|
||||
data: Partial<EntityDTO<FromEntityType<T>>>,
|
||||
repo: DwengoEntityRepository<T>
|
||||
): Promise<void> {
|
||||
repo.assign(object, data);
|
||||
await repo.getEntityManager().flush();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue