Skip to content

Commit f52b2a9

Browse files
committed
feat: add optional parameter channelName to grabReddit method
1 parent ec6ef16 commit f52b2a9

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

apps/aigency-backend/src/grabbers/reddit/reddit.controller.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import { AllRpcExceptionsFilter } from 'src/common/all-rpc-exceptions.filter';
1111
export class RedditController {
1212
constructor(private redditService: RedditService) {}
1313

14-
@ZodToOpenRPC({ params: z.object({}) })
15-
public grabReddits() {
16-
return this.redditService.grabReddits();
14+
@ZodToOpenRPC({
15+
params: z.object({
16+
channelName: z.string().optional(),
17+
}),
18+
})
19+
public grabReddits(params: { channelName?: string }) {
20+
return this.redditService.grabReddits(params.channelName);
1721
}
1822
}

apps/aigency-backend/src/grabbers/reddit/reddit.service.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class RedditService {
9090
}
9191
}
9292

93-
async grabReddits() {
93+
async grabReddits(channelName?: string) {
9494
try {
9595
const activeSubscriptions =
9696
await this.subscriptionService.getSubscriptions({
@@ -99,22 +99,25 @@ export class RedditService {
9999
offset: 0,
100100
onlyActive: true,
101101
});
102-
if (!activeSubscriptions || !activeSubscriptions.total) return;
102+
if (!channelName && (!activeSubscriptions || !activeSubscriptions.total))
103+
return;
103104

104105
const usersWithActiveFinders =
105106
await this.finderService.getActiveFinders();
106107

107-
const uniqueReddits = Array.from(
108-
new Set(
109-
activeSubscriptions.items
110-
.filter(
111-
(item) =>
112-
!item.isByFinder ||
113-
usersWithActiveFinders.includes(item.userId),
114-
)
115-
.map((sub) => sub.link),
116-
),
117-
);
108+
const uniqueReddits = channelName
109+
? [channelName]
110+
: Array.from(
111+
new Set(
112+
activeSubscriptions.items
113+
.filter(
114+
(item) =>
115+
!item.isByFinder ||
116+
usersWithActiveFinders.includes(item.userId),
117+
)
118+
.map((sub) => sub.link),
119+
),
120+
);
118121
// console.log('uniqueReddits', uniqueReddits);
119122

120123
const submissionXmls = await Promise.allSettled(

apps/aigency-backend/src/subscription/subscription.service.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ export class SubscriptionService {
6262

6363
// ToDo: hardcoded subscription checks. Move to service?
6464
let channelName: string | null | undefined = null;
65+
let messages: any[] | null | undefined = null;
6566
if (source === 'telegram') {
66-
const messages =
67-
await this.telegramService.getTelegramChannelMessages(link);
68-
console.log(messages);
69-
if (messages?.length) channelName = messages[0].source;
67+
messages = await this.telegramService.getTelegramChannelMessages(link);
68+
// console.log(messages);
69+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
70+
if (messages?.length) channelName = messages[0].source!;
7071
} else if (source === 'reddit') {
71-
const messages = await this.redditService.getRedditChannelMessages(link);
72-
console.log(messages);
72+
messages = await this.redditService.getRedditChannelMessages(link);
73+
// console.log(messages);
7374
if (messages?.length) {
74-
channelName = messages[0].category._attributes.label;
75+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
76+
channelName = messages[0].category._attributes.label!;
7577
}
7678
}
7779

@@ -94,6 +96,7 @@ export class SubscriptionService {
9496
lastSeenPostTimestamp: subscription.lastSeenPostTimestamp,
9597
isByFinder: subscription.isByFinder,
9698
evaluations: subscription.evaluations,
99+
messages,
97100
};
98101
}
99102

0 commit comments

Comments
 (0)