Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

1.7 KB
Raw Blame
import TvApiBase from './base'
import type { AppResponse } from './base.types'
import type { InvoiceArgCreate, InvoiceArgList, InvoiceArgPdf, InvoiceArgStatus, InvoiceArgUpdate, InvoiceItem } from './invoices.types'

export default class TvInvoicesApi extends TvApiBase {
    protected moduleUrl = '/module/invoices'

    public async fetch(params: InvoiceArgList) {
        return this.request(this.$axios.get<AppResponse<InvoiceItem[]>>(`${this.moduleUrl}`, { params }))
    }

    public async fetchById(id: number) {
        return this.request(this.$axios.get<AppResponse<InvoiceItem>>(`${this.moduleUrl}/${id}`))
    }

    public async create(data: InvoiceArgCreate) {
        return this.request(this.$axios.post<AppResponse<InvoiceItem>>(`${this.moduleUrl}`, data))
    }

    public async update({ id, data }: InvoiceArgUpdate) {
        return this.request(this.$axios.patch<AppResponse<InvoiceItem>>(`${this.moduleUrl}/${id}`, data))
    }

    public async setStatus({ id, status }: InvoiceArgStatus) {
        return this.request(this.$axios.patch<AppResponse<InvoiceItem>>(`${this.moduleUrl}/${id}/status`, { status }))
    }

    public async reissue(id: number) {
        return this.request(this.$axios.post<AppResponse<InvoiceItem>>(`${this.moduleUrl}/${id}/reissue`, {}))
    }

    public async fetchPdf({ id, lang }: InvoiceArgPdf): Promise<Blob> {
        const response = await this.$axios.get<ArrayBuffer>(`${this.moduleUrl}/${id}/pdf`, { params: { lang }, responseType: 'arraybuffer' })
        return new Blob([response.data], { type: 'application/pdf' })
    }

    public async delete(id: number) {
        return this.request(this.$axios.delete<AppResponse<boolean>>(`${this.moduleUrl}/${id}`))
    }
}