Migration activity_events (uuid id, organization_id FK CASCADE, kind ENUM PG natif relance_sent/invoice_paid/invoice_imported/warning_drafted, at, label HTML léger, meta jsonb). Append-only — pas de mutation. Index (org, at).
Schema rules : kind typé en union + meta typé { invoiceId?, clientId?, planStepOrder? }.
Service activity_recorder.ts : recordActivity({orgId, kind, label, meta, trx?}). Branché dans :
- InvoicesController.markPaid → invoice_paid
- ImportBatchesController.validateDraft → invoice_imported
À venir : SendRelanceJob (relance_sent + warning_drafted) quand BullMQ sera là.
Service dashboard.ts :
- computeKpis(orgId) : 1 requête FILTER pour les counts par status + 1 requête pour les sommes paid this month / prev month / DSO. miseEnDemeurePending=0 et percentile=undefined V1 (placeholders honnêtes plutôt que faux chiffres).
- topLatePayers(orgId, 5) : INNER JOIN clients + agrégation count() par client_id, due_date < today + status actif.
Controller DashboardController :
- GET /dashboard/kpis : computeKpis
- GET /dashboard/activity : 20 derniers events de l'org, plus récent en tête
- GET /dashboard/top-late : top 5
Routes /api/v1/dashboard/* (auth requise).
Bruno : nouveau dossier 07-Dashboard avec 3 requêtes documentées.
Pour générer du contenu activity feed : encaisser une facture (Invoices → Mark paid) ou valider un draft (Imports → Validate). KPIs : créer des factures puis les marquer payées (paidAt rentre dans les sommes).
268 lines
8.8 KiB
TypeScript
268 lines
8.8 KiB
TypeScript
/**
|
|
* This file is automatically generated
|
|
* DO NOT EDIT manually
|
|
* Run "node ace migration:run" command to re-generate this file
|
|
*/
|
|
|
|
import { BaseModel, column } from '@adonisjs/lucid/orm'
|
|
import { DateTime } from 'luxon'
|
|
|
|
export class ActivityEventSchema extends BaseModel {
|
|
static $columns = ['at', 'createdAt', 'id', 'kind', 'label', 'meta', 'organizationId', 'updatedAt'] as const
|
|
$columns = ActivityEventSchema.$columns
|
|
@column.dateTime()
|
|
declare at: DateTime
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare kind: 'relance_sent' | 'invoice_paid' | 'invoice_imported' | 'warning_drafted'
|
|
@column()
|
|
declare label: string
|
|
@column()
|
|
declare meta: { invoiceId?: string; clientId?: string; planStepOrder?: number; [k: string]: unknown }
|
|
@column()
|
|
declare organizationId: string
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class AuthAccessTokenSchema extends BaseModel {
|
|
static $columns = ['abilities', 'createdAt', 'expiresAt', 'hash', 'id', 'lastUsedAt', 'name', 'tokenableId', 'type', 'updatedAt'] as const
|
|
$columns = AuthAccessTokenSchema.$columns
|
|
@column()
|
|
declare abilities: string
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime | null
|
|
@column.dateTime()
|
|
declare expiresAt: DateTime | null
|
|
@column()
|
|
declare hash: string
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column.dateTime()
|
|
declare lastUsedAt: DateTime | null
|
|
@column()
|
|
declare name: string | null
|
|
@column()
|
|
declare tokenableId: string
|
|
@column()
|
|
declare type: string
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class ClientSchema extends BaseModel {
|
|
static $columns = ['address', 'createdAt', 'email', 'id', 'name', 'notes', 'organizationId', 'phone', 'siret', 'updatedAt'] as const
|
|
$columns = ClientSchema.$columns
|
|
@column()
|
|
declare address: string | null
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column()
|
|
declare email: string
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare name: string
|
|
@column()
|
|
declare notes: string | null
|
|
@column()
|
|
declare organizationId: string
|
|
@column()
|
|
declare phone: string | null
|
|
@column()
|
|
declare siret: string | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class ImportBatchSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'id', 'organizationId', 'updatedAt'] as const
|
|
$columns = ImportBatchSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare organizationId: string
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class ImportDraftSchema extends BaseModel {
|
|
static $columns = ['batchId', 'confidence', 'createdAt', 'edited', 'extracted', 'filename', 'id', 'invoiceId', 'pdfStorageKey', 'status', 'updatedAt'] as const
|
|
$columns = ImportDraftSchema.$columns
|
|
@column()
|
|
declare batchId: string
|
|
@column()
|
|
declare confidence: Partial<{ clientId: number; clientName: number; clientEmail: number; numero: number; amountTtcCents: number; issueDate: number; dueDate: number; planId: number }>
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column()
|
|
declare edited: { clientId: string | null; clientName: string; clientEmail: string | null; numero: string; amountTtcCents: number; issueDate: string; dueDate: string; planId: string | null }
|
|
@column()
|
|
declare extracted: { clientId: string | null; clientName: string; clientEmail: string | null; numero: string; amountTtcCents: number; issueDate: string; dueDate: string; planId: string | null }
|
|
@column()
|
|
declare filename: string
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare invoiceId: string | null
|
|
@column()
|
|
declare pdfStorageKey: string | null
|
|
@column()
|
|
declare status: 'pending' | 'validated' | 'skipped'
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class InvoiceSchema extends BaseModel {
|
|
static $columns = ['amountTtcCents', 'clientId', 'createdAt', 'dueDate', 'id', 'issueDate', 'notes', 'numero', 'organizationId', 'paidAt', 'pdfStorageKey', 'planId', 'rubisEarned', 'status', 'updatedAt'] as const
|
|
$columns = InvoiceSchema.$columns
|
|
@column()
|
|
declare amountTtcCents: number
|
|
@column()
|
|
declare clientId: string
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column.dateTime()
|
|
declare dueDate: DateTime
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column.dateTime()
|
|
declare issueDate: DateTime
|
|
@column()
|
|
declare notes: string | null
|
|
@column()
|
|
declare numero: string
|
|
@column()
|
|
declare organizationId: string
|
|
@column.dateTime()
|
|
declare paidAt: DateTime | null
|
|
@column()
|
|
declare pdfStorageKey: string | null
|
|
@column()
|
|
declare planId: string | null
|
|
@column()
|
|
declare rubisEarned: number
|
|
@column()
|
|
declare status: 'pending' | 'awaiting_user_confirmation' | 'in_relance' | 'paid' | 'litigation' | 'cancelled'
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class OrganizationSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'id', 'monthlyVolumeBucket', 'name', 'onboardingCompletedAt', 'rubisCount', 'siret', 'updatedAt'] as const
|
|
$columns = OrganizationSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare monthlyVolumeBucket: string | null
|
|
@column()
|
|
declare name: string
|
|
@column.dateTime()
|
|
declare onboardingCompletedAt: DateTime | null
|
|
@column()
|
|
declare rubisCount: number
|
|
@column()
|
|
declare siret: string | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class PlanStepSchema extends BaseModel {
|
|
static $columns = ['body', 'createdAt', 'id', 'offsetDays', 'order', 'planId', 'requiresManualValidation', 'subject', 'tone', 'updatedAt'] as const
|
|
$columns = PlanStepSchema.$columns
|
|
@column()
|
|
declare body: string
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare offsetDays: number
|
|
@column()
|
|
declare order: number
|
|
@column()
|
|
declare planId: string
|
|
@column()
|
|
declare requiresManualValidation: boolean
|
|
@column()
|
|
declare subject: string
|
|
@column()
|
|
declare tone: 'amical' | 'courtois' | 'ferme' | 'mise_en_demeure'
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class PlanSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'description', 'id', 'isDefault', 'name', 'organizationId', 'slug', 'updatedAt'] as const
|
|
$columns = PlanSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column()
|
|
declare description: string
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare isDefault: boolean
|
|
@column()
|
|
declare name: string
|
|
@column()
|
|
declare organizationId: string
|
|
@column()
|
|
declare slug: string | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|
|
|
|
export class RefreshTokenSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'expiresAt', 'hashedToken', 'id', 'ipAddress', 'lastUsedAt', 'revokedAt', 'updatedAt', 'userAgent', 'userId'] as const
|
|
$columns = RefreshTokenSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column.dateTime()
|
|
declare expiresAt: DateTime
|
|
@column()
|
|
declare hashedToken: string
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare ipAddress: string | null
|
|
@column.dateTime()
|
|
declare lastUsedAt: DateTime | null
|
|
@column.dateTime()
|
|
declare revokedAt: DateTime | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
@column()
|
|
declare userAgent: string | null
|
|
@column()
|
|
declare userId: string
|
|
}
|
|
|
|
export class UserSchema extends BaseModel {
|
|
static $columns = ['createdAt', 'email', 'fullName', 'id', 'organizationId', 'password', 'signature', 'updatedAt'] as const
|
|
$columns = UserSchema.$columns
|
|
@column.dateTime({ autoCreate: true })
|
|
declare createdAt: DateTime
|
|
@column()
|
|
declare email: string
|
|
@column()
|
|
declare fullName: string | null
|
|
@column({ isPrimary: true })
|
|
declare id: string
|
|
@column()
|
|
declare organizationId: string | null
|
|
@column({ serializeAs: null })
|
|
declare password: string
|
|
@column()
|
|
declare signature: string | null
|
|
@column.dateTime({ autoCreate: true, autoUpdate: true })
|
|
declare updatedAt: DateTime | null
|
|
}
|