Allow users to enable merging links

This commit is contained in:
Isaac Wise
2024-03-04 23:24:30 -06:00
parent 281b376eac
commit 750aa294d0
7 changed files with 40 additions and 4 deletions
+22
View File
@@ -87,6 +87,28 @@ export default async function postLink(
return { response: "Uncaught error.", status: 500 };
}
const user = await prisma.user.findUnique({
where: {
id: userId,
},
});
const existingLink = await prisma.link.findFirst({
where: {
url: link.url,
collection: {
ownerId: userId,
},
},
});
if (existingLink && user?.mergeDuplicateLinks) {
return {
response: "Link already exists",
status: 409,
};
}
const numberOfLinksTheUserHas = await prisma.link.count({
where: {
collection: {
@@ -190,6 +190,7 @@ export default async function updateUserById(
archiveAsPDF: data.archiveAsPDF,
archiveAsWaybackMachine: data.archiveAsWaybackMachine,
linksRouteTo: data.linksRouteTo,
mergeDuplicateLinks: data.mergeDuplicateLinks,
password:
data.newPassword && data.newPassword !== ""
? newHashedPassword