improved typesafety

This commit is contained in:
Daniel
2023-05-27 07:41:29 +03:30
parent 7f3d93517d
commit f26ffa7323
12 changed files with 321 additions and 535 deletions
@@ -4,10 +4,13 @@
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
import { prisma } from "@/lib/api/db";
import { NewCollection } from "@/types/global";
import { CollectionIncludingMembers } from "@/types/global";
import { existsSync, mkdirSync } from "fs";
export default async function (collection: NewCollection, userId: number) {
export default async function (
collection: CollectionIncludingMembers,
userId: number
) {
if (!collection || collection.name.trim() === "")
return {
response: "Please enter a valid collection.",
@@ -43,7 +46,7 @@ export default async function (collection: NewCollection, userId: number) {
description: collection.description,
members: {
create: collection.members.map((e) => ({
user: { connect: { email: e.email } },
user: { connect: { email: e.user.email } },
canCreate: e.canCreate,
canUpdate: e.canUpdate,
canDelete: e.canDelete,
@@ -4,11 +4,14 @@
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
import { prisma } from "@/lib/api/db";
import { ExtendedCollection } from "@/types/global";
import { CollectionIncludingMembers } from "@/types/global";
import getPermission from "@/lib/api/getPermission";
export default async function (collection: ExtendedCollection, userId: number) {
if (!collection)
export default async function (
collection: CollectionIncludingMembers,
userId: number
) {
if (!collection.id)
return { response: "Please choose a valid collection.", status: 401 };
const collectionIsAccessible = await getPermission(userId, collection.id);