Migrate KYC backend from Django to Express + Apollo Server + Prisma
All checks were successful
Build Docker Image / build (push) Successful in 2m12s
All checks were successful
Build Docker Image / build (push) Successful in 2m12s
Replace Python/Django/Graphene with TypeScript/Express/Apollo Server. Same 3 endpoints (public/user/m2m), same JWT auth via Logto. Prisma replaces Django ORM. MongoDB, Temporal and SurrealDB integrations preserved.
This commit is contained in:
65
src/services/mongodb.ts
Normal file
65
src/services/mongodb.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
const MONGODB_URI = process.env.MONGODB_URI || ''
|
||||
const MONGODB_DB = process.env.MONGODB_DB || 'kyc'
|
||||
|
||||
export async function getCompanyDocuments(inn: string) {
|
||||
if (!MONGODB_URI) return []
|
||||
const client = new MongoClient(MONGODB_URI)
|
||||
try {
|
||||
await client.connect()
|
||||
const db = client.db(MONGODB_DB)
|
||||
return await db.collection('company_documents').find({ inn }).toArray()
|
||||
} finally {
|
||||
await client.close()
|
||||
}
|
||||
}
|
||||
|
||||
interface CompanySummary {
|
||||
inn?: string
|
||||
ogrn?: string
|
||||
name?: string
|
||||
companyType?: string
|
||||
registrationYear?: number
|
||||
isActive: boolean
|
||||
address?: string
|
||||
director?: string
|
||||
capital?: string
|
||||
activities: string[]
|
||||
sources: string[]
|
||||
lastUpdated?: string
|
||||
}
|
||||
|
||||
export function aggregateCompanyData(documents: Record<string, unknown>[]): CompanySummary {
|
||||
const summary: CompanySummary = {
|
||||
isActive: true,
|
||||
activities: [],
|
||||
sources: [],
|
||||
}
|
||||
|
||||
for (const doc of documents) {
|
||||
const source = (doc.source as string) || 'unknown'
|
||||
summary.sources.push(source)
|
||||
|
||||
const data = (doc.data as Record<string, unknown>) || {}
|
||||
|
||||
if (!summary.inn) summary.inn = doc.inn as string
|
||||
if (!summary.ogrn && data.ogrn) summary.ogrn = data.ogrn as string
|
||||
if (!summary.name && data.name) summary.name = data.name as string
|
||||
|
||||
if (!summary.companyType && summary.name) {
|
||||
const name = summary.name.toUpperCase()
|
||||
if (name.includes('ООО') || name.includes('ОБЩЕСТВО С ОГРАНИЧЕННОЙ')) summary.companyType = 'ООО'
|
||||
else if (name.includes('ПАО')) summary.companyType = 'ПАО'
|
||||
else if (name.includes('АО') || name.includes('АКЦИОНЕРНОЕ ОБЩЕСТВО')) summary.companyType = 'АО'
|
||||
else if (name.includes('ИП') || name.includes('ИНДИВИДУАЛЬНЫЙ ПРЕДПРИНИМАТЕЛЬ')) summary.companyType = 'ИП'
|
||||
}
|
||||
|
||||
const collectedAt = doc.collected_at as string | undefined
|
||||
if (collectedAt && (!summary.lastUpdated || collectedAt > summary.lastUpdated)) {
|
||||
summary.lastUpdated = collectedAt
|
||||
}
|
||||
}
|
||||
|
||||
return summary
|
||||
}
|
||||
Reference in New Issue
Block a user