Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create file api #374

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions convex/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const createFile = mutation({
document,
whiteboard,
private: false,
read:true,
write:false,
writtenBy:[createdBy],
readBy:[createdBy]
});
return result;
},
Expand Down Expand Up @@ -189,11 +193,11 @@ export const updateWrite = mutation({
export const updateRead = mutation({
args: {
_id: v.id("files"),
writtenBy: v.array(v.string())
readBy: v.array(v.string())
},
handler: async (ctx, args) => {
const { _id,writtenBy } = args;
const res = await ctx.db.patch(_id, { writtenBy, write:false, read:true });
const { _id,readBy } = args;
const res = await ctx.db.patch(_id, { readBy, write:false, read:true });
return res;
},
});
1 change: 1 addition & 0 deletions convex/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineSchema({
whiteboard: v.string(),
private: v.string(),
writtenBy: v.array(v.string()),
readBy: v.array(v.string()),
write:v.boolean(),
read:v.boolean()
}),
Expand Down
8 changes: 4 additions & 4 deletions src/app/api/files/read/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConvexHttpClient } from "convex/browser";

export const PUT = async (req: Request) => {
try {
const { teamId, email, memberEmail, writtenBy, fileId } = await req.json();
const { teamId, email, memberEmail, readBy, fileId } = await req.json();

if (!teamId || !memberEmail || !email || !fileId)
return new Response("Parameters missing!!", { status: 401 });
Expand All @@ -20,11 +20,11 @@ export const PUT = async (req: Request) => {
return new Response("Only owner can make changes!!", { status: 400 });
}

const updatedWrittenBy = Array.isArray(writtenBy)
? writtenBy.filter(writer => writer !== memberEmail)
const updatedReadBy = Array.isArray(readBy)
? readBy.filter(writer => writer !== memberEmail)
: [];

await client.mutation(api.files.updateRead, { _id: fileId, writtenBy:updatedWrittenBy });
await client.mutation(api.files.updateRead, { _id: fileId, readBy:updatedReadBy });

return new Response("Changed to Public!!", { status: 200 });
} catch (err) {
Expand Down
6 changes: 5 additions & 1 deletion src/components/shared/MemberModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar";
import { useSelector } from "react-redux";
import { RootState } from "@/app/store";
import { FileListContext } from "@/app/_context/FilesListContext";
import { useState,useContext,useEffect } from "react";

type Props = {
image: string;
Expand Down Expand Up @@ -54,7 +56,9 @@ export default function MemberModal({
<span className=" font-bold">{teamName}</span>
</DialogDescription>
</DialogHeader>
<h1>File Access : </h1>



<DialogFooter className=" text-gray-500">Email : {email}</DialogFooter>
</DialogContent>
</Dialog>
Expand Down
Loading