feat: Modify the abstract repository upsert to handle subresources as per convention (#6813)

* feat: Modify the abstract repository upsert method to handle subresources correctly

* fix: Preserve the upsertWithResponse order in the response, and return all the data

* fix: Create integration tests folder for mikro orm utils that run against the DB

* fix: Remove many-to-one creation and additional changes based on PR review
This commit is contained in:
Stevche Radevski
2024-03-28 15:28:57 +01:00
committed by GitHub
parent 21156f945d
commit a6562d2a41
9 changed files with 1163 additions and 3 deletions
+12
View File
@@ -70,5 +70,17 @@ export type FindOptions<T = any> = {
options?: OptionsQuery<T, any>
}
/**
* @interface
*
* An object used to specify the configuration of how the upsert should be performed.
*/
export type UpsertWithReplaceConfig<T> = {
/**
* The relationships that will be updated/created/deleted as part of the upsert
*/
relations?: (keyof T)[]
}
export * from "./repository-service"
export * from "./entity"
@@ -5,6 +5,7 @@ import {
FilterQuery as InternalFilterQuery,
FilterQuery,
FindOptions,
UpsertWithReplaceConfig,
} from "./index"
/**
@@ -70,6 +71,12 @@ export interface RepositoryService<T = any> extends BaseRepositoryService<T> {
): Promise<[T[], Record<string, unknown[]>]>
upsert(data: any[], context?: Context): Promise<T[]>
upsertWithReplace(
data: any[],
config?: UpsertWithReplaceConfig<T>,
context?: Context
): Promise<T[]>
}
export interface TreeRepositoryService<T = any>
@@ -4,6 +4,7 @@ import {
BaseFilterable,
FilterQuery as InternalFilterQuery,
FilterQuery,
UpsertWithReplaceConfig,
} from "../dal"
export interface InternalModuleService<
@@ -78,4 +79,10 @@ export interface InternalModuleService<
upsert(data: any[], sharedContext?: Context): Promise<TEntity[]>
upsert(data: any, sharedContext?: Context): Promise<TEntity>
upsertWithReplace(
data: any[],
config?: UpsertWithReplaceConfig<TEntity>,
sharedContext?: Context
): Promise<TEntity[]>
}