feat: PUT request geabstraheerd naar service-helper.ts

This commit is contained in:
Adriaan Jacquet 2025-04-06 22:19:15 +02:00
parent 800d52257c
commit 541e8ab2d5
4 changed files with 57 additions and 17 deletions

View 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();
}