fix: the annoucmet feth based on the user of business
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
export interface ISendAnnouncement {
|
||||
announcementId: string;
|
||||
businessId: string;
|
||||
isPublic: boolean;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Logger } from "@nestjs/common";
|
||||
import { Job } from "bullmq";
|
||||
|
||||
import { WorkerProcessor } from "../../../common/queues/worker.processor";
|
||||
import { Business } from "../../businesses/entities/business.entity";
|
||||
import { IAnnouncementNotificationData } from "../../notifications/interfaces/ISendNotificationData";
|
||||
import { NotificationQueue } from "../../notifications/queue/notification.queue";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
@@ -39,15 +40,23 @@ export class AnnouncementProcessor extends WorkerProcessor {
|
||||
private async sendAnnouncement(job: Job<ISendAnnouncement>, token?: string) {
|
||||
this.logger.log(`Sending announcement: ${job.data.announcementId} to users. ${token}`);
|
||||
|
||||
const businessId = job.data.businessId;
|
||||
|
||||
const em = this.em.fork();
|
||||
|
||||
const data = job.data;
|
||||
|
||||
try {
|
||||
await em.begin();
|
||||
const business = await em.findOne(Business, { id: businessId });
|
||||
if (!business) throw new Error("Business not found");
|
||||
|
||||
// Create a query builder to fetch unique users
|
||||
const userQueryBuilder = em.createQueryBuilder(User, "u");
|
||||
userQueryBuilder.select("u.id").distinct();
|
||||
userQueryBuilder
|
||||
.select("u.id")
|
||||
.distinct()
|
||||
.where({ business: { id: businessId } });
|
||||
|
||||
// Execute the query to get distinct user IDs
|
||||
const userResult = await userQueryBuilder.execute();
|
||||
|
||||
Reference in New Issue
Block a user