39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { RequirePermission } from '../auth/decorators/permission.decorator';
|
|
import { SyncService } from './sync.service';
|
|
import type { SyncPlatform } from '../entities/sync-log.entity';
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('sync')
|
|
export class SyncController {
|
|
constructor(private readonly syncService: SyncService) {}
|
|
|
|
@Post('trigger')
|
|
@RequirePermission('sync:trigger')
|
|
async triggerSync(@Query('platform') platform?: SyncPlatform) {
|
|
const logs = await this.syncService.triggerSync(platform);
|
|
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')
|
|
@RequirePermission('sync:read')
|
|
async getLogs(
|
|
@Query('platform') platform?: SyncPlatform,
|
|
@Query('limit') limit?: number,
|
|
) {
|
|
return this.syncService.getLogs(platform, limit ? Number(limit) : 50);
|
|
}
|
|
}
|