Skip to content

Commit

Permalink
Remove queueMessage instance for follows
Browse files Browse the repository at this point in the history
  • Loading branch information
koredefashokun committed Dec 24, 2024
1 parent 56c24ca commit e3fd02f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
10 changes: 1 addition & 9 deletions api/src/collections/order/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const createOrder: Resolver<CreateOrderArgs> = async (
) => {
// Get all required data in a single query
const cart = await ctx.prisma.cart.findUnique({
where: { id: cartId },
where: { id: cartId, userId: ctx.user.id },
include: {
user: {
include: {
Expand All @@ -36,14 +36,6 @@ const createOrder: Resolver<CreateOrderArgs> = async (
throw new Error('Cart not found');
}

if (cart.userId !== ctx.user.id) {
throw new Error('You are not authorized to access this cart.');
}

if (!cart.store) {
throw new Error('Store not found');
}

const card = cart.user.cards[0];

if (!card) {
Expand Down
10 changes: 6 additions & 4 deletions api/src/collections/store-follower/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ const followStore: Resolver<FollowStoreArgs> = async (_, { storeId }, ctx) => {

for (const pushToken of pushTokens) {
if (pushToken) {
ctx.services.notifications.queueMessage({
to: pushToken,
title: `${follower.store.name} has a new follower`,
body: `${ctx.user.name} followed you`
ctx.services.notifications.queueNotification({
type: 'NEW_FOLLOW',
data: {
followerName: ctx.user.name
},
recipientTokens: [pushToken]
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions api/src/templates/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ export const notificationTemplates: Record<
ORDER_COMPLETED: {
title: 'Order Completed',
body: data => `Your order #${data.orderId} has been completed`
},
NEW_FOLLOW: {
title: 'New Store Follower',
body: data => `${data.followerName} started following your store`
}
};
3 changes: 2 additions & 1 deletion api/src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export type NotificationType =
| 'ORDER_FULFILLED'
| 'DELIVERY_CONFIRMED'
| 'ORDER_CANCELLED'
| 'ORDER_COMPLETED';
| 'ORDER_COMPLETED'
| 'NEW_FOLLOW';

export interface NotificationTemplate {
title: string;
Expand Down

0 comments on commit e3fd02f

Please sign in to comment.