push notification

fix implemented
This commit is contained in:
dimitar committed 2026-02-22 04:00:20 +01:00
1 parent 0bbf2ab56f
commit 57864e00da
15 files changed
+5126 -26

No files matched your search

+13 -1
View File
@@ -49,11 +49,15 @@ export class PushService implements OnModuleInit {
}
async subscribe(dto: SubscribeDto): Promise<PushSubscriptionEntity> {
this.logger.log('Subscribing push notification...');
this.logger.debug(`Endpoint: ${dto.endpoint?.substring(0, 50)}...`);
const existing = await this.subscriptionRepo.findOne({
where: { endpoint: dto.endpoint },
});
if (existing) {
this.logger.log('Subscription already exists, updating...');
if (dto.userId && existing.userId !== dto.userId) {
existing.userId = dto.userId;
return this.subscriptionRepo.save(existing);
@@ -61,6 +65,7 @@ export class PushService implements OnModuleInit {
return existing;
}
this.logger.log('Creating new subscription...');
const subscription = this.subscriptionRepo.create({
endpoint: dto.endpoint,
p256dh: dto.p256dh,
@@ -68,7 +73,9 @@ export class PushService implements OnModuleInit {
userId: dto.userId ?? null,
});
return this.subscriptionRepo.save(subscription);
const saved = await this.subscriptionRepo.save(subscription);
this.logger.log(`Subscription saved with ID: ${saved.id}`);
return saved;
}
async unsubscribe(dto: UnsubscribeDto): Promise<void> {
@@ -170,4 +177,9 @@ export class PushService implements OnModuleInit {
tag: `live-blog-${blogSlug}`,
});
}
async getStats(): Promise<{ totalSubscribers: number }> {
const totalSubscribers = await this.subscriptionRepo.count();
return { totalSubscribers };
}
}