261 lines
7.0 KiB
Plaintext
261 lines
7.0 KiB
Plaintext
// User Management Domain
|
|
// Contains User, Farmer, Buyer, Administrator models and related enums
|
|
|
|
// User Status Enums
|
|
enum FarmerStatus {
|
|
ACTIVE
|
|
INACTIVE
|
|
SUSPENDED
|
|
PENDING_VERIFICATION
|
|
BLACKLISTED
|
|
}
|
|
|
|
enum BuyerStatus {
|
|
ACTIVE
|
|
INACTIVE
|
|
SUSPENDED
|
|
PENDING_VERIFICATION
|
|
BLACKLISTED
|
|
}
|
|
|
|
enum BuyerType {
|
|
INDIVIDUAL
|
|
WHOLESALER
|
|
RETAILER
|
|
PROCESSOR
|
|
EXPORTER
|
|
COOPERATIVE
|
|
GOVERNMENT
|
|
RESTAURANT
|
|
HOTEL
|
|
}
|
|
|
|
enum BusinessSize {
|
|
MICRO
|
|
SMALL
|
|
MEDIUM
|
|
LARGE
|
|
ENTERPRISE
|
|
}
|
|
|
|
enum LandOwnership {
|
|
OWNER
|
|
TENANT
|
|
SHARECROPPER
|
|
COOPERATIVE_MEMBER
|
|
GOVERNMENT_LEASE
|
|
FAMILY_LAND
|
|
OTHER
|
|
}
|
|
|
|
// User Models
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
phone String?
|
|
name String
|
|
role UserRole
|
|
isActive Boolean @default(true)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
farmer Farmer?
|
|
buyer Buyer?
|
|
administrator Administrator?
|
|
notifications NotificationRecipient[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model Farmer {
|
|
id String @id @default(cuid())
|
|
userId String @unique
|
|
farmerCode String @unique
|
|
name String
|
|
phone String?
|
|
email String?
|
|
dateOfBirth DateTime?
|
|
gender Gender?
|
|
maritalStatus MaritalStatus?
|
|
spouseName String?
|
|
numberOfChildren Int? @default(0)
|
|
religionId String?
|
|
religion Religion? @relation(fields: [religionId], references: [id])
|
|
nationalityId String? @default("indonesia")
|
|
nationality Country? @relation("FarmerNationality", fields: [nationalityId], references: [id])
|
|
address String?
|
|
village String?
|
|
district String?
|
|
province String?
|
|
postalCode String?
|
|
countryId String? @default("indonesia")
|
|
country Country? @relation("FarmerCountry", fields: [countryId], references: [id])
|
|
|
|
// Location data
|
|
latitude Float?
|
|
longitude Float?
|
|
addressGeoJson Json? // GeoJSON point for precise location
|
|
|
|
// Identity information
|
|
identityType IdentityType?
|
|
identityNumber String?
|
|
identityExpiry DateTime?
|
|
|
|
// Banking information
|
|
bankAccount String?
|
|
bankName String?
|
|
accountHolderName String?
|
|
|
|
// Photos and attachments
|
|
profilePhotoUrl String?
|
|
idCardFrontUrl String?
|
|
idCardBackUrl String?
|
|
|
|
// Verification status
|
|
isVerified Boolean @default(false)
|
|
verificationDate DateTime?
|
|
verifiedBy String? // admin ID who verified
|
|
verificationNotes String?
|
|
|
|
// Farming experience
|
|
farmingExperience Int? // years of experience
|
|
educationLevelId String?
|
|
educationLevel EducationLevel? @relation(fields: [educationLevelId], references: [id])
|
|
occupation String? // primary occupation if not full-time farmer
|
|
monthlyIncome Decimal? // estimated monthly income
|
|
landOwnership LandOwnership?
|
|
primaryCrop String?
|
|
farmingMethods String[] // organic, conventional, etc.
|
|
hasVehicle Boolean? // for transportation
|
|
vehicleType String? // motorcycle, car, truck, etc.
|
|
hasSmartphone Boolean? @default(true)
|
|
internetAccess Boolean? @default(true)
|
|
|
|
// Emergency contact
|
|
emergencyContactName String?
|
|
emergencyContactPhone String?
|
|
emergencyContactRelation String?
|
|
|
|
// Status and metadata
|
|
status FarmerStatus @default(ACTIVE)
|
|
notes String?
|
|
joinedAt DateTime @default(now())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
farms Farm[]
|
|
trainings FarmerTraining[]
|
|
certifications FarmerCertification[]
|
|
procurements Procurement[]
|
|
harvests Harvest[]
|
|
attachments FarmerAttachment[]
|
|
workers FarmWorker[]
|
|
laborRecords LaborRecord[]
|
|
laborSchedules LaborSchedule[]
|
|
equipment Equipment[]
|
|
assets Asset[]
|
|
financialRecords FinancialRecord[]
|
|
reviews BuyerReview[]
|
|
contracts Contract[]
|
|
seasonHarvests SeasonHarvest[]
|
|
|
|
@@index([farmerCode])
|
|
@@index([userId])
|
|
@@index([status])
|
|
@@index([joinedAt])
|
|
@@index([latitude, longitude])
|
|
@@map("farmers")
|
|
}
|
|
|
|
model Buyer {
|
|
id String @id @default(cuid())
|
|
userId String @unique
|
|
buyerCode String @unique
|
|
name String
|
|
company String?
|
|
phone String?
|
|
email String?
|
|
address String?
|
|
|
|
// Enhanced buyer details
|
|
buyerType BuyerType?
|
|
businessLicense String?
|
|
taxNumber String?
|
|
contactPerson String?
|
|
contactPersonPhone String?
|
|
paymentTerms Int? // days
|
|
creditLimit Decimal?
|
|
preferredProducts String[]
|
|
qualityRequirements String?
|
|
|
|
// Location and logistics
|
|
warehouseAddress String?
|
|
deliveryPreference String?
|
|
operatingRadius Decimal? // km
|
|
|
|
// Business details
|
|
businessSize BusinessSize?
|
|
yearEstablished Int?
|
|
annualVolume Decimal? // estimated annual purchase volume
|
|
employeeCount Int?
|
|
website String?
|
|
|
|
// Financial information
|
|
bankAccount String?
|
|
bankName String?
|
|
accountHolderName String?
|
|
|
|
// Verification and status
|
|
isVerified Boolean @default(false)
|
|
verificationDate DateTime?
|
|
verifiedBy String? // admin ID who verified
|
|
verificationNotes String?
|
|
status BuyerStatus @default(ACTIVE)
|
|
|
|
// Photos and documents
|
|
profilePhotoUrl String?
|
|
businessLicenseUrl String?
|
|
taxCertificateUrl String?
|
|
|
|
// Preferences
|
|
preferredPickupDays String[] // Mon, Tue, Wed, etc.
|
|
preferredPickupTime String?
|
|
minimumOrderQuantity Decimal?
|
|
maximumOrderQuantity Decimal?
|
|
|
|
notes String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
procurements Procurement[]
|
|
reviews BuyerReview[]
|
|
contracts Contract[]
|
|
|
|
@@index([buyerCode])
|
|
@@index([userId])
|
|
@@index([status])
|
|
@@index([buyerType])
|
|
@@map("buyers")
|
|
}
|
|
|
|
model Administrator {
|
|
id String @id @default(cuid())
|
|
userId String @unique
|
|
adminCode String @unique
|
|
name String
|
|
phone String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
// Relations
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([adminCode])
|
|
@@index([userId])
|
|
@@map("administrators")
|
|
} |