36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { AdPlatform } from '@life-platform/shared';
|
|
import { WebhookSignatureGuard } from './guards/webhook-signature.guard';
|
|
import { TrystBoostWebhookDto } from './dto/tryst-boost-webhook.dto';
|
|
import { AdCheckInsService } from './ad-checkins.service';
|
|
|
|
@ApiTags('Escort Webhooks')
|
|
@Controller('escort/webhooks')
|
|
export class TrystBoostWebhookController {
|
|
constructor(private readonly adCheckInsService: AdCheckInsService) {}
|
|
|
|
@Post('tryst-boost')
|
|
@UseGuards(WebhookSignatureGuard)
|
|
async handleTrystBoostRefreshed(@Body() dto: TrystBoostWebhookDto) {
|
|
const checkedInAt = dto.cycle.reactivatedAt;
|
|
|
|
const notes = [
|
|
`Cycle #${dto.cycle.number}: ${dto.cycle.action}`,
|
|
`Boost active: ${dto.boost.active}, expires: ${dto.boost.expiresAt}`,
|
|
`Next refresh: ${dto.boost.nextRefreshAt}`,
|
|
dto.extension ? `Extension: ${dto.extension.name} v${dto.extension.version}` : null,
|
|
]
|
|
.filter(Boolean)
|
|
.join(' | ');
|
|
|
|
const entry = await this.adCheckInsService.createEntry({
|
|
platform: AdPlatform.Tryst,
|
|
checkedInAt,
|
|
notes,
|
|
showOnCalendar: false,
|
|
});
|
|
|
|
return { logged: true, checkinId: entry.id };
|
|
}
|
|
}
|