mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 07:38:10 +00:00
change price logic on the ,rule engine ui, auto generate the contrat
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { ConflictException, Inject, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { generateCode } from '../../../common/utils/generate-code.util';
|
||||
import { CreateYardDto } from '../dto/create-yard.dto';
|
||||
import { ReorderItemsDto } from '../dto/reorder-items.dto';
|
||||
import { UpdateYardDto } from '../dto/update-yard.dto';
|
||||
import { Yard } from '../entities/yard.entity';
|
||||
import { IYardsRepository, YARDS_REPOSITORY } from '../interfaces/yards.repository.interface';
|
||||
import { DisplayOrderService } from './display-order.service';
|
||||
|
||||
@Injectable()
|
||||
export class YardsService {
|
||||
constructor(
|
||||
@Inject(YARDS_REPOSITORY)
|
||||
private readonly repository: IYardsRepository,
|
||||
private readonly displayOrder: DisplayOrderService,
|
||||
) {}
|
||||
|
||||
/** List yards with pagination. */
|
||||
@@ -20,7 +23,7 @@ export class YardsService {
|
||||
pageSize?: number;
|
||||
}): Promise<{ data: Yard[]; meta: { total: number; page: number; pageSize: number; totalPages: number } }> {
|
||||
const page = filter.page ?? 1;
|
||||
const pageSize = filter.pageSize ?? 20;
|
||||
const pageSize = filter.pageSize ?? 10;
|
||||
const where: Record<string, unknown> = {};
|
||||
if (filter.isActive !== undefined) where.isActive = filter.isActive;
|
||||
if (filter.country) where.country = filter.country;
|
||||
@@ -46,12 +49,18 @@ export class YardsService {
|
||||
const code = generateCode(dto.label);
|
||||
const existing = await this.repository.findByCode(code);
|
||||
if (existing) throw new ConflictException(`Yard with label "${dto.label}" conflicts with existing code "${code}"`);
|
||||
|
||||
const displayOrder = await this.displayOrder.resolveCreateOrder(Yard, 'displayOrder', {
|
||||
explicitOrder: dto.displayOrder,
|
||||
insertAfterId: dto.insertAfterId,
|
||||
});
|
||||
|
||||
return this.repository.create({
|
||||
code,
|
||||
label: dto.label,
|
||||
country: dto.country,
|
||||
isActive: dto.isActive ?? true,
|
||||
displayOrder: dto.displayOrder ?? 1,
|
||||
displayOrder,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,4 +77,13 @@ export class YardsService {
|
||||
await this.findById(id);
|
||||
await this.repository.softDelete(id);
|
||||
}
|
||||
|
||||
async reorder(dto: ReorderItemsDto): Promise<void> {
|
||||
await this.displayOrder.reorderByIds(Yard, 'displayOrder', dto.ids);
|
||||
}
|
||||
|
||||
async moveOrder(id: string, direction: 'up' | 'down'): Promise<void> {
|
||||
await this.findById(id);
|
||||
await this.displayOrder.moveOne(Yard, 'displayOrder', id, direction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user