mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
33 lines
900 B
TypeScript
33 lines
900 B
TypeScript
import { Service, Inject } from 'typedi';
|
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import { ServiceError } from '@/exceptions';
|
|
import { ERRORS } from './constants';
|
|
|
|
@Service()
|
|
export class CRUDWarehouseTransfer {
|
|
@Inject()
|
|
tenancy: HasTenancyService;
|
|
|
|
|
|
throwIfTransferNotFound = (warehouseTransfer) => {
|
|
if (!warehouseTransfer) {
|
|
throw new ServiceError(ERRORS.WAREHOUSE_TRANSFER_NOT_FOUND);
|
|
}
|
|
}
|
|
|
|
public getWarehouseTransferOrThrowNotFound = async (
|
|
tenantId: number,
|
|
branchId: number
|
|
) => {
|
|
const { WarehouseTransfer } = this.tenancy.models(tenantId);
|
|
|
|
const foundTransfer = await WarehouseTransfer.query().findById(branchId);
|
|
|
|
if (!foundTransfer) {
|
|
throw new ServiceError(ERRORS.WAREHOUSE_TRANSFER_NOT_FOUND);
|
|
}
|
|
return foundTransfer;
|
|
};
|
|
}
|