rule engine and configration and fix booking for custoemr

This commit is contained in:
marshal
2026-06-01 23:15:11 +03:00
parent b9ca0b8a82
commit 452ebdbc0a
52 changed files with 3355 additions and 3358 deletions

View File

@@ -1,4 +1,5 @@
import { ConflictException, Inject, Injectable, NotFoundException } from '@nestjs/common';
import { generateCode } from '../../../common/utils/generate-code.util';
import { CreatePriorityRuleDto } from '../dto/create-priority-rule.dto';
import { UpdatePriorityRuleDto } from '../dto/update-priority-rule.dto';
import { PriorityRule } from '../entities/priority-rule.entity';
@@ -27,7 +28,7 @@ export class PriorityRulesService {
const [data, total] = await this.repository.findAndCount({
where,
order: { code: 'ASC' },
order: { label: 'ASC' },
skip: (page - 1) * pageSize,
take: pageSize,
});
@@ -43,12 +44,13 @@ export class PriorityRulesService {
/** Create a new priority rule. */
async create(dto: CreatePriorityRuleDto): Promise<PriorityRule> {
const existing = await this.repository.findAll({ where: { code: dto.code } });
const code = generateCode(dto.label);
const existing = await this.repository.findAll({ where: { code } });
if (existing.length > 0) {
throw new ConflictException(`Priority rule with code "${dto.code}" already exists`);
throw new ConflictException(`Priority rule with label "${dto.label}" conflicts with existing code "${code}"`);
}
return this.repository.create({
code: dto.code,
code,
label: dto.label,
score: dto.score,
conditionCurrency: dto.conditionCurrency ?? null,
@@ -59,7 +61,8 @@ export class PriorityRulesService {
/** Update an existing priority rule. */
async update(id: string, dto: UpdatePriorityRuleDto): Promise<PriorityRule> {
await this.findById(id);
const updated = await this.repository.update(id, dto);
const { ...patch } = dto;
const updated = await this.repository.update(id, patch);
if (!updated) throw new NotFoundException(`Priority rule ${id} not found`);
return updated;
}