feat(products): add reset functionality to delete all products and related data
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
@@ -109,4 +110,10 @@ export class ProductsController {
|
||||
restore(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.productsService.restore(id);
|
||||
}
|
||||
|
||||
@Delete('reset-all')
|
||||
@HttpCode(200)
|
||||
resetAll() {
|
||||
return this.productsService.resetAll();
|
||||
}
|
||||
}
|
||||
@@ -381,4 +381,20 @@ export class ProductsService {
|
||||
async findAllTags() {
|
||||
return this.prisma.tag.findMany({ orderBy: { name: 'asc' } });
|
||||
}
|
||||
|
||||
async resetAll() {
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.receiptAlias.deleteMany(),
|
||||
this.prisma.inventoryConsumption.deleteMany(),
|
||||
this.prisma.inventoryItem.deleteMany(),
|
||||
this.prisma.pantryItem.deleteMany(),
|
||||
this.prisma.nutrition.deleteMany(),
|
||||
this.prisma.productTag.deleteMany(),
|
||||
this.prisma.tag.deleteMany(),
|
||||
this.prisma.userProduct.deleteMany(),
|
||||
this.prisma.recipeIngredient.deleteMany(),
|
||||
this.prisma.product.deleteMany(),
|
||||
]);
|
||||
return { ok: true };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user