Skip to content

Commit

Permalink
create block service function
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-maker committed Dec 18, 2023
1 parent 6e8ee54 commit 88e477b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/block-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getSelf } from "./auth-service";
import { db } from "./db";

export const isBlockedByUser = async (id: string) => {
try {
const self = await getSelf();

const otherUser = await db.user.findUnique({
where: {
id,
},
});

if (!otherUser) {
throw new Error("User not found");
}

if (otherUser.id === self.id) {
return false;
}

const existingBlock = await db.block.findUnique({
where: {
blockerId_blockedId: {
blockerId: otherUser.id,
blockedId: self.id,
},
},
});

return !!existingBlock;
} catch {
return false;
}
};

0 comments on commit 88e477b

Please sign in to comment.