Add WooCommerce integration: sync orders to invoices/people with webhook, cron, and settings UI.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "WooCommerceConnection" (
|
||||
"id" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"label" TEXT NOT NULL,
|
||||
"storeUrl" TEXT NOT NULL,
|
||||
"consumerKeyCiphertext" TEXT NOT NULL,
|
||||
"consumerKeyIv" TEXT NOT NULL,
|
||||
"consumerKeyTag" TEXT NOT NULL,
|
||||
"consumerKeyLast4" TEXT NOT NULL DEFAULT '',
|
||||
"consumerSecretCiphertext" TEXT NOT NULL,
|
||||
"consumerSecretIv" TEXT NOT NULL,
|
||||
"consumerSecretTag" TEXT NOT NULL,
|
||||
"webhookSecretCiphertext" TEXT,
|
||||
"webhookSecretIv" TEXT,
|
||||
"webhookSecretTag" TEXT,
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
"lastSyncAt" TIMESTAMP(3),
|
||||
"lastHealthAt" TIMESTAMP(3),
|
||||
"lastHealthOk" BOOLEAN,
|
||||
"lastError" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "WooCommerceConnection_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "WooCommerceOrderLink" (
|
||||
"id" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"connectionId" TEXT NOT NULL,
|
||||
"wooOrderId" TEXT NOT NULL,
|
||||
"wooOrderNumber" TEXT,
|
||||
"invoiceId" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL DEFAULT '',
|
||||
"total" DECIMAL(18,2) NOT NULL DEFAULT 0,
|
||||
"currency" TEXT NOT NULL DEFAULT 'IRR',
|
||||
"rawPayload" JSONB,
|
||||
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "WooCommerceOrderLink_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "WooCommerceConnection_organizationId_enabled_idx" ON "WooCommerceConnection"("organizationId", "enabled");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "WooCommerceOrderLink_organizationId_syncedAt_idx" ON "WooCommerceOrderLink"("organizationId", "syncedAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "WooCommerceOrderLink_invoiceId_idx" ON "WooCommerceOrderLink"("invoiceId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "WooCommerceOrderLink_connectionId_wooOrderId_key" ON "WooCommerceOrderLink"("connectionId", "wooOrderId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "WooCommerceConnection" ADD CONSTRAINT "WooCommerceConnection_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "WooCommerceOrderLink" ADD CONSTRAINT "WooCommerceOrderLink_connectionId_fkey" FOREIGN KEY ("connectionId") REFERENCES "WooCommerceConnection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -198,6 +198,7 @@ model Organization {
|
||||
apiKeys OrganizationApiKey[]
|
||||
webhookEndpoints WebhookEndpoint[]
|
||||
smsCampaigns SmsCampaign[]
|
||||
wooCommerceConnections WooCommerceConnection[]
|
||||
}
|
||||
|
||||
model User {
|
||||
@@ -1729,3 +1730,53 @@ model SmsCampaignRecipient {
|
||||
|
||||
@@index([campaignId, status])
|
||||
}
|
||||
|
||||
/// اتصال فروشگاه ووکامرس
|
||||
model WooCommerceConnection {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
label String
|
||||
storeUrl String
|
||||
consumerKeyCiphertext String
|
||||
consumerKeyIv String
|
||||
consumerKeyTag String
|
||||
consumerKeyLast4 String @default("")
|
||||
consumerSecretCiphertext String
|
||||
consumerSecretIv String
|
||||
consumerSecretTag String
|
||||
webhookSecretCiphertext String?
|
||||
webhookSecretIv String?
|
||||
webhookSecretTag String?
|
||||
enabled Boolean @default(true)
|
||||
lastSyncAt DateTime?
|
||||
lastHealthAt DateTime?
|
||||
lastHealthOk Boolean?
|
||||
lastError String?
|
||||
orders WooCommerceOrderLink[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([organizationId, enabled])
|
||||
}
|
||||
|
||||
model WooCommerceOrderLink {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
connectionId String
|
||||
connection WooCommerceConnection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
|
||||
wooOrderId String
|
||||
wooOrderNumber String?
|
||||
invoiceId String
|
||||
status String @default("")
|
||||
total Decimal @default(0) @db.Decimal(18, 2)
|
||||
currency String @default("IRR")
|
||||
rawPayload Json?
|
||||
syncedAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([connectionId, wooOrderId])
|
||||
@@index([organizationId, syncedAt])
|
||||
@@index([invoiceId])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user