mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ServiceError, ServiceErrors } from '@/exceptions';
|
||||
import { ERRORS } from './contants';
|
||||
|
||||
@Service()
|
||||
export class WarehouseValidator {
|
||||
@Inject()
|
||||
tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} tenantId
|
||||
* @param {number} warehouseId
|
||||
*/
|
||||
public validateWarehouseNotOnlyWarehouse = async (
|
||||
tenantId: number,
|
||||
warehouseId: number
|
||||
) => {
|
||||
const { Warehouse } = this.tenancy.models(tenantId);
|
||||
|
||||
const warehouses = await Warehouse.query().whereNot('id', warehouseId);
|
||||
|
||||
if (warehouses.length === 0) {
|
||||
throw new ServiceError(ERRORS.COULD_NOT_DELETE_ONLY_WAERHOUSE);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tenantId
|
||||
* @param code
|
||||
* @param exceptWarehouseId
|
||||
*/
|
||||
public validateWarehouseCodeUnique = async (
|
||||
tenantId: number,
|
||||
code: string,
|
||||
exceptWarehouseId?: number
|
||||
) => {
|
||||
const { Warehouse } = this.tenancy.models(tenantId);
|
||||
|
||||
const warehouse = await Warehouse.query()
|
||||
.onBuild((query) => {
|
||||
query.select(['id']);
|
||||
query.where('code', code);
|
||||
|
||||
if (exceptWarehouseId) {
|
||||
query.whereNot('id', exceptWarehouseId);
|
||||
}
|
||||
})
|
||||
.first();
|
||||
|
||||
if (warehouse) {
|
||||
throw new ServiceError(ERRORS.WAREHOUSE_CODE_NOT_UNIQUE);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user