Skip to content

Commit 68509c9

Browse files
committed
feat: enhance app and template creation notifications with total counts
1 parent 74bf95a commit 68509c9

4 files changed

Lines changed: 92 additions & 16 deletions

File tree

backend/src/routes/apps.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,17 @@ export function createAppsRouter(db: Knex, notificationService: INotificationSer
141141

142142
const [insertId] = await db<App>('apps').insert(newApp)
143143

144+
// Get total count of apps for the notification
145+
const result = await db('apps').count({ count: 'id' }).first()
146+
const count = result?.count
147+
const totalApps = typeof count === 'number' ? count : Number(count)
148+
144149
// Send notification about the newly created app
145150
const appTitle = trimmedName
146151
const appDescription = truncateText(description || 'No description provided', MAX_NOTIFICATION_DESCRIPTION_LENGTH)
147152

148153
try {
149-
await notificationService.sendAppCreationNotification(appTitle, appDescription)
154+
await notificationService.sendAppCreationNotification(appTitle, appDescription, insertId, totalApps)
150155
} catch (error) {
151156
console.error('Failed to send app creation notification:', error)
152157
// Non-critical error, don't fail the request

backend/src/routes/templates.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export function createTemplatesRouter(db: Knex, notificationService: INotificati
7373
owner_address: address,
7474
})
7575

76+
// Get total count of templates for the notification
77+
const result = await db('templates').count({ count: 'id' }).first()
78+
const count = result?.count
79+
const totalTemplates = typeof count === 'number' ? count : Number(count)
80+
7681
// Send notification about the newly created template
7782
const templateTitle = templateData.title
7883
const templateDescription = truncateText(
@@ -81,7 +86,12 @@ export function createTemplatesRouter(db: Knex, notificationService: INotificati
8186
)
8287

8388
try {
84-
await notificationService.sendTemplateCreationNotification(templateTitle, templateDescription)
89+
await notificationService.sendTemplateCreationNotification(
90+
templateTitle,
91+
templateDescription,
92+
insertId,
93+
totalTemplates,
94+
)
8595
} catch (error) {
8696
console.error('Failed to send template creation notification:', error)
8797
// Non-critical error, don't fail the request

backend/src/services/notification.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ export interface INotificationService {
66
* Sends a notification about a newly created app
77
* @param {string} title - The full title of the app
88
* @param {string} description - The shortened description of the app
9+
* @param {number} appId - The ID of the newly created app
10+
* @param {number} totalApps - The total count of apps
911
* @returns {Promise<boolean>} - Whether the notification was sent successfully
1012
*/
11-
sendAppCreationNotification(title: string, description: string): Promise<boolean>
13+
sendAppCreationNotification(title: string, description: string, appId: number, totalApps: number): Promise<boolean>
1214

1315
/**
1416
* Sends a notification about a newly created template
1517
* @param {string} title - The full title of the template
1618
* @param {string} description - The shortened description of the template
19+
* @param {number} templateId - The ID of the newly created template
20+
* @param {number} totalTemplates - The total count of templates
1721
* @returns {Promise<boolean>} - Whether the notification was sent successfully
1822
*/
19-
sendTemplateCreationNotification(title: string, description: string): Promise<boolean>
23+
sendTemplateCreationNotification(
24+
title: string,
25+
description: string,
26+
templateId: number,
27+
totalTemplates: number,
28+
): Promise<boolean>
2029

2130
/**
2231
* Sends a notification about a newly registered user
@@ -57,21 +66,35 @@ export class TelegramNotificationService implements INotificationService {
5766
* Sends a notification about a newly created app
5867
* @param {string} title - The full title of the app
5968
* @param {string} description - The shortened description of the app
69+
* @param {number} appId - The ID of the newly created app
70+
* @param {number} totalApps - The total count of apps
6071
* @returns {Promise<boolean>} - Whether the notification was sent successfully
6172
*/
62-
async sendAppCreationNotification(title: string, description: string): Promise<boolean> {
63-
const message = `🆕 New App Created!\n\n📱 *${title}*\n\n${description}`
73+
async sendAppCreationNotification(
74+
title: string,
75+
description: string,
76+
appId: number,
77+
totalApps: number,
78+
): Promise<boolean> {
79+
const message = `🆕 New App Created!\n\n📱 *${title}* (ID: ${appId})\n\n${description}\n\n📊 Total Apps: *${totalApps}*`
6480
return this.sendTelegramMessage(message)
6581
}
6682

6783
/**
6884
* Sends a notification about a newly created template
6985
* @param {string} title - The full title of the template
7086
* @param {string} description - The shortened description of the template
87+
* @param {number} templateId - The ID of the newly created template
88+
* @param {number} totalTemplates - The total count of templates
7189
* @returns {Promise<boolean>} - Whether the notification was sent successfully
7290
*/
73-
async sendTemplateCreationNotification(title: string, description: string): Promise<boolean> {
74-
const message = `🆕 New Template Created!\n\n📋 *${title}*\n\n${description}`
91+
async sendTemplateCreationNotification(
92+
title: string,
93+
description: string,
94+
templateId: number,
95+
totalTemplates: number,
96+
): Promise<boolean> {
97+
const message = `🆕 New Template Created!\n\n📋 *${title}* (ID: ${templateId})\n\n${description}\n\n📊 Total Templates: *${totalTemplates}*`
7598
return this.sendTelegramMessage(message)
7699
}
77100

@@ -151,12 +174,24 @@ export function createNotificationService(): INotificationService {
151174
// If no configuration is available, use a mock service that logs to console
152175
console.warn('Telegram notification service not configured. Using console logging instead.')
153176
return {
154-
async sendAppCreationNotification(title: string, description: string): Promise<boolean> {
155-
console.log(`[NOTIFICATION] New App Created: ${title} - ${description}`)
177+
async sendAppCreationNotification(
178+
title: string,
179+
description: string,
180+
appId: number,
181+
totalApps: number,
182+
): Promise<boolean> {
183+
console.log(`[NOTIFICATION] New App Created: ${title} (ID: ${appId}) - ${description} - Total Apps: ${totalApps}`)
156184
return true
157185
},
158-
async sendTemplateCreationNotification(title: string, description: string): Promise<boolean> {
159-
console.log(`[NOTIFICATION] New Template Created: ${title} - ${description}`)
186+
async sendTemplateCreationNotification(
187+
title: string,
188+
description: string,
189+
templateId: number,
190+
totalTemplates: number,
191+
): Promise<boolean> {
192+
console.log(
193+
`[NOTIFICATION] New Template Created: ${title} (ID: ${templateId}) - ${description} - Total Templates: ${totalTemplates}`,
194+
)
160195
return true
161196
},
162197
async sendUserRegistrationNotification(address: string, totalUsers: number): Promise<boolean> {

backend/src/tests/__mocks__/notification.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export class MockNotificationService implements INotificationService {
88
type: string
99
title?: string
1010
description?: string
11+
appId?: number
12+
templateId?: number
13+
totalApps?: number
14+
totalTemplates?: number
1115
address?: string
1216
totalUsers?: number
1317
feedback?: string
@@ -18,21 +22,35 @@ export class MockNotificationService implements INotificationService {
1822
* Sends a notification about a newly created app (mock implementation)
1923
* @param {string} title - The full title of the app
2024
* @param {string} description - The shortened description of the app
25+
* @param {number} appId - The ID of the newly created app
26+
* @param {number} totalApps - The total count of apps
2127
* @returns {Promise<boolean>} - Always returns true
2228
*/
23-
async sendAppCreationNotification(title: string, description: string): Promise<boolean> {
24-
this.notificationsSent.push({ type: 'app', title, description })
29+
async sendAppCreationNotification(
30+
title: string,
31+
description: string,
32+
appId: number,
33+
totalApps: number,
34+
): Promise<boolean> {
35+
this.notificationsSent.push({ type: 'app', title, description, appId, totalApps })
2536
return true
2637
}
2738

2839
/**
2940
* Sends a notification about a newly created template (mock implementation)
3041
* @param {string} title - The full title of the template
3142
* @param {string} description - The shortened description of the template
43+
* @param {number} templateId - The ID of the newly created template
44+
* @param {number} totalTemplates - The total count of templates
3245
* @returns {Promise<boolean>} - Always returns true
3346
*/
34-
async sendTemplateCreationNotification(title: string, description: string): Promise<boolean> {
35-
this.notificationsSent.push({ type: 'template', title, description })
47+
async sendTemplateCreationNotification(
48+
title: string,
49+
description: string,
50+
templateId: number,
51+
totalTemplates: number,
52+
): Promise<boolean> {
53+
this.notificationsSent.push({ type: 'template', title, description, templateId, totalTemplates })
3654
return true
3755
}
3856

@@ -64,6 +82,10 @@ export class MockNotificationService implements INotificationService {
6482
* type: string
6583
* title?: string
6684
* description?: string
85+
* appId?: number
86+
* templateId?: number
87+
* totalApps?: number
88+
* totalTemplates?: number
6789
* address?: string
6890
* totalUsers?: number
6991
* feedback?: string
@@ -74,6 +96,10 @@ export class MockNotificationService implements INotificationService {
7496
type: string
7597
title?: string
7698
description?: string
99+
appId?: number
100+
templateId?: number
101+
totalApps?: number
102+
totalTemplates?: number
77103
address?: string
78104
totalUsers?: number
79105
feedback?: string

0 commit comments

Comments
 (0)