mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
|
import { GetSaleInvoiceMailStateTransformer } from './GetSaleInvoiceMailState.transformer';
|
|
import { SendSaleInvoiceMailCommon } from '../commands/SendInvoiceInvoiceMailCommon.service';
|
|
import { SaleInvoice } from '../models/SaleInvoice';
|
|
import { SaleInvoiceMailState } from '../SaleInvoice.types';
|
|
|
|
@Injectable()
|
|
export class GetSaleInvoiceMailState {
|
|
constructor(
|
|
private transformer: TransformerInjectable,
|
|
private invoiceMail: SendSaleInvoiceMailCommon,
|
|
|
|
@Inject(SaleInvoice.name)
|
|
private saleInvoiceModel: typeof SaleInvoice,
|
|
) {}
|
|
|
|
/**
|
|
* Retrieves the invoice mail state of the given sale invoice.
|
|
* Invoice mail state includes the mail options, branding attributes and the invoice details.
|
|
* @param {number} saleInvoiceId - Sale invoice id.
|
|
* @returns {Promise<SaleInvoiceMailState>}
|
|
*/
|
|
public async getInvoiceMailState(
|
|
saleInvoiceId: number,
|
|
): Promise<SaleInvoiceMailState> {
|
|
const saleInvoice = await this.saleInvoiceModel
|
|
.query()
|
|
.findById(saleInvoiceId)
|
|
.withGraphFetched('customer')
|
|
.withGraphFetched('entries.item')
|
|
.withGraphFetched('pdfTemplate')
|
|
.throwIfNotFound();
|
|
|
|
const mailOptions =
|
|
await this.invoiceMail.getInvoiceMailOptions(saleInvoiceId);
|
|
|
|
// Transforms the sale invoice mail state.
|
|
const transformed = await this.transformer.transform(
|
|
saleInvoice,
|
|
new GetSaleInvoiceMailStateTransformer(),
|
|
{
|
|
mailOptions,
|
|
},
|
|
);
|
|
return transformed;
|
|
}
|
|
}
|