refactor: migrate credit note and vendor credit services to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-29 18:37:33 +02:00
parent 9f9b75cd31
commit caf235e2b5
107 changed files with 7396 additions and 109 deletions

View File

@@ -0,0 +1,39 @@
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { ERRORS } from '../constants';
import { CreditNoteTransformer } from './CreditNoteTransformer';
import { Inject, Injectable } from '@nestjs/common';
import { CreditNote } from '../models/CreditNote';
import { ServiceError } from '@/modules/Items/ServiceError';
@Injectable()
export class GetCreditNote {
constructor(
private readonly transformer: TransformerInjectable,
@Inject(CreditNote.name)
private readonly creditNoteModel: typeof CreditNote,
) {}
/**
* Retrieve the credit note graph.
* @param {number} tenantId
* @param {number} creditNoteId
* @returns
*/
public async getCreditNote(creditNoteId: number) {
// Retrieve the vendor credit model graph.
const creditNote = await this.creditNoteModel
.query()
.findById(creditNoteId)
.withGraphFetched('entries.item')
.withGraphFetched('customer')
.withGraphFetched('branch')
.withGraphFetched('attachments');
if (!creditNote) {
throw new ServiceError(ERRORS.CREDIT_NOTE_NOT_FOUND);
}
// Transforms the credit note model to POJO.
return this.transformer.transform(creditNote, new CreditNoteTransformer());
}
}