fix: prohibit adding barname for expired contracts
This commit is contained in:
@@ -532,6 +532,7 @@ export const enum IndustryMessage {
|
|||||||
export const enum CompanyMessage {
|
export const enum CompanyMessage {
|
||||||
RENT_CONTRACT_IMAGE_IS_REQUIRED="تصویر اجاره نامه الزامی است",
|
RENT_CONTRACT_IMAGE_IS_REQUIRED="تصویر اجاره نامه الزامی است",
|
||||||
RENT_END_IS_REQUIRED="تاریخ پایان قرارداد الزامی است",
|
RENT_END_IS_REQUIRED="تاریخ پایان قرارداد الزامی است",
|
||||||
|
RENT_CONTRACT_IS_EXPIRED="تاریخ قرارداد پایان یافته است",
|
||||||
ADDRESS_MUST_BE_STRING = "آدرس شرکت باید یک رشته باشد",
|
ADDRESS_MUST_BE_STRING = "آدرس شرکت باید یک رشته باشد",
|
||||||
ADDRESS_REQUIRED = "آدرس شرکت مورد نیاز است",
|
ADDRESS_REQUIRED = "آدرس شرکت مورد نیاز است",
|
||||||
CHIEF_EXECUTIVE_MUST_BE_STRING = "نام مدیرعامل باید یک رشته باشد",
|
CHIEF_EXECUTIVE_MUST_BE_STRING = "نام مدیرعامل باید یک رشته باشد",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { BarnameStatus } from "./enums/bill-type.enum";
|
|||||||
import { UpdateBarnameAsWatcherDto } from "./dto/update-barname-watcher.dto";
|
import { UpdateBarnameAsWatcherDto } from "./dto/update-barname-watcher.dto";
|
||||||
import { RoleEnum } from "../users/enums/role.enum";
|
import { RoleEnum } from "../users/enums/role.enum";
|
||||||
import { User } from "../users/entities/user.entity";
|
import { User } from "../users/entities/user.entity";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -30,6 +31,15 @@ export class BarnameService {
|
|||||||
const company = await this.em.findOne(Company, { business, user: { id: userId }, deletedAt: null });
|
const company = await this.em.findOne(Company, { business, user: { id: userId }, deletedAt: null });
|
||||||
if (!company) throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND);
|
if (!company) throw new BadRequestException(CompanyMessage.COMPANY_NOT_FOUND);
|
||||||
|
|
||||||
|
if (company.isRented) { // validate for rented company
|
||||||
|
if (!company.rentEndAt) {
|
||||||
|
throw new BadRequestException(CompanyMessage.RENT_END_IS_REQUIRED)
|
||||||
|
}
|
||||||
|
if (dayjs().isAfter(company.rentEndAt)) {
|
||||||
|
throw new BadRequestException(CompanyMessage.RENT_CONTRACT_IS_EXPIRED)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const bill = this.em.create(Barname,
|
const bill = this.em.create(Barname,
|
||||||
{
|
{
|
||||||
carType,
|
carType,
|
||||||
|
|||||||
Reference in New Issue
Block a user