mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Feature: documents trash aka soft delete (#6944)
This commit is contained in:
59
src-ui/src/app/services/trash.service.spec.ts
Normal file
59
src-ui/src/app/services/trash.service.spec.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
|
||||
import { TrashService } from './trash.service'
|
||||
import {
|
||||
HttpClientTestingModule,
|
||||
HttpTestingController,
|
||||
} from '@angular/common/http/testing'
|
||||
import { environment } from 'src/environments/environment'
|
||||
|
||||
describe('TrashService', () => {
|
||||
let service: TrashService
|
||||
let httpTestingController: HttpTestingController
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
})
|
||||
service = TestBed.inject(TrashService)
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
})
|
||||
|
||||
it('should call correct endpoint for getTrash', () => {
|
||||
service.getTrash().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}trash/?page=1`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('should call correct endpoint for emptyTrash', () => {
|
||||
service.emptyTrash().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}trash/`
|
||||
)
|
||||
expect(req.request.method).toEqual('POST')
|
||||
expect(req.request.body).toEqual({ action: 'empty' })
|
||||
|
||||
service.emptyTrash([1, 2, 3]).subscribe()
|
||||
const req2 = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}trash/`
|
||||
)
|
||||
expect(req2.request.body).toEqual({
|
||||
action: 'empty',
|
||||
documents: [1, 2, 3],
|
||||
})
|
||||
})
|
||||
|
||||
it('should call correct endpoint for restoreDocuments', () => {
|
||||
service.restoreDocuments([1, 2, 3]).subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}trash/`
|
||||
)
|
||||
expect(req.request.method).toEqual('POST')
|
||||
expect(req.request.body).toEqual({
|
||||
action: 'restore',
|
||||
documents: [1, 2, 3],
|
||||
})
|
||||
})
|
||||
})
|
37
src-ui/src/app/services/trash.service.ts
Normal file
37
src-ui/src/app/services/trash.service.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { Document } from '../data/document'
|
||||
import { Results } from '../data/results'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TrashService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
public getTrash(page: number = 1): Observable<Results<Document>> {
|
||||
const httpParams = new HttpParams().set('page', page.toString())
|
||||
return this.http.get<Results<Document>>(`${environment.apiBaseUrl}trash/`, {
|
||||
params: httpParams,
|
||||
})
|
||||
}
|
||||
|
||||
public emptyTrash(documents?: number[]): Observable<any> {
|
||||
const data = {
|
||||
action: 'empty',
|
||||
}
|
||||
if (documents?.length) {
|
||||
data['documents'] = documents
|
||||
}
|
||||
return this.http.post(`${environment.apiBaseUrl}trash/`, data)
|
||||
}
|
||||
|
||||
public restoreDocuments(documents: number[]): Observable<any> {
|
||||
return this.http.post(`${environment.apiBaseUrl}trash/`, {
|
||||
action: 'restore',
|
||||
documents,
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user