mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
refactor: import resource module to nestjs
This commit is contained in:
@@ -7,7 +7,9 @@ import { GetCreditNotePdf } from './queries/GetCreditNotePdf.serivce';
|
||||
import {
|
||||
ICreditNoteEditDTO,
|
||||
ICreditNoteNewDTO,
|
||||
ICreditNotesQueryDTO,
|
||||
} from './types/CreditNotes.types';
|
||||
import { GetCreditNotesService } from './queries/GetCreditNotes.service';
|
||||
|
||||
@Injectable()
|
||||
export class CreditNoteApplication {
|
||||
@@ -17,6 +19,7 @@ export class CreditNoteApplication {
|
||||
private openCreditNoteService: OpenCreditNoteService,
|
||||
private deleteCreditNoteService: DeleteCreditNoteService,
|
||||
private getCreditNotePdfService: GetCreditNotePdf,
|
||||
private getCreditNotesService: GetCreditNotesService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -67,4 +70,13 @@ export class CreditNoteApplication {
|
||||
getCreditNotePdf(creditNoteId: number) {
|
||||
return this.getCreditNotePdfService.getCreditNotePdf(creditNoteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the credit notes list.
|
||||
* @param {ICreditNotesQueryDTO} creditNotesQuery
|
||||
* @returns {Promise<GetCreditNotesResponse>}
|
||||
*/
|
||||
getCreditNotes(creditNotesQuery: ICreditNotesQueryDTO) {
|
||||
return this.getCreditNotesService.getCreditNotesList(creditNotesQuery);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import { Body, Controller, Delete, Param, Post, Put } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { CreditNoteApplication } from './CreditNoteApplication.service';
|
||||
import {
|
||||
ICreditNoteEditDTO,
|
||||
ICreditNoteNewDTO,
|
||||
ICreditNotesQueryDTO,
|
||||
} from './types/CreditNotes.types';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
|
||||
@@ -19,6 +29,11 @@ export class CreditNotesController {
|
||||
return this.creditNoteApplication.createCreditNote(creditNoteDTO);
|
||||
}
|
||||
|
||||
@Get()
|
||||
getCreditNotes(@Query() creditNotesQuery: ICreditNotesQueryDTO) {
|
||||
return this.creditNoteApplication.getCreditNotes(creditNotesQuery);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
editCreditNote(
|
||||
@Param('id') creditNoteId: number,
|
||||
|
||||
@@ -1,68 +1,67 @@
|
||||
// import { Service, Inject } from 'typedi';
|
||||
// import * as R from 'ramda';
|
||||
// import { ICreditNotesQueryDTO } from '@/interfaces';
|
||||
// import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
||||
// import BaseCreditNotes from './commands/CommandCreditNoteDTOTransform.service';
|
||||
// import { CreditNoteTransformer } from './queries/CreditNoteTransformer';
|
||||
// import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import * as R from 'ramda';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service';
|
||||
import { ICreditNotesQueryDTO } from '../types/CreditNotes.types';
|
||||
import { CreditNote } from '../models/CreditNote';
|
||||
import { CreditNoteTransformer } from './CreditNoteTransformer';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
// @Service()
|
||||
// export default class ListCreditNotes extends BaseCreditNotes {
|
||||
// @Inject()
|
||||
// private dynamicListService: DynamicListingService;
|
||||
@Injectable()
|
||||
export class GetCreditNotesService {
|
||||
constructor(
|
||||
private readonly dynamicListService: DynamicListService,
|
||||
private readonly transformer: TransformerInjectable,
|
||||
|
||||
// @Inject()
|
||||
// private transformer: TransformerInjectable;
|
||||
@Inject(CreditNote.name)
|
||||
private readonly creditNoteModel: typeof CreditNote,
|
||||
) {}
|
||||
|
||||
// /**
|
||||
// * Parses the sale invoice list filter DTO.
|
||||
// * @param filterDTO
|
||||
// * @returns
|
||||
// */
|
||||
// private parseListFilterDTO = (filterDTO) => {
|
||||
// return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
// };
|
||||
/**
|
||||
* Parses the sale invoice list filter DTO.
|
||||
* @param filterDTO
|
||||
* @returns
|
||||
*/
|
||||
private parseListFilterDTO = (filterDTO) => {
|
||||
return R.compose(this.dynamicListService.parseStringifiedFilter)(filterDTO);
|
||||
};
|
||||
|
||||
// /**
|
||||
// * Retrieves the paginated and filterable credit notes list.
|
||||
// * @param {number} tenantId -
|
||||
// * @param {ICreditNotesQueryDTO} creditNotesQuery -
|
||||
// */
|
||||
// public getCreditNotesList = async (
|
||||
// tenantId: number,
|
||||
// creditNotesQuery: ICreditNotesQueryDTO
|
||||
// ) => {
|
||||
// const { CreditNote } = this.tenancy.models(tenantId);
|
||||
/**
|
||||
* Retrieves the paginated and filterable credit notes list.
|
||||
* @param {number} tenantId -
|
||||
* @param {ICreditNotesQueryDTO} creditNotesQuery -
|
||||
*/
|
||||
public async getCreditNotesList(
|
||||
creditNotesQuery: ICreditNotesQueryDTO,
|
||||
): Promise<GetCreditNotesResponse> {
|
||||
// Parses stringified filter roles.
|
||||
const filter = this.parseListFilterDTO(creditNotesQuery);
|
||||
|
||||
// // Parses stringified filter roles.
|
||||
// const filter = this.parseListFilterDTO(creditNotesQuery);
|
||||
// Dynamic list service.
|
||||
const dynamicFilter = await this.dynamicListService.dynamicList(
|
||||
CreditNote,
|
||||
filter,
|
||||
);
|
||||
const { results, pagination } = await this.creditNoteModel
|
||||
.query()
|
||||
.onBuild((builder) => {
|
||||
builder.withGraphFetched('entries.item');
|
||||
builder.withGraphFetched('customer');
|
||||
dynamicFilter.buildQuery()(builder);
|
||||
creditNotesQuery?.filterQuery && creditNotesQuery?.filterQuery(builder);
|
||||
})
|
||||
.pagination(filter.page - 1, filter.pageSize);
|
||||
|
||||
// // Dynamic list service.
|
||||
// const dynamicFilter = await this.dynamicListService.dynamicList(
|
||||
// tenantId,
|
||||
// CreditNote,
|
||||
// filter
|
||||
// );
|
||||
// const { results, pagination } = await CreditNote.query()
|
||||
// .onBuild((builder) => {
|
||||
// builder.withGraphFetched('entries.item');
|
||||
// builder.withGraphFetched('customer');
|
||||
// dynamicFilter.buildQuery()(builder);
|
||||
// creditNotesQuery?.filterQuery && creditNotesQuery?.filterQuery(builder);
|
||||
// })
|
||||
// .pagination(filter.page - 1, filter.pageSize);
|
||||
// Transforomes the credit notes to POJO.
|
||||
const creditNotes = await this.transformer.transform(
|
||||
results,
|
||||
new CreditNoteTransformer(),
|
||||
);
|
||||
|
||||
// // Transforomes the credit notes to POJO.
|
||||
// const creditNotes = await this.transformer.transform(
|
||||
// tenantId,
|
||||
// results,
|
||||
// new CreditNoteTransformer()
|
||||
// );
|
||||
|
||||
// return {
|
||||
// creditNotes,
|
||||
// pagination,
|
||||
// filterMeta: dynamicFilter.getResponseMeta(),
|
||||
// };
|
||||
// };
|
||||
// }
|
||||
return {
|
||||
creditNotes,
|
||||
pagination,
|
||||
filterMeta: dynamicFilter.getResponseMeta(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { CreditNoteInventoryTransactions } from '../commands/CreditNotesInventor
|
||||
@Injectable()
|
||||
export class CreditNoteInventoryTransactionsSubscriber {
|
||||
constructor(
|
||||
private readonly inventoryTransactions: CreditNoteInventoryTransactions;
|
||||
private readonly inventoryTransactions: CreditNoteInventoryTransactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -30,9 +30,9 @@ export class CreditNoteInventoryTransactionsSubscriber {
|
||||
|
||||
await this.inventoryTransactions.createInventoryTransactions(
|
||||
creditNote,
|
||||
trx
|
||||
trx,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrites inventory transactions once credit note edited.
|
||||
@@ -48,11 +48,11 @@ export class CreditNoteInventoryTransactionsSubscriber {
|
||||
if (!creditNote.isOpen) return;
|
||||
|
||||
await this.inventoryTransactions.editInventoryTransactions(
|
||||
creditNoteId,
|
||||
creditNote.id,
|
||||
creditNote,
|
||||
trx
|
||||
trx,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts inventory transactions once credit note deleted.
|
||||
@@ -67,8 +67,8 @@ export class CreditNoteInventoryTransactionsSubscriber {
|
||||
if (!oldCreditNote.isOpen) return;
|
||||
|
||||
await this.inventoryTransactions.deleteInventoryTransactions(
|
||||
creditNoteId,
|
||||
trx
|
||||
oldCreditNote.id,
|
||||
trx,
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user