correct cascade delete options
This commit is contained in:
parent
e33dfdb845
commit
b1b714f44e
19 changed files with 207 additions and 52 deletions
|
|
@ -35,7 +35,7 @@ export abstract class AbstractRepository<T extends AbstractEntity> {
|
|||
await this.repo.delete(id as any);
|
||||
}
|
||||
|
||||
async save(entity: T): Promise<T> {
|
||||
async update(entity: T): Promise<T> {
|
||||
return this.repo.save(entity);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { AbstractRepository } from "./AbstractRepository.js";
|
||||
import { RecipeEntity } from "../entities/RecipeEntity.js";
|
||||
import { AppDataSource } from "../data-source.js";
|
||||
|
||||
export class RecipeRepository extends AbstractRepository<RecipeEntity> {
|
||||
constructor() {
|
||||
|
|
@ -20,6 +21,20 @@ export class RecipeRepository extends AbstractRepository<RecipeEntity> {
|
|||
'instructionSteps'
|
||||
]
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async updateRecipe(entity: RecipeEntity): Promise<RecipeEntity> {
|
||||
return AppDataSource.transaction(async (em) => {
|
||||
// load existing data
|
||||
const existing = await this.repo.findOneOrFail({
|
||||
where: { id: entity.id },
|
||||
relations: ["instructionSteps", "ingredientGroups", "ingredientGroups.ingredients"],
|
||||
});
|
||||
|
||||
// merge new entity and existing entity
|
||||
this.repo.merge(existing, entity);
|
||||
return this.repo.save(existing);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue