feat(sync): implement sync stubs with env-var gating and status endpoint
This commit is contained in:
@@ -16,6 +16,17 @@ export class SyncController {
|
|||||||
return { synced: logs.length, logs };
|
return { synced: logs.length, logs };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('status')
|
||||||
|
@RequirePermission('sync:read')
|
||||||
|
async getStatus() {
|
||||||
|
const lastDingTalk = await this.syncService.getLastSync('dingtalk');
|
||||||
|
const lastWeCom = await this.syncService.getLastSync('wecom');
|
||||||
|
return {
|
||||||
|
dingTalk: lastDingTalk ? { lastSyncAt: lastDingTalk.finishedAt, status: lastDingTalk.status } : null,
|
||||||
|
weCom: lastWeCom ? { lastSyncAt: lastWeCom.finishedAt, status: lastWeCom.status } : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Get('logs')
|
@Get('logs')
|
||||||
@RequirePermission('sync:read')
|
@RequirePermission('sync:read')
|
||||||
async getLogs(
|
async getLogs(
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ export class SyncService {
|
|||||||
return this.syncLogRepo.find({ where, order: { createdAt: 'DESC' }, take: limit });
|
return this.syncLogRepo.find({ where, order: { createdAt: 'DESC' }, take: limit });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getLastSync(platform: SyncPlatform): Promise<SyncLog | null> {
|
||||||
|
return this.syncLogRepo.findOne({
|
||||||
|
where: { platform },
|
||||||
|
order: { createdAt: 'DESC' },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ── Private helpers ──
|
// ── Private helpers ──
|
||||||
|
|
||||||
private async determineSyncType(platform: SyncPlatform): Promise<SyncType> {
|
private async determineSyncType(platform: SyncPlatform): Promise<SyncType> {
|
||||||
@@ -145,20 +152,28 @@ export class SyncService {
|
|||||||
* Pass `lastSyncAt` to the DingTalk API for incremental sync.
|
* Pass `lastSyncAt` to the DingTalk API for incremental sync.
|
||||||
*/
|
*/
|
||||||
private async performDingTalkSync(_lastSyncAt: Date | null): Promise<number> {
|
private async performDingTalkSync(_lastSyncAt: Date | null): Promise<number> {
|
||||||
// TODO: Call DingTalk API — e.g. attendance records, user list, etc.
|
const appKey = process.env.DINGTALK_APP_KEY;
|
||||||
// const records = await this.dingTalkClient.fetchAttendance({ updatedAfter: lastSyncAt });
|
if (!appKey) {
|
||||||
// return records.length;
|
this.logger.warn('DingTalk not configured (DINGTALK_APP_KEY missing), skipping sync');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.warn(
|
||||||
|
'DingTalk integration service not yet implemented — add DingTalkService to SyncModule to enable real sync',
|
||||||
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform the actual WeCom data pull.
|
|
||||||
* Pass `lastSyncAt` to the WeCom API for incremental sync.
|
|
||||||
*/
|
|
||||||
private async performWeComSync(_lastSyncAt: Date | null): Promise<number> {
|
private async performWeComSync(_lastSyncAt: Date | null): Promise<number> {
|
||||||
// TODO: Call WeCom API — e.g. contacts, attendance, etc.
|
const corpId = process.env.WECOM_CORP_ID;
|
||||||
// const records = await this.weComClient.fetchContacts({ updatedAfter: lastSyncAt });
|
if (!corpId) {
|
||||||
// return records.length;
|
this.logger.warn('WeCom not configured (WECOM_CORP_ID missing), skipping sync');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.warn(
|
||||||
|
'WeCom integration service not yet implemented — add WeComService to SyncModule to enable real sync',
|
||||||
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user