Skip to content

Commit 38c9d5e

Browse files
authored
chore: queue updated (#207)
* chore: queue updated * chore: vk pixel
1 parent 84d91c5 commit 38c9d5e

13 files changed

Lines changed: 824 additions & 127 deletions

File tree

apps/atrium-telegram/server/api/ticket/id/[ticketId]/message.post.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { TicketMessageCreated } from '@roll-stack/essence'
12
import { createTicketMessageSchema } from '#shared/services/ticket'
23
import { db } from '@roll-stack/database'
3-
import { queue } from '@roll-stack/essence'
4+
import { Events, queue } from '@roll-stack/essence'
45
import { type } from 'arktype'
56

67
export default defineEventHandler(async (event) => {
@@ -39,8 +40,8 @@ export default defineEventHandler(async (event) => {
3940
})
4041
}
4142

42-
// Event
43-
await queue.ticket.messageCreated({
43+
// Push Event
44+
await queue.publish<TicketMessageCreated>(Events.ticketMessageCreated, {
4445
ticketId: message.ticketId,
4546
ticketOwnerId: ticket.userId,
4647
messageId: message.id,
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
1-
import type { NotificationUserBeaconOnEpicCommentCreated, TicketMessageCreated } from '@roll-stack/essence'
1+
import type { EventHandlerMap, NotificationUserBeaconOnEpicCommentCreated, TicketMessageCreated } from '@roll-stack/essence'
22
import { db } from '@roll-stack/database'
3-
import { queue } from '@roll-stack/essence'
3+
import { Events, queue } from '@roll-stack/essence'
44
import { useAtriumBot } from '../telegram/atrium-bot'
55
import { useWasabiBot } from '../telegram/wasabi-bot'
66

77
const { telegram } = useRuntimeConfig()
88

99
export async function setupConsumers() {
10-
return queue.telegram.consume(async (msg) => {
11-
if (msg.type === 'ticketMessageCreated') {
12-
return handleTicketMessageCreated(msg as TicketMessageCreated)
13-
}
14-
if (msg.type === 'notificationUserBeaconOnEpicCommentCreated') {
15-
return handleUserBeaconOnEpicCommentCreated(msg as NotificationUserBeaconOnEpicCommentCreated)
16-
}
17-
18-
return queue.ignore()
19-
})
10+
return queue.consume(queue.telegram.name, {
11+
[Events.ticketMessageCreated]: handleTicketMessageCreated,
12+
[Events.notificationUserBeaconOnEpicCommentCreated]: handleUserBeaconOnEpicCommentCreated,
13+
} as EventHandlerMap)
2014
}
2115

22-
async function handleTicketMessageCreated(msg: TicketMessageCreated) {
16+
async function handleTicketMessageCreated(data: TicketMessageCreated['data']): Promise<boolean> {
2317
try {
2418
// Send Telegram message to Owner user via Wasabi Bot
25-
const wasabiUser = await db.telegram.findUserByIdAndBotId(msg.data.ticketOwnerId, telegram.wasabiBotId)
19+
const wasabiUser = await db.telegram.findUserByIdAndBotId(data.ticketOwnerId, telegram.wasabiBotId)
2620
if (wasabiUser) {
27-
const text = `${msg.data.userName} ${msg.data.userSurname}: ${msg.data.userText}`
21+
const text = `${data.userName} ${data.userSurname}: ${data.userText}`
2822
await useWasabiBot().api.sendMessage(wasabiUser.telegramId, text)
2923
}
3024

31-
return queue.success()
25+
return true
3226
} catch (error) {
3327
console.error(error)
34-
return queue.fail()
28+
return false
3529
}
3630
}
3731

38-
async function handleUserBeaconOnEpicCommentCreated(msg: NotificationUserBeaconOnEpicCommentCreated) {
32+
async function handleUserBeaconOnEpicCommentCreated(data: NotificationUserBeaconOnEpicCommentCreated['data']): Promise<boolean> {
3933
try {
4034
// Send Telegram message to Atrium user
41-
const atriumUser = await db.telegram.findUserByIdAndBotId(msg.data.userId, telegram.atriumBotId)
35+
const atriumUser = await db.telegram.findUserByIdAndBotId(data.userId, telegram.atriumBotId)
4236
if (atriumUser) {
4337
const separator = 'zzzzz'
44-
const startAppData = `epic${separator}${msg.data.epicId}`
38+
const startAppData = `epic${separator}${data.epicId}`
4539

4640
await useAtriumBot()
4741
.api
4842
.sendMessage(
4943
atriumUser.telegramId,
50-
`👋 ${msg.data.senderName} ${msg.data.senderSurname}\n${msg.data.title}\n\n${msg.data.description}`,
44+
`👋 ${data.senderName} ${data.senderSurname}\n${data.title}\n\n${data.description}`,
5145
{
5246
reply_markup: {
5347
inline_keyboard: [[{
@@ -59,9 +53,9 @@ async function handleUserBeaconOnEpicCommentCreated(msg: NotificationUserBeaconO
5953
)
6054
}
6155

62-
return queue.success()
56+
return true
6357
} catch (error) {
6458
console.error(error)
65-
return queue.fail()
59+
return false
6660
}
6761
}

apps/web-app/server/api/beacon/epic/comment.post.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { NotificationUserBeaconOnEpicCommentCreated } from '@roll-stack/essence'
12
import { createBeaconSchema } from '#shared/services/notification'
23
import { db } from '@roll-stack/database'
3-
import { queue } from '@roll-stack/essence'
4+
import { Events, queue } from '@roll-stack/essence'
45
import { type } from 'arktype'
56

67
export default defineEventHandler(async (event) => {
@@ -50,8 +51,8 @@ export default defineEventHandler(async (event) => {
5051
description,
5152
})
5253

53-
// Queue
54-
await queue.notification.userBeaconOnEpicCommentCreated({
54+
// Push Event
55+
await queue.publish<NotificationUserBeaconOnEpicCommentCreated>(Events.notificationUserBeaconOnEpicCommentCreated, {
5556
userId,
5657
senderName: sender.name,
5758
senderSurname: sender.surname,

apps/web-app/server/api/ticket/id/[ticketId]/message.post.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import type { TicketMessageCreated } from '@roll-stack/essence'
12
import { createTicketMessageSchema } from '#shared/services/ticket'
23
import { db } from '@roll-stack/database'
3-
import { queue } from '@roll-stack/essence'
4+
import { Events, queue } from '@roll-stack/essence'
45
import { type } from 'arktype'
56

67
export default defineEventHandler(async (event) => {
@@ -39,8 +40,8 @@ export default defineEventHandler(async (event) => {
3940
})
4041
}
4142

42-
// Event
43-
await queue.ticket.messageCreated({
43+
// Push Event
44+
await queue.publish<TicketMessageCreated>(Events.ticketMessageCreated, {
4445
ticketId: message.ticketId,
4546
ticketOwnerId: ticket.userId,
4647
messageId: message.id,

apps/webinar/app/app.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ useHead({
2121
lang,
2222
dir,
2323
},
24+
script: [
25+
{
26+
type: 'text/javascript',
27+
src: '/vk-pixel.min.js',
28+
},
29+
],
2430
})
2531
</script>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var _tmr = window._tmr || (window._tmr = []);
2+
_tmr.push({id: "3706869", type: "pageView", start: (new Date()).getTime()});
3+
(function (d, w, id) {
4+
if (d.getElementById(id)) return;
5+
var ts = d.createElement("script"); ts.type = "text/javascript"; ts.async = true; ts.id = id;
6+
ts.src = "https://top-fwz1.mail.ru/js/code.js";
7+
var f = function () {var s = d.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ts, s);};
8+
if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); }
9+
})(document, window, "tmr-code");

packages/essence/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { repository as queue } from './queue'
22
export type * from './queue/types'
3+
export { Events } from './queue/types'
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { Repository } from '@nextorders/queue'
2-
import type { NotificationUserBeaconOnEpicCommentCreated } from '../types'
32
import { Entity } from '@nextorders/queue'
4-
import { Events } from '../types'
53

64
export class Notification extends Entity {
75
constructor(repository: Repository) {
@@ -11,18 +9,4 @@ export class Notification extends Entity {
119
repository,
1210
})
1311
}
14-
15-
async userBeaconOnEpicCommentCreated(data: NotificationUserBeaconOnEpicCommentCreated['data']): Promise<NotificationUserBeaconOnEpicCommentCreated> {
16-
const body = {
17-
type: Events.NOTIFICATION_USER_BEACON_ON_EPIC_COMMENT_CREATED,
18-
data,
19-
} as const
20-
21-
await this.repository.publisher.send({
22-
exchange: this.repository.exchanges.events.exchange,
23-
routingKey: Events.NOTIFICATION_USER_BEACON_ON_EPIC_COMMENT_CREATED,
24-
}, body)
25-
26-
return body
27-
}
2812
}

packages/essence/src/queue/entities/telegram.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class Telegram extends Entity {
77
super({
88
name: 'telegram',
99
eventsToConsume: [
10-
Events.TICKET_MESSAGE_CREATED,
11-
Events.NOTIFICATION_USER_BEACON_ON_EPIC_COMMENT_CREATED,
10+
Events.ticketMessageCreated,
11+
Events.notificationUserBeaconOnEpicCommentCreated,
1212
],
1313
repository,
1414
})
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { Repository } from '@nextorders/queue'
2-
import type { TicketMessageCreated } from './../types'
32
import { Entity } from '@nextorders/queue'
4-
import { Events } from './../types'
53

64
export class Ticket extends Entity {
75
constructor(repository: Repository) {
@@ -11,18 +9,4 @@ export class Ticket extends Entity {
119
repository,
1210
})
1311
}
14-
15-
async messageCreated(data: TicketMessageCreated['data']): Promise<TicketMessageCreated> {
16-
const body = {
17-
type: Events.TICKET_MESSAGE_CREATED,
18-
data,
19-
} as const
20-
21-
await this.repository.publisher.send({
22-
exchange: this.repository.exchanges.events.exchange,
23-
routingKey: Events.TICKET_MESSAGE_CREATED,
24-
}, body)
25-
26-
return body
27-
}
2812
}

0 commit comments

Comments
 (0)