mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 05:25:41 +00:00
Merge pull request #1128 from Tria-plc/freight_feature/usermanagement
Freight feature/usermanagement
This commit is contained in:
@@ -59,26 +59,57 @@ export class CargoTypesRepository implements ICargoTypesRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(data: Partial<CargoType>): Promise<CargoType> {
|
async create(data: Partial<CargoType>): Promise<CargoType> {
|
||||||
const entity = this.repo.create(data);
|
const { wagonTypes, ...columns } = data;
|
||||||
return this.repo.save(entity);
|
const entity = this.repo.create(columns);
|
||||||
|
const saved = await this.repo.save(entity);
|
||||||
|
if (wagonTypes?.length) {
|
||||||
|
await this.syncWagonTypes(saved.id, wagonTypes.map((wt) => wt.id), []);
|
||||||
|
}
|
||||||
|
return (await this.findById(saved.id)) ?? saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: Partial<CargoType>): Promise<CargoType | null> {
|
async update(id: string, data: Partial<CargoType>): Promise<CargoType | null> {
|
||||||
// Relation lists can't ride a column UPDATE — sync them via entity save.
|
|
||||||
const { wagonTypes, ...columns } = data;
|
const { wagonTypes, ...columns } = data;
|
||||||
if (Object.keys(columns).length) {
|
if (Object.keys(columns).length) {
|
||||||
await this.repo.update(id, columns as never);
|
await this.repo.update(id, columns as never);
|
||||||
}
|
}
|
||||||
if (wagonTypes) {
|
if (wagonTypes) {
|
||||||
const entity = await this.repo.findOne({ where: { id } });
|
const current = await this.repo.findOne({
|
||||||
if (entity) {
|
where: { id },
|
||||||
entity.wagonTypes = wagonTypes;
|
relations: { wagonTypes: true },
|
||||||
await this.repo.save(entity);
|
});
|
||||||
|
if (current) {
|
||||||
|
await this.syncWagonTypes(
|
||||||
|
id,
|
||||||
|
wagonTypes.map((wt) => wt.id),
|
||||||
|
(current.wagonTypes ?? []).map((wt) => wt.id),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.findById(id);
|
return this.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diffs the wagon-type links through the relation query builder rather than
|
||||||
|
* an entity save: junction-row inserts from save() broadcast afterInsert with
|
||||||
|
* no entity attached, which the @tria-plc/auditlog subscriber (deployed
|
||||||
|
* builds) dereferences and crashes the request on.
|
||||||
|
*/
|
||||||
|
private async syncWagonTypes(
|
||||||
|
id: string,
|
||||||
|
nextIds: string[],
|
||||||
|
currentIds: string[],
|
||||||
|
): Promise<void> {
|
||||||
|
const toAdd = nextIds.filter((x) => !currentIds.includes(x));
|
||||||
|
const toRemove = currentIds.filter((x) => !nextIds.includes(x));
|
||||||
|
if (!toAdd.length && !toRemove.length) return;
|
||||||
|
await this.repo
|
||||||
|
.createQueryBuilder()
|
||||||
|
.relation(CargoType, 'wagonTypes')
|
||||||
|
.of(id)
|
||||||
|
.addAndRemove(toAdd, toRemove);
|
||||||
|
}
|
||||||
|
|
||||||
async softDelete(id: string): Promise<void> {
|
async softDelete(id: string): Promise<void> {
|
||||||
await this.repo.softDelete(id);
|
await this.repo.softDelete(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,15 @@ const FleetRecordActions = ({
|
|||||||
{removeLabel}
|
{removeLabel}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
) : null}
|
) : null}
|
||||||
|
{onPurge ? (
|
||||||
|
<MenuItem
|
||||||
|
color="red"
|
||||||
|
onClick={() => onPurge(record)}
|
||||||
|
leftSection={<ShieldAlert size={14} strokeWidth={2} />}
|
||||||
|
>
|
||||||
|
Delete permanently
|
||||||
|
</MenuItem>
|
||||||
|
) : null}
|
||||||
</Menu.Dropdown>
|
</Menu.Dropdown>
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -191,13 +191,12 @@ export class CbeBillService {
|
|||||||
return mapPaymentFailure(dto, "Payment is being processed.");
|
return mapPaymentFailure(dto, "Payment is being processed.");
|
||||||
}
|
}
|
||||||
if (prior.failureClass === "BUSINESS") {
|
if (prior.failureClass === "BUSINESS") {
|
||||||
// Final — retrying cannot change the answer. Replay what we told CBE last time.
|
// Final — retrying cannot change the answer. Same End_To_End_Txn_Id was already
|
||||||
return (
|
// resolved (possibly against a different Bill_Id/amount); say so instead of
|
||||||
(prior.responsePayload as unknown as CbePaymentResponseDto) ??
|
// echoing the original reason, which no longer describes this request.
|
||||||
mapPaymentFailure(
|
return mapPaymentFailure(
|
||||||
dto,
|
dto,
|
||||||
prior.responseDescription ?? "Payment already failed.",
|
`End_To_End_Txn_Id ${dto.End_To_End_Txn_Id} was already processed and failed: ${prior.responseDescription ?? "unknown reason"}.`,
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// FAILED + TRANSIENT: allowed retry — fall through and re-run the settlement.
|
// FAILED + TRANSIENT: allowed retry — fall through and re-run the settlement.
|
||||||
|
|||||||
Reference in New Issue
Block a user