refactor: update quotation structure and endpoint
This commit is contained in:
parent
4f4b8df9a3
commit
71ffd895f6
3 changed files with 262 additions and 363 deletions
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `QuotationService` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `QuotationServiceWork` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `QuotationServiceWorkProduct` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "QuotationService" DROP CONSTRAINT "QuotationService_quotationId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "QuotationService" DROP CONSTRAINT "QuotationService_refServiceId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "QuotationServiceWork" DROP CONSTRAINT "QuotationServiceWork_serviceId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "QuotationServiceWorkProduct" DROP CONSTRAINT "QuotationServiceWorkProduct_productId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "QuotationServiceWorkProduct" DROP CONSTRAINT "QuotationServiceWorkProduct_workId_fkey";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "QuotationService";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "QuotationServiceWork";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "QuotationServiceWorkProduct";
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "QuotationProductServiceList" (
|
||||
"id" TEXT NOT NULL,
|
||||
"quotationId" TEXT NOT NULL,
|
||||
"order" INTEGER NOT NULL,
|
||||
"vat" DOUBLE PRECISION NOT NULL,
|
||||
"amount" INTEGER NOT NULL,
|
||||
"discount" DOUBLE PRECISION NOT NULL,
|
||||
"pricePerUnit" DOUBLE PRECISION NOT NULL,
|
||||
"productId" TEXT NOT NULL,
|
||||
"workId" TEXT,
|
||||
"serviceId" TEXT,
|
||||
|
||||
CONSTRAINT "QuotationProductServiceList_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuotationProductServiceList" ADD CONSTRAINT "QuotationProductServiceList_quotationId_fkey" FOREIGN KEY ("quotationId") REFERENCES "Quotation"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuotationProductServiceList" ADD CONSTRAINT "QuotationProductServiceList_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuotationProductServiceList" ADD CONSTRAINT "QuotationProductServiceList_workId_fkey" FOREIGN KEY ("workId") REFERENCES "Work"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "QuotationProductServiceList" ADD CONSTRAINT "QuotationProductServiceList_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "Service"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
|
@ -931,7 +931,7 @@ model Product {
|
|||
productGroupId String
|
||||
|
||||
workProduct WorkProduct[]
|
||||
quotationServiceWorkProduct QuotationServiceWorkProduct[]
|
||||
quotationProductServiceList QuotationProductServiceList[]
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
createdBy User? @relation(name: "ProductCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
||||
|
|
@ -955,8 +955,8 @@ model Service {
|
|||
shared Boolean @default(false)
|
||||
selectedImage String?
|
||||
|
||||
work Work[]
|
||||
quotationService QuotationService[]
|
||||
work Work[]
|
||||
quotationProductServiceList QuotationProductServiceList[]
|
||||
|
||||
productGroup ProductGroup @relation(fields: [productGroupId], references: [id], onDelete: Cascade)
|
||||
productGroupId String
|
||||
|
|
@ -989,7 +989,8 @@ model Work {
|
|||
updatedBy User? @relation(name: "WorkUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
|
||||
updatedByUserId String?
|
||||
|
||||
productOnWork WorkProduct[]
|
||||
productOnWork WorkProduct[]
|
||||
quotationProductServiceList QuotationProductServiceList[]
|
||||
}
|
||||
|
||||
model WorkProduct {
|
||||
|
|
@ -1045,10 +1046,10 @@ model Quotation {
|
|||
workerCount Int
|
||||
worker QuotationWorker[]
|
||||
|
||||
service QuotationService[]
|
||||
|
||||
urgent Boolean @default(false)
|
||||
|
||||
productServiceList QuotationProductServiceList[]
|
||||
|
||||
totalPrice Float
|
||||
totalDiscount Float
|
||||
vat Float
|
||||
|
|
@ -1084,47 +1085,24 @@ model QuotationWorker {
|
|||
quotationId String
|
||||
}
|
||||
|
||||
model QuotationService {
|
||||
id String @id @default(cuid())
|
||||
|
||||
code String
|
||||
name String
|
||||
detail String
|
||||
attributes Json?
|
||||
|
||||
work QuotationServiceWork[]
|
||||
|
||||
refServiceId String
|
||||
refService Service @relation(fields: [refServiceId], references: [id])
|
||||
|
||||
quotation Quotation @relation(fields: [quotationId], references: [id], onDelete: Cascade)
|
||||
model QuotationProductServiceList {
|
||||
id String @id @default(cuid())
|
||||
quotationId String
|
||||
}
|
||||
quotation Quotation @relation(fields: [quotationId], references: [id])
|
||||
|
||||
model QuotationServiceWork {
|
||||
id String @id @default(cuid())
|
||||
|
||||
order Int
|
||||
name String
|
||||
attributes Json?
|
||||
|
||||
service QuotationService @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
||||
serviceId String
|
||||
|
||||
productOnWork QuotationServiceWorkProduct[]
|
||||
}
|
||||
|
||||
model QuotationServiceWorkProduct {
|
||||
order Int
|
||||
work QuotationServiceWork @relation(fields: [workId], references: [id], onDelete: Cascade)
|
||||
workId String
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
productId String
|
||||
order Int
|
||||
|
||||
vat Float
|
||||
amount Int
|
||||
discount Float
|
||||
pricePerUnit Float
|
||||
|
||||
@@id([workId, productId])
|
||||
productId String
|
||||
product Product @relation(fields: [productId], references: [id])
|
||||
|
||||
workId String?
|
||||
work Work? @relation(fields: [workId], references: [id])
|
||||
|
||||
serviceId String?
|
||||
service Service? @relation(fields: [serviceId], references: [id])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue