Allow collections with the same name
This commit is contained in:
@@ -12,6 +12,12 @@ export default async function getCollection(userId: number) {
|
||||
_count: {
|
||||
select: { links: true },
|
||||
},
|
||||
parent: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
members: {
|
||||
include: {
|
||||
user: {
|
||||
|
||||
@@ -32,27 +32,6 @@ export default async function postCollection(
|
||||
};
|
||||
}
|
||||
|
||||
const findCollection = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select: {
|
||||
collections: {
|
||||
where: {
|
||||
name: collection.name,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const checkIfCollectionExists = findCollection?.collections[0];
|
||||
|
||||
if (checkIfCollectionExists)
|
||||
return {
|
||||
response: "Oops! There's already a Collection with that name.",
|
||||
status: 400,
|
||||
};
|
||||
|
||||
const newCollection = await prisma.collection.create({
|
||||
data: {
|
||||
owner: {
|
||||
@@ -65,10 +44,10 @@ export default async function postCollection(
|
||||
color: collection.color,
|
||||
parent: collection.parentId
|
||||
? {
|
||||
connect: {
|
||||
id: collection.parentId,
|
||||
},
|
||||
}
|
||||
connect: {
|
||||
id: collection.parentId,
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
include: {
|
||||
|
||||
@@ -88,14 +88,11 @@ export default async function postLink(
|
||||
collection: {
|
||||
connectOrCreate: {
|
||||
where: {
|
||||
name_ownerId: {
|
||||
ownerId: link.collection.ownerId,
|
||||
name: link.collection.name,
|
||||
},
|
||||
id: link.collection.id ?? 0,
|
||||
},
|
||||
create: {
|
||||
name: link.collection.name.trim(),
|
||||
ownerId: userId,
|
||||
ownerId: userId
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user