Add quotation and tariff backend flow
All checks were successful
Build Docker Image / build (push) Successful in 3m32s
All checks were successful
Build Docker Image / build (push) Successful in 3m32s
This commit is contained in:
166
prisma/migrations/0_init/migration.sql
Normal file
166
prisma/migrations/0_init/migration.sql
Normal file
@@ -0,0 +1,166 @@
|
||||
-- CreateSchema
|
||||
CREATE SCHEMA IF NOT EXISTS "public";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "orders_tariff_reference" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"team_uuid" VARCHAR(100) NOT NULL,
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"status" VARCHAR(20) NOT NULL DEFAULT 'active',
|
||||
"operation_code" VARCHAR(50),
|
||||
"incoterms_code" VARCHAR(20),
|
||||
"transport_type_code" VARCHAR(50),
|
||||
"tare_type_code" VARCHAR(50),
|
||||
"source_country_code" VARCHAR(10),
|
||||
"destination_country_code" VARCHAR(10),
|
||||
"source_hub_uuid" VARCHAR(100),
|
||||
"destination_hub_uuid" VARCHAR(100),
|
||||
"min_weight_kg" DECIMAL(12,2),
|
||||
"max_weight_kg" DECIMAL(12,2),
|
||||
"min_volume_cbm" DECIMAL(12,3),
|
||||
"max_volume_cbm" DECIMAL(12,3),
|
||||
"min_distance_km" INTEGER,
|
||||
"max_distance_km" INTEGER,
|
||||
"amount_usd" DECIMAL(12,2) NOT NULL,
|
||||
"min_price_usd" DECIMAL(12,2),
|
||||
"eta_days" INTEGER,
|
||||
"priority" INTEGER NOT NULL DEFAULT 100,
|
||||
"currency" VARCHAR(10) NOT NULL DEFAULT 'USD',
|
||||
"dmn_expression" TEXT,
|
||||
"notes" TEXT,
|
||||
"created_by_user_id" VARCHAR(255),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "orders_tariff_reference_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "orders_quotation" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"team_uuid" VARCHAR(100) NOT NULL,
|
||||
"created_by_user_id" VARCHAR(255),
|
||||
"title" VARCHAR(255) NOT NULL DEFAULT 'Quotation',
|
||||
"status" VARCHAR(30) NOT NULL DEFAULT 'draft',
|
||||
"operation_code" VARCHAR(50),
|
||||
"incoterms_code" VARCHAR(20),
|
||||
"transport_type_code" VARCHAR(50),
|
||||
"tare_type_code" VARCHAR(50),
|
||||
"source_country_code" VARCHAR(10),
|
||||
"source_hub_uuid" VARCHAR(100),
|
||||
"source_location_uuid" VARCHAR(100),
|
||||
"source_location_name" VARCHAR(255),
|
||||
"source_latitude" DOUBLE PRECISION,
|
||||
"source_longitude" DOUBLE PRECISION,
|
||||
"destination_country_code" VARCHAR(10),
|
||||
"destination_hub_uuid" VARCHAR(100),
|
||||
"destination_location_uuid" VARCHAR(100),
|
||||
"destination_location_name" VARCHAR(255),
|
||||
"destination_latitude" DOUBLE PRECISION,
|
||||
"destination_longitude" DOUBLE PRECISION,
|
||||
"chargeable_weight_kg" DECIMAL(12,2),
|
||||
"gross_weight_kg" DECIMAL(12,2),
|
||||
"volume_cbm" DECIMAL(12,3),
|
||||
"units_count" INTEGER,
|
||||
"route_distance_km" INTEGER,
|
||||
"selected_tariff_id" INTEGER,
|
||||
"tariff_match_summary" TEXT,
|
||||
"tariff_snapshot" TEXT,
|
||||
"total_amount" DECIMAL(12,2) NOT NULL DEFAULT 0,
|
||||
"currency" VARCHAR(10) NOT NULL DEFAULT 'USD',
|
||||
"eta_days" INTEGER,
|
||||
"notes" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "orders_quotation_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "orders_quotation_change" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"quotation_id" INTEGER NOT NULL,
|
||||
"actor_user_id" VARCHAR(255),
|
||||
"actor_label" VARCHAR(255),
|
||||
"source" VARCHAR(50) NOT NULL,
|
||||
"summary" TEXT,
|
||||
"payload_json" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "orders_quotation_change_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "orders_order" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"uuid" TEXT NOT NULL,
|
||||
"team_uuid" VARCHAR(100) NOT NULL,
|
||||
"quotation_id" INTEGER,
|
||||
"created_by_user_id" VARCHAR(255),
|
||||
"name" VARCHAR(255) NOT NULL,
|
||||
"status" VARCHAR(30) NOT NULL DEFAULT 'draft',
|
||||
"total_amount" DECIMAL(12,2) NOT NULL DEFAULT 0,
|
||||
"currency" VARCHAR(10) NOT NULL DEFAULT 'USD',
|
||||
"source_location_uuid" VARCHAR(100),
|
||||
"source_location_name" VARCHAR(255),
|
||||
"source_country_code" VARCHAR(10),
|
||||
"source_latitude" DOUBLE PRECISION,
|
||||
"source_longitude" DOUBLE PRECISION,
|
||||
"destination_location_uuid" VARCHAR(100),
|
||||
"destination_location_name" VARCHAR(255),
|
||||
"destination_country_code" VARCHAR(10),
|
||||
"destination_latitude" DOUBLE PRECISION,
|
||||
"destination_longitude" DOUBLE PRECISION,
|
||||
"eta_days" INTEGER,
|
||||
"notes" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "orders_order_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "orders_tariff_reference_uuid_key" ON "orders_tariff_reference"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_tariff_reference_team_uuid_status_priority_idx" ON "orders_tariff_reference"("team_uuid", "status", "priority");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_tariff_reference_team_uuid_source_country_code_desti_idx" ON "orders_tariff_reference"("team_uuid", "source_country_code", "destination_country_code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "orders_quotation_uuid_key" ON "orders_quotation"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_quotation_team_uuid_status_created_at_idx" ON "orders_quotation"("team_uuid", "status", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_quotation_team_uuid_source_country_code_destination__idx" ON "orders_quotation"("team_uuid", "source_country_code", "destination_country_code");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "orders_quotation_change_uuid_key" ON "orders_quotation_change"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_quotation_change_quotation_id_created_at_idx" ON "orders_quotation_change"("quotation_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "orders_order_uuid_key" ON "orders_order"("uuid");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "orders_order_quotation_id_key" ON "orders_order"("quotation_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "orders_order_team_uuid_created_at_idx" ON "orders_order"("team_uuid", "created_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "orders_quotation" ADD CONSTRAINT "orders_quotation_selected_tariff_id_fkey" FOREIGN KEY ("selected_tariff_id") REFERENCES "orders_tariff_reference"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "orders_quotation_change" ADD CONSTRAINT "orders_quotation_change_quotation_id_fkey" FOREIGN KEY ("quotation_id") REFERENCES "orders_quotation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "orders_order" ADD CONSTRAINT "orders_order_quotation_id_fkey" FOREIGN KEY ("quotation_id") REFERENCES "orders_quotation"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
139
prisma/schema.prisma
Normal file
139
prisma/schema.prisma
Normal file
@@ -0,0 +1,139 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("ORDERS_DATABASE_URL")
|
||||
}
|
||||
|
||||
model TariffReference {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String @map("team_uuid") @db.VarChar(100)
|
||||
name String @db.VarChar(255)
|
||||
status String @default("active") @db.VarChar(20)
|
||||
operationCode String? @map("operation_code") @db.VarChar(50)
|
||||
incotermsCode String? @map("incoterms_code") @db.VarChar(20)
|
||||
transportTypeCode String? @map("transport_type_code") @db.VarChar(50)
|
||||
tareTypeCode String? @map("tare_type_code") @db.VarChar(50)
|
||||
sourceCountryCode String? @map("source_country_code") @db.VarChar(10)
|
||||
destinationCountryCode String? @map("destination_country_code") @db.VarChar(10)
|
||||
sourceHubUuid String? @map("source_hub_uuid") @db.VarChar(100)
|
||||
destinationHubUuid String? @map("destination_hub_uuid") @db.VarChar(100)
|
||||
minWeightKg Decimal? @map("min_weight_kg") @db.Decimal(12, 2)
|
||||
maxWeightKg Decimal? @map("max_weight_kg") @db.Decimal(12, 2)
|
||||
minVolumeCbm Decimal? @map("min_volume_cbm") @db.Decimal(12, 3)
|
||||
maxVolumeCbm Decimal? @map("max_volume_cbm") @db.Decimal(12, 3)
|
||||
minDistanceKm Int? @map("min_distance_km")
|
||||
maxDistanceKm Int? @map("max_distance_km")
|
||||
amountUsd Decimal @map("amount_usd") @db.Decimal(12, 2)
|
||||
minPriceUsd Decimal? @map("min_price_usd") @db.Decimal(12, 2)
|
||||
etaDays Int? @map("eta_days")
|
||||
priority Int @default(100)
|
||||
currency String @default("USD") @db.VarChar(10)
|
||||
dmnExpression String? @map("dmn_expression")
|
||||
notes String?
|
||||
createdByUserId String? @map("created_by_user_id") @db.VarChar(255)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
quotations Quotation[] @relation("QuotationSelectedTariff")
|
||||
|
||||
@@index([teamUuid, status, priority])
|
||||
@@index([teamUuid, sourceCountryCode, destinationCountryCode])
|
||||
@@map("orders_tariff_reference")
|
||||
}
|
||||
|
||||
model Quotation {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String @map("team_uuid") @db.VarChar(100)
|
||||
createdByUserId String? @map("created_by_user_id") @db.VarChar(255)
|
||||
title String @default("Quotation") @db.VarChar(255)
|
||||
status String @default("draft") @db.VarChar(30)
|
||||
operationCode String? @map("operation_code") @db.VarChar(50)
|
||||
incotermsCode String? @map("incoterms_code") @db.VarChar(20)
|
||||
transportTypeCode String? @map("transport_type_code") @db.VarChar(50)
|
||||
tareTypeCode String? @map("tare_type_code") @db.VarChar(50)
|
||||
sourceCountryCode String? @map("source_country_code") @db.VarChar(10)
|
||||
sourceHubUuid String? @map("source_hub_uuid") @db.VarChar(100)
|
||||
sourceLocationUuid String? @map("source_location_uuid") @db.VarChar(100)
|
||||
sourceLocationName String? @map("source_location_name") @db.VarChar(255)
|
||||
sourceLatitude Float? @map("source_latitude")
|
||||
sourceLongitude Float? @map("source_longitude")
|
||||
destinationCountryCode String? @map("destination_country_code") @db.VarChar(10)
|
||||
destinationHubUuid String? @map("destination_hub_uuid") @db.VarChar(100)
|
||||
destinationLocationUuid String? @map("destination_location_uuid") @db.VarChar(100)
|
||||
destinationLocationName String? @map("destination_location_name") @db.VarChar(255)
|
||||
destinationLatitude Float? @map("destination_latitude")
|
||||
destinationLongitude Float? @map("destination_longitude")
|
||||
chargeableWeightKg Decimal? @map("chargeable_weight_kg") @db.Decimal(12, 2)
|
||||
grossWeightKg Decimal? @map("gross_weight_kg") @db.Decimal(12, 2)
|
||||
volumeCbm Decimal? @map("volume_cbm") @db.Decimal(12, 3)
|
||||
unitsCount Int? @map("units_count")
|
||||
routeDistanceKm Int? @map("route_distance_km")
|
||||
selectedTariffId Int? @map("selected_tariff_id")
|
||||
selectedTariff TariffReference? @relation("QuotationSelectedTariff", fields: [selectedTariffId], references: [id], onDelete: SetNull)
|
||||
tariffMatchSummary String? @map("tariff_match_summary")
|
||||
tariffSnapshot String? @map("tariff_snapshot")
|
||||
totalAmount Decimal @default(0) @map("total_amount") @db.Decimal(12, 2)
|
||||
currency String @default("USD") @db.VarChar(10)
|
||||
etaDays Int? @map("eta_days")
|
||||
notes String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
orders Order[]
|
||||
changes QuotationChange[]
|
||||
|
||||
@@index([teamUuid, status, createdAt])
|
||||
@@index([teamUuid, sourceCountryCode, destinationCountryCode])
|
||||
@@map("orders_quotation")
|
||||
}
|
||||
|
||||
model QuotationChange {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
quotationId Int @map("quotation_id")
|
||||
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
|
||||
actorUserId String? @map("actor_user_id") @db.VarChar(255)
|
||||
actorLabel String? @map("actor_label") @db.VarChar(255)
|
||||
source String @db.VarChar(50)
|
||||
summary String?
|
||||
payloadJson String? @map("payload_json")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
@@index([quotationId, createdAt])
|
||||
@@map("orders_quotation_change")
|
||||
}
|
||||
|
||||
model Order {
|
||||
id Int @id @default(autoincrement())
|
||||
uuid String @unique @default(uuid())
|
||||
teamUuid String @map("team_uuid") @db.VarChar(100)
|
||||
quotationId Int? @unique @map("quotation_id")
|
||||
quotation Quotation? @relation(fields: [quotationId], references: [id], onDelete: SetNull)
|
||||
createdByUserId String? @map("created_by_user_id") @db.VarChar(255)
|
||||
name String @db.VarChar(255)
|
||||
status String @default("draft") @db.VarChar(30)
|
||||
totalAmount Decimal @default(0) @map("total_amount") @db.Decimal(12, 2)
|
||||
currency String @default("USD") @db.VarChar(10)
|
||||
sourceLocationUuid String? @map("source_location_uuid") @db.VarChar(100)
|
||||
sourceLocationName String? @map("source_location_name") @db.VarChar(255)
|
||||
sourceCountryCode String? @map("source_country_code") @db.VarChar(10)
|
||||
sourceLatitude Float? @map("source_latitude")
|
||||
sourceLongitude Float? @map("source_longitude")
|
||||
destinationLocationUuid String? @map("destination_location_uuid") @db.VarChar(100)
|
||||
destinationLocationName String? @map("destination_location_name") @db.VarChar(255)
|
||||
destinationCountryCode String? @map("destination_country_code") @db.VarChar(10)
|
||||
destinationLatitude Float? @map("destination_latitude")
|
||||
destinationLongitude Float? @map("destination_longitude")
|
||||
etaDays Int? @map("eta_days")
|
||||
notes String?
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([teamUuid, createdAt])
|
||||
@@map("orders_order")
|
||||
}
|
||||
Reference in New Issue
Block a user