update request status after invoice created
This commit is contained in:
@@ -11,6 +11,7 @@ import { User } from '../user/entities/user.entity';
|
||||
import { ProductService } from '../product/providers/product.service';
|
||||
import { InvoiceRepository } from './repositories/invoice.repository';
|
||||
import { InvoiceCreatedEvent } from './events/invoice.events';
|
||||
import { RequestStatusEnum } from '../request/enum/request';
|
||||
|
||||
const TAX_RATE = 0.1;
|
||||
|
||||
@@ -98,6 +99,17 @@ export class InvoiceService {
|
||||
invoice.total = total;
|
||||
invoice.balance = total - invoice.paidAmount;
|
||||
|
||||
if (dto.requestId) {
|
||||
const requestEntity = await em.findOne(
|
||||
Request,
|
||||
{ id: dto.requestId },
|
||||
);
|
||||
if (!requestEntity) {
|
||||
throw new NotFoundException('Request not found');
|
||||
}
|
||||
requestEntity.status = RequestStatusEnum.INVOICED;
|
||||
}
|
||||
|
||||
await em.flush();
|
||||
return invoice;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user