- Add @nestjs/schedule dependency
- Create SyncLog entity (platform, syncType, status, recordsCount, errorMessage, timestamps)
- Create SyncState entity for tracking lastSyncAt per platform
- SyncService with @Cron('0 2 * * *') daily scheduled sync
- Incremental sync: tracks last_sync_at per platform, passes to integration APIs
- Full/incremental mode determined by existence of prior sync
- SyncController: POST /sync/trigger (manual), GET /sync/logs (history)
- Register SyncModule in AppModule with ScheduleModule
36 lines
996 B
TypeScript
36 lines
996 B
TypeScript
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn } from 'typeorm';
|
|
|
|
export type SyncPlatform = 'dingtalk' | 'wecom';
|
|
export type SyncType = 'full' | 'incremental';
|
|
export type SyncStatus = 'running' | 'success' | 'failed';
|
|
|
|
@Entity('sync_logs')
|
|
export class SyncLog {
|
|
@PrimaryGeneratedColumn()
|
|
id: number;
|
|
|
|
@Column({ type: 'varchar', length: 20 })
|
|
platform: SyncPlatform;
|
|
|
|
@Column({ name: 'sync_type', type: 'varchar', length: 20 })
|
|
syncType: SyncType;
|
|
|
|
@Column({ type: 'varchar', length: 20 })
|
|
status: SyncStatus;
|
|
|
|
@Column({ name: 'records_count', type: 'integer', default: 0 })
|
|
recordsCount: number;
|
|
|
|
@Column({ name: 'error_message', type: 'text', nullable: true })
|
|
errorMessage: string | null;
|
|
|
|
@Column({ name: 'started_at', type: 'datetime', nullable: true })
|
|
startedAt: Date | null;
|
|
|
|
@Column({ name: 'finished_at', type: 'datetime', nullable: true })
|
|
finishedAt: Date | null;
|
|
|
|
@CreateDateColumn({ name: 'created_at' })
|
|
createdAt: Date;
|
|
}
|