Skip to content

Commit

Permalink
Added bookmark listing notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Herrera authored and Ashley Herrera committed Nov 10, 2024
1 parent 17a8c12 commit 751abc7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/services/PostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import { CreatePostRequest, FilterPostsRequest, FilterPostsByPriceRequest, GetSe
import { uploadImage } from '../utils/Requests';
import { getLoadedModel } from '../utils/SentenceEncoder';
import { PostRepository } from 'src/repositories/PostRepository';
import { FindTokensRequest } from '../types';
import { NotifService } from './NotifService';
require('@tensorflow-models/universal-sentence-encoder')

@Service()
export class PostService {
private transactions: TransactionsManager;

constructor(@InjectManager() entityManager: EntityManager) {
this.transactions = new TransactionsManager(entityManager);
}
Expand Down Expand Up @@ -232,6 +234,17 @@ export class PostService {
if (!post) throw new NotFoundError('Post not found!');
if (post.user.isActive == false) throw new NotFoundError('User is not active!');
const userRepository = Repositories.user(transactionalEntityManager);
const postOwner = await userRepository.getUserById(post.user.id);
if (!postOwner) throw new NotFoundError('Post owner not found!');
const bookmarkNotifRequest: FindTokensRequest =
{
email: postOwner.email,
title: "Bookmark Listing Notification",
body: user.username + " bookmarked your listing!",
data: {} as JSON
}
const notifService = new NotifService(transactionalEntityManager);
await notifService.sendNotifs(bookmarkNotifRequest);
return await userRepository.savePost(user, post);
});
}
Expand Down

0 comments on commit 751abc7

Please sign in to comment.