CRM apis
This commit is contained in:
+164
-23
@@ -85,6 +85,50 @@ enum InteractionType {
|
||||
note
|
||||
}
|
||||
|
||||
enum SalesPipelineStage {
|
||||
negotiation
|
||||
awaiting_catalog
|
||||
awaiting_price
|
||||
ready_to_order
|
||||
}
|
||||
|
||||
enum OpportunityOutcome {
|
||||
open
|
||||
won
|
||||
lost
|
||||
}
|
||||
|
||||
enum LostReason {
|
||||
price
|
||||
product
|
||||
supply_time
|
||||
customer_decision
|
||||
other
|
||||
}
|
||||
|
||||
enum TimelineEventSource {
|
||||
manual
|
||||
system
|
||||
}
|
||||
|
||||
enum TimelineEventKind {
|
||||
meeting
|
||||
call
|
||||
note
|
||||
reminder
|
||||
next_action
|
||||
order_created
|
||||
price_announced
|
||||
price_confirmed
|
||||
catalog_requested
|
||||
}
|
||||
|
||||
enum AssignmentRequestStatus {
|
||||
pending
|
||||
approved
|
||||
rejected
|
||||
}
|
||||
|
||||
enum ProductSeason {
|
||||
summer
|
||||
winter
|
||||
@@ -240,21 +284,29 @@ model Customer {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
company Company? @relation(fields: [companyId], references: [id], onDelete: SetNull)
|
||||
levelDef CustomerLevelDef? @relation(fields: [levelDefId], references: [id], onDelete: SetNull)
|
||||
assignedAgent Customer? @relation("AgentCustomers", fields: [assignedAgentId], references: [id], onDelete: SetNull)
|
||||
agentCustomers Customer[] @relation("AgentCustomers")
|
||||
carts Cart[]
|
||||
orders Order[]
|
||||
notifications CustomerNotification[]
|
||||
meetings MeetingInteraction[] @relation("MeetingCustomer")
|
||||
meetingsAsAgent MeetingInteraction[] @relation("MeetingAgent")
|
||||
reminders Reminder[] @relation("ReminderOwner")
|
||||
remindersAbout Reminder[] @relation("ReminderCustomer")
|
||||
favorites ProductFavorite[]
|
||||
catalogRequests CatalogRequest[]
|
||||
productSuggestions ProductSuggestion[]
|
||||
addresses CustomerAddress[]
|
||||
company Company? @relation(fields: [companyId], references: [id], onDelete: SetNull)
|
||||
levelDef CustomerLevelDef? @relation(fields: [levelDefId], references: [id], onDelete: SetNull)
|
||||
assignedAgent Customer? @relation("AgentCustomers", fields: [assignedAgentId], references: [id], onDelete: SetNull)
|
||||
agentCustomers Customer[] @relation("AgentCustomers")
|
||||
carts Cart[]
|
||||
orders Order[]
|
||||
notifications CustomerNotification[]
|
||||
meetings MeetingInteraction[] @relation("MeetingCustomer")
|
||||
meetingsAsAgent MeetingInteraction[] @relation("MeetingAgent")
|
||||
reminders Reminder[] @relation("ReminderOwner")
|
||||
remindersAbout Reminder[] @relation("ReminderCustomer")
|
||||
favorites ProductFavorite[]
|
||||
catalogRequests CatalogRequest[]
|
||||
productSuggestions ProductSuggestion[]
|
||||
addresses CustomerAddress[]
|
||||
salesOpportunities SalesOpportunity[]
|
||||
timelineEvents CustomerTimelineEvent[]
|
||||
crmNextActions CrmNextAction[]
|
||||
assignmentRequests CustomerAssignmentRequest[] @relation("AssignmentCustomer")
|
||||
assignmentFrom CustomerAssignmentRequest[] @relation("AssignmentFromAgent")
|
||||
assignmentTo CustomerAssignmentRequest[] @relation("AssignmentToAgent")
|
||||
assignmentRequested CustomerAssignmentRequest[] @relation("AssignmentRequestedBy")
|
||||
opportunitiesOwned SalesOpportunity[] @relation("OpportunityAgent")
|
||||
|
||||
@@index([companyId])
|
||||
@@index([appRole])
|
||||
@@ -363,14 +415,15 @@ model Order {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
user Customer @relation(fields: [userId], references: [id], onDelete: Restrict)
|
||||
company Company @relation(fields: [companyId], references: [id], onDelete: Restrict)
|
||||
items OrderItem[]
|
||||
checks Check[]
|
||||
cashReceipt CashPaymentReceipt?
|
||||
shipment Shipment?
|
||||
statusHistory OrderStatusHistory[]
|
||||
notifications CustomerNotification[]
|
||||
user Customer @relation(fields: [userId], references: [id], onDelete: Restrict)
|
||||
company Company @relation(fields: [companyId], references: [id], onDelete: Restrict)
|
||||
items OrderItem[]
|
||||
checks Check[]
|
||||
cashReceipt CashPaymentReceipt?
|
||||
shipment Shipment?
|
||||
statusHistory OrderStatusHistory[]
|
||||
notifications CustomerNotification[]
|
||||
wonOpportunities SalesOpportunity[]
|
||||
|
||||
@@index([userId])
|
||||
@@index([companyId])
|
||||
@@ -620,6 +673,94 @@ model Reminder {
|
||||
@@index([date])
|
||||
}
|
||||
|
||||
model SalesOpportunity {
|
||||
id String @id @default(cuid())
|
||||
customerId String
|
||||
stage SalesPipelineStage @default(negotiation)
|
||||
outcome OpportunityOutcome @default(open)
|
||||
lostReason LostReason?
|
||||
lostNote String?
|
||||
lostAt DateTime?
|
||||
wonOrderId String?
|
||||
wonAt DateTime?
|
||||
assignedAgentId String?
|
||||
ownerAdminId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
||||
assignedAgent Customer? @relation("OpportunityAgent", fields: [assignedAgentId], references: [id], onDelete: SetNull)
|
||||
wonOrder Order? @relation(fields: [wonOrderId], references: [id], onDelete: SetNull)
|
||||
nextActions CrmNextAction[]
|
||||
|
||||
@@index([customerId])
|
||||
@@index([stage, outcome])
|
||||
@@index([assignedAgentId])
|
||||
}
|
||||
|
||||
model CustomerTimelineEvent {
|
||||
id String @id @default(cuid())
|
||||
customerId String
|
||||
kind TimelineEventKind
|
||||
source TimelineEventSource @default(manual)
|
||||
title String
|
||||
body String?
|
||||
occurredAt DateTime @default(now())
|
||||
actorAdminId String?
|
||||
actorCustomerId String?
|
||||
relatedOrderId String?
|
||||
relatedMeetingId String?
|
||||
relatedActionId String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([customerId, occurredAt])
|
||||
}
|
||||
|
||||
model CrmNextAction {
|
||||
id String @id @default(cuid())
|
||||
customerId String
|
||||
opportunityId String?
|
||||
title String
|
||||
description String?
|
||||
dueAt DateTime
|
||||
completed Boolean @default(false)
|
||||
completedAt DateTime?
|
||||
assigneeAdminId String?
|
||||
assigneeAgentId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
||||
opportunity SalesOpportunity? @relation(fields: [opportunityId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([customerId, completed])
|
||||
@@index([dueAt])
|
||||
}
|
||||
|
||||
model CustomerAssignmentRequest {
|
||||
id String @id @default(cuid())
|
||||
customerId String
|
||||
fromAgentId String?
|
||||
toAgentId String
|
||||
requestedByAgentId String
|
||||
status AssignmentRequestStatus @default(pending)
|
||||
reviewNote String?
|
||||
reviewedByAdminId String?
|
||||
reviewedAt DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
customer Customer @relation("AssignmentCustomer", fields: [customerId], references: [id], onDelete: Cascade)
|
||||
fromAgent Customer? @relation("AssignmentFromAgent", fields: [fromAgentId], references: [id], onDelete: SetNull)
|
||||
toAgent Customer @relation("AssignmentToAgent", fields: [toAgentId], references: [id], onDelete: Cascade)
|
||||
requestedByAgent Customer @relation("AssignmentRequestedBy", fields: [requestedByAgentId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([status])
|
||||
@@index([customerId])
|
||||
}
|
||||
|
||||
model ProductFavorite {
|
||||
id String @id @default(cuid())
|
||||
customerId String
|
||||
|
||||
Reference in New Issue
Block a user