diff --git a/CHANGELOG.md b/CHANGELOG.md index fa9efefae..f05e8b4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added + +- Introduced a new button to delete all activities from the portfolio activities page + ## 1.260.0 - 2023-04-23 ### Added diff --git a/apps/api/src/app/order/order.controller.ts b/apps/api/src/app/order/order.controller.ts index 90f8c10b1..0f1e382d6 100644 --- a/apps/api/src/app/order/order.controller.ts +++ b/apps/api/src/app/order/order.controller.ts @@ -41,6 +41,23 @@ export class OrderController { @Inject(REQUEST) private readonly request: RequestWithUser ) {} + @Delete() + @UseGuards(AuthGuard('jwt')) + public async deleteOrders(): Promise { + if ( + !hasPermission(this.request.user.permissions, permissions.deleteOrder) + ) { + throw new HttpException( + getReasonPhrase(StatusCodes.FORBIDDEN), + StatusCodes.FORBIDDEN + ); + } + + return this.orderService.deleteOrders({ + userId: this.request.user.id + }); + } + @Delete(':id') @UseGuards(AuthGuard('jwt')) public async deleteOrder(@Param('id') id: string): Promise { diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 2403bf495..9bc2c6a8e 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -181,6 +181,14 @@ export class OrderService { return order; } + public async deleteOrders(where: Prisma.OrderWhereInput): Promise { + const { count } = await this.prismaService.order.deleteMany({ + where + }); + + return count; + } + public async getOrders({ filters, includeDrafts = false, diff --git a/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts b/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts index 2e89b60c5..3e4d5ae66 100644 --- a/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts @@ -138,6 +138,23 @@ export class ActivitiesPageComponent implements OnDestroy, OnInit { }); } + public onDeleteAllActivities() { + const confirmation = confirm( + $localize`Do you really want to delete all your activities?` + ); + + if (confirmation) { + this.dataService + .deleteAllOrders() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe({ + next: () => { + this.fetchActivities(); + } + }); + } + } + public onExport(activityIds?: string[]) { this.dataService .fetchExport(activityIds) diff --git a/apps/client/src/app/pages/portfolio/activities/activities-page.html b/apps/client/src/app/pages/portfolio/activities/activities-page.html index b0705ccd6..dddc41b0b 100644 --- a/apps/client/src/app/pages/portfolio/activities/activities-page.html +++ b/apps/client/src/app/pages/portfolio/activities/activities-page.html @@ -13,6 +13,7 @@ (activityDeleted)="onDeleteActivity($event)" (activityToClone)="onCloneActivity($event)" (activityToUpdate)="onUpdateActivity($event)" + (deleteAllActivities)="onDeleteAllActivities()" (export)="onExport($event)" (exportDrafts)="onExportDrafts($event)" (import)="onImport()" diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 845f1e0f2..bff672717 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -146,6 +146,10 @@ export class DataService { return this.http.delete(`/api/v1/account/${aId}`); } + public deleteAllOrders() { + return this.http.delete(`/api/v1/order/`); + } + public deleteOrder(aId: string) { return this.http.delete(`/api/v1/order/${aId}`); } diff --git a/libs/ui/src/lib/activities-table/activities-table.component.html b/libs/ui/src/lib/activities-table/activities-table.component.html index 8f7b682a3..4ac853436 100644 --- a/libs/ui/src/lib/activities-table/activities-table.component.html +++ b/libs/ui/src/lib/activities-table/activities-table.component.html @@ -53,6 +53,14 @@ Export Drafts as ICS + diff --git a/libs/ui/src/lib/activities-table/activities-table.component.ts b/libs/ui/src/lib/activities-table/activities-table.component.ts index 3d8273ca5..1c3fb0367 100644 --- a/libs/ui/src/lib/activities-table/activities-table.component.ts +++ b/libs/ui/src/lib/activities-table/activities-table.component.ts @@ -49,6 +49,7 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy, OnInit { @Output() activityDeleted = new EventEmitter(); @Output() activityToClone = new EventEmitter(); @Output() activityToUpdate = new EventEmitter(); + @Output() deleteAllActivities = new EventEmitter(); @Output() export = new EventEmitter(); @Output() exportDrafts = new EventEmitter(); @Output() import = new EventEmitter(); @@ -231,6 +232,10 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy, OnInit { ); } + public onDeleteAllActivities() { + this.deleteAllActivities.emit(); + } + public onImport() { this.import.emit(); }