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) {
|
2024-10-10 13:57:32 -07:00
|
|
|
// 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) {
|
2023-09-24 19:24:28 -07:00
|
|
|
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
|
|
|
}
|
2022-11-08 03:39:54 -08:00
|
|
|
}
|