paperless-ngx/src-ui/src/app/services/rest/mail-account.service.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-11-08 03:39:54 -08:00
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { tap } from 'rxjs/operators'
2023-12-19 22:36:35 -08:00
import { MailAccount } from 'src/app/data/mail-account'
2022-11-08 03:39:54 -08:00
import { AbstractPaperlessService } from './abstract-paperless-service'
@Injectable({
providedIn: 'root',
})
2023-12-19 22:36:35 -08:00
export class MailAccountService extends AbstractPaperlessService<MailAccount> {
2022-11-08 03:39:54 -08:00
loading: boolean
constructor(http: HttpClient) {
super(http, 'mail_accounts')
}
private reload() {
this.loading = true
this.listAll().subscribe((r) => {
this.mailAccounts = r.results
this.loading = false
})
}
2023-12-19 22:36:35 -08:00
private mailAccounts: MailAccount[] = []
2022-11-08 03:39:54 -08:00
get allAccounts() {
return this.mailAccounts
}
2023-12-19 22:36:35 -08:00
create(o: MailAccount) {
2022-11-08 03:39:54 -08:00
return super.create(o).pipe(tap(() => this.reload()))
}
2023-12-19 22:36:35 -08:00
update(o: MailAccount) {
// Remove expiration from the object before updating
delete o.expiration
2022-11-08 03:39:54 -08:00
return super.update(o).pipe(tap(() => this.reload()))
}
2023-12-19 22:36:35 -08:00
delete(o: MailAccount) {
2022-11-08 03:39:54 -08:00
return super.delete(o).pipe(tap(() => this.reload()))
}
2023-03-24 01:17:20 -07:00
2023-12-19 22:36:35 -08:00
test(o: MailAccount) {
const account = Object.assign({}, o)
delete account['set_permissions']
return this.http.post(this.getResourceUrl() + 'test/', account)
2023-03-24 01:17:20 -07:00
}
processAccount(account: MailAccount) {
return this.http.post(this.getResourceUrl(account.id, 'process'), {})
}
2022-11-08 03:39:54 -08:00
}