Merge branch 'freight/hot_fix' of github.com:Tria-plc/edr-platform into freight/hot_fix

This commit is contained in:
yaschalew
2026-06-30 07:05:53 +03:00
3 changed files with 76 additions and 64 deletions

View File

@@ -32,71 +32,83 @@ export class CreateInvoices1821000000002 implements MigrationInterface {
`); `);
} }
await queryRunner.query(` const invoicesExists = await queryRunner.query(
CREATE TABLE freight.invoices ( `SELECT 1 FROM information_schema.tables WHERE table_schema = 'freight' AND table_name = 'invoices';`,
id uuid NOT NULL DEFAULT uuid_generate_v4(), );
invoice_number varchar(64) NOT NULL,
company_id uuid NOT NULL, if (!invoicesExists.length) {
company_profile_id uuid NOT NULL, await queryRunner.query(`
total_amount numeric(14, 2) NOT NULL, CREATE TABLE freight.invoices (
currency varchar(8) NOT NULL DEFAULT 'ETB', id uuid NOT NULL DEFAULT uuid_generate_v4(),
status freight.invoices_status_enum NOT NULL DEFAULT 'DRAFT', invoice_number varchar(64) NOT NULL,
source varchar(255) NOT NULL, company_id uuid NOT NULL,
source_id varchar(255) NOT NULL, company_profile_id uuid NOT NULL,
type varchar(255) NOT NULL, total_amount numeric(14, 2) NOT NULL,
issued_at timestamptz, currency varchar(8) NOT NULL DEFAULT 'ETB',
payment_id uuid, status freight.invoices_status_enum NOT NULL DEFAULT 'DRAFT',
due_at timestamptz NOT NULL, source varchar(255) NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(), source_id varchar(255) NOT NULL,
updated_at timestamptz NOT NULL DEFAULT now(), type varchar(255) NOT NULL,
deleted_at timestamptz, issued_at timestamptz,
CONSTRAINT pk_invoices PRIMARY KEY (id), payment_id uuid,
CONSTRAINT uq_invoices_invoice_number UNIQUE (invoice_number), due_at timestamptz NOT NULL,
CONSTRAINT fk_invoices_company FOREIGN KEY (company_id) created_at timestamptz NOT NULL DEFAULT now(),
REFERENCES freight.companies (id) ON DELETE RESTRICT, updated_at timestamptz NOT NULL DEFAULT now(),
CONSTRAINT fk_invoices_company_profile FOREIGN KEY (company_profile_id) deleted_at timestamptz,
REFERENCES freight.company_profiles (id) ON DELETE RESTRICT, CONSTRAINT pk_invoices PRIMARY KEY (id),
CONSTRAINT fk_invoices_payment FOREIGN KEY (payment_id) CONSTRAINT uq_invoices_invoice_number UNIQUE (invoice_number),
REFERENCES freight.payments (id) ON DELETE SET NULL CONSTRAINT fk_invoices_company FOREIGN KEY (company_id)
REFERENCES freight.companies (id) ON DELETE RESTRICT,
CONSTRAINT fk_invoices_company_profile FOREIGN KEY (company_profile_id)
REFERENCES freight.company_profiles (id) ON DELETE RESTRICT,
CONSTRAINT fk_invoices_payment FOREIGN KEY (payment_id)
REFERENCES freight.payments (id) ON DELETE SET NULL
);
`);
await queryRunner.query(
`CREATE INDEX idx_invoices_company ON freight.invoices (company_id);`,
); );
`); await queryRunner.query(
`CREATE INDEX idx_invoices_company_profile ON freight.invoices (company_profile_id);`,
await queryRunner.query(
`CREATE INDEX idx_invoices_company ON freight.invoices (company_id);`,
);
await queryRunner.query(
`CREATE INDEX idx_invoices_company_profile ON freight.invoices (company_profile_id);`,
);
await queryRunner.query(
`CREATE INDEX idx_invoices_source ON freight.invoices (source, source_id);`,
);
await queryRunner.query(
`CREATE INDEX idx_invoices_status ON freight.invoices (status);`,
);
await queryRunner.query(`
CREATE TABLE freight.invoice_lines (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
invoice_id uuid NOT NULL,
charge_type varchar NOT NULL,
description varchar(255),
quantity numeric(12, 2) NOT NULL DEFAULT 1,
unit_rate numeric(14, 2) NOT NULL DEFAULT 0,
amount numeric(14, 2) NOT NULL,
currency varchar(8) NOT NULL DEFAULT 'ETB',
metadata jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
CONSTRAINT pk_invoice_lines PRIMARY KEY (id),
CONSTRAINT fk_invoice_lines_invoice FOREIGN KEY (invoice_id)
REFERENCES freight.invoices (id) ON DELETE CASCADE
); );
`); await queryRunner.query(
`CREATE INDEX idx_invoices_source ON freight.invoices (source, source_id);`,
);
await queryRunner.query(
`CREATE INDEX idx_invoices_status ON freight.invoices (status);`,
);
}
await queryRunner.query( const invoiceLinesExists = await queryRunner.query(
`CREATE INDEX idx_invoice_lines_invoice ON freight.invoice_lines (invoice_id);`, `SELECT 1 FROM information_schema.tables WHERE table_schema = 'freight' AND table_name = 'invoice_lines';`,
); );
if (!invoiceLinesExists.length) {
await queryRunner.query(`
CREATE TABLE freight.invoice_lines (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
invoice_id uuid NOT NULL,
charge_type varchar NOT NULL,
description varchar(255),
quantity numeric(12, 2) NOT NULL DEFAULT 1,
unit_rate numeric(14, 2) NOT NULL DEFAULT 0,
amount numeric(14, 2) NOT NULL,
currency varchar(8) NOT NULL DEFAULT 'ETB',
metadata jsonb,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
deleted_at timestamptz,
CONSTRAINT pk_invoice_lines PRIMARY KEY (id),
CONSTRAINT fk_invoice_lines_invoice FOREIGN KEY (invoice_id)
REFERENCES freight.invoices (id) ON DELETE CASCADE
);
`);
await queryRunner.query(
`CREATE INDEX idx_invoice_lines_invoice ON freight.invoice_lines (invoice_id);`,
);
}
} }
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {

View File

@@ -441,10 +441,10 @@ const FirstMilePage = () => {
}); });
const allocateMutation = useMutation({ const allocateMutation = useMutation({
mutationFn: (data) => apiClient.post(`/first-mile/${containerAllocationFirstMileId}/allocate-containers`, data), mutationFn: (data) => api.post(`/first-mile/${containerAllocationFirstMileId}/allocate-containers`, data),
onSuccess: () => { onSuccess: () => {
toast({ title: "Containers allocated" }); toast({ title: "Containers allocated" });
void qc.invalidateQueries({ queryKey: QUERY_KEYS.FIRST_MILE.detail(containerAllocationFirstMileId ?? "") }); void qc.invalidateQueries({ queryKey: QUERY_KEYS.FIRST_MILE.byId(containerAllocationFirstMileId ?? "") });
setContainerAllocationOpen(false); setContainerAllocationOpen(false);
setContainerAllocationFirstMileId(null); setContainerAllocationFirstMileId(null);
}, },

View File

@@ -395,7 +395,7 @@ const LastMilePage = () => {
api.post(`/last-mile/${activeId}/allocate-containers`, data), api.post(`/last-mile/${activeId}/allocate-containers`, data),
onSuccess: () => { onSuccess: () => {
toast({ title: "Containers allocated", variant: "default" }); toast({ title: "Containers allocated", variant: "default" });
void qc.invalidateQueries({ queryKey: QUERY_KEYS.LAST_MILE.detail(activeId ?? "") }); void qc.invalidateQueries({ queryKey: QUERY_KEYS.LAST_MILE.byId(activeId ?? "") });
closeAllocation(); closeAllocation();
}, },
onError: () => { onError: () => {