add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -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);
}
};
}