Skip to content

Commit

Permalink
Merge branch 'subhadeeproy3902:main' into feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mahek0620 authored Jun 30, 2024
2 parents 1a0436e + 729a929 commit 0ae0e9a
Show file tree
Hide file tree
Showing 22 changed files with 699 additions and 110 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ NEXT_PUBLIC_EMAILJS_TEMPLATE_ID=your_id
NEXT_PUBLIC_EMAILJS_API_KEY=your_id
NEXT_PUBLIC_EMAILJS_SERVICE_ID=your_id
RESEND_API_KEY=your_api_key
NEXT_PUBLIC_CLIENT_URL=http://localhost:3000
#use these variables only ;)
54 changes: 32 additions & 22 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 @@ -154,40 +158,46 @@ export const getPrivateFiles = query({

export const changeToPrivate = mutation({
args: {
_id: v.id("files"),
teamId: v.id("teams"),
email: v.string(),
_id: v.id("files")
},
handler: async (ctx, args) => {
const { _id, email, teamId } = args;

const teamInfo = await await ctx.db.get(teamId);

if (teamInfo.createdBy === email) {
return { status: 401 };
}

const { _id } = args;
const res = await ctx.db.patch(_id, { private: true });
return res;
},
});

export const changeToPublic = mutation({
args: {
_id: v.id("files"),
teamId: v.id("teams"),
email: v.string(),
_id: v.id("files")
},
handler: async (ctx, args) => {
const { _id, email, teamId } = args;

const teamInfo = await await ctx.db.get(teamId);

if (teamInfo.createdBy === email) {
return { status: 401 };
}

const { _id } = args;
const res = await ctx.db.patch(_id, { private: false });
return res;
},
});

export const updateWrite = mutation({
args: {
_id: v.id("files"),
writtenBy: v.array(v.string())
},
handler: async (ctx, args) => {
const { _id,writtenBy } = args;
const res = await ctx.db.patch(_id, { writtenBy, write:true, read:true });
return res;
},
});

export const updateRead = mutation({
args: {
_id: v.id("files"),
readBy: v.array(v.string())
},
handler: async (ctx, args) => {
const { _id,readBy } = args;
const res = await ctx.db.patch(_id, { readBy, write:false, read:true });
return res;
},
});
6 changes: 4 additions & 2 deletions convex/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { v } from "convex/values";

export default defineSchema({
teams: defineTable({

teamName: v.string(),
createdBy: v.string(),
teamMembers: v.array(v.string()),
Expand All @@ -21,6 +20,9 @@ export default defineSchema({
document: v.string(),
whiteboard: v.string(),
private: v.string(),
accessedBy: v.array(v.string())
writtenBy: v.array(v.string()),
readBy: v.array(v.string()),
write:v.boolean(),
read:v.boolean()
}),
});
21 changes: 19 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,22 @@ export default withPWAConfig({
hostname: '*',
}
]
}
});
},
webpack: (config, { isServer }) => {
// If it's a server build, exclude the `.node` file from bundling
if (isServer) {
config.externals = config.externals || [];
config.externals.push({
'@resvg/resvg-js-darwin-arm64/resvgjs.darwin-arm64.node': 'commonjs2 @resvg/resvg-js-darwin-arm64/resvgjs.darwin-arm64.node',
});
}

// Use node-loader for .node files
config.module.rules.push({
test: /\.node$/,
use: 'node-loader',
});

return config;
},
});
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@react-three/fiber": "^8.16.6",
"@reduxjs/toolkit": "^2.2.4",
"@studio-freight/lenis": "^1.0.42",
"axios": "^1.7.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"convex": "^1.11.3",
Expand All @@ -53,6 +54,8 @@
"embla-carousel-react": "^8.0.4",
"express": "^4.19.2",
"framer-motion": "^11.1.9",
"html2canvas": "^1.4.1",
"jspdf": "^2.5.1",
"langchain": "^0.2.4",
"lucide-react": "^0.378.0",
"moment": "^2.30.1",
Expand All @@ -70,6 +73,7 @@
"resend": "^3.3.0",
"sharp": "^0.33.3",
"sonner": "^1.5.0",
"svg2img": "^1.0.0-beta.2",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"three": "^0.164.1",
Expand All @@ -84,6 +88,7 @@
"editorjs-inline-image": "^2.1.1",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.3",
"node-loader": "^2.0.0",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5"
Expand Down
25 changes: 25 additions & 0 deletions src/app/api/files/private/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { api } from "../../../../../convex/_generated/api";
import { ConvexHttpClient } from "convex/browser";

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

console.log(teamId,email,fileId)

if (!teamId || !email || !fileId) return new Response('Parameters missing!!',{status: 401});

const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

const teamInfo = await client.query(api.teams.getTeamById,{_id:teamId});

if (teamInfo.createdBy !== email) return new Response('Only owner can make changes!!',{status: 400});


await client.mutation(api.files.changeToPrivate,{_id:fileId});

return new Response('Changed to Private!!',{status: 200});
} catch (err) {
console.log(err)
}
}
24 changes: 24 additions & 0 deletions src/app/api/files/public/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { api } from "../../../../../convex/_generated/api";
import { ConvexHttpClient } from "convex/browser";

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

if (!teamId || !email || !fileId) return new Response('Parameters missing!!',{status: 401});

const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

const teamInfo = await client.query(api.teams.getTeamById,{_id:teamId})

if (teamInfo.createdBy !== email) {
return new Response('Only owner can make changes!!',{status: 400});
}

await client.mutation(api.files.changeToPublic,{_id:fileId});

return new Response('Changed to Public!!',{status: 200});
} catch (err) {
console.log(err)
}
}
33 changes: 33 additions & 0 deletions src/app/api/files/read/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { api } from "../../../../../convex/_generated/api";
import { ConvexHttpClient } from "convex/browser";

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

if (!teamId || !memberEmail || !email || !fileId)
return new Response("Parameters missing!!", { status: 401 });

const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

const teamInfo = await client.query(api.teams.getTeamById, { _id: teamId });

if (!teamInfo.teamMembers.includes(memberEmail)) {
return new Response("User is not member of the team", { status: 400 });
}

if (teamInfo.createdBy !== email) {
return new Response("Only owner can make changes!!", { status: 400 });
}

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

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

return new Response("Changed to Public!!", { status: 200 });
} catch (err) {
console.log(err);
}
};
29 changes: 29 additions & 0 deletions src/app/api/files/write/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { api } from "../../../../../convex/_generated/api";
import { ConvexHttpClient } from "convex/browser";

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

if (!teamId || !memberEmail || !email || !fileId)
return new Response("Parameters missing!!", { status: 401 });

const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

const teamInfo = await client.query(api.teams.getTeamById, { _id: teamId });

if (!teamInfo.teamMembers.includes(memberEmail)) {
return new Response("User is not member of the team", { status: 400 });
}

if (teamInfo.createdBy !== email) {
return new Response("Only owner can make changes!!", { status: 400 });
}

await client.mutation(api.files.updateWrite, { _id: fileId, writtenBy: [...writtenBy,memberEmail] });

return new Response("Changed to Public!!", { status: 200 });
} catch (err) {
console.log(err);
}
};
16 changes: 16 additions & 0 deletions src/app/api/teams/get/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { NextResponse } from "next/server";
import { api } from "../../../../../convex/_generated/api";
import { ConvexHttpClient } from "convex/browser";

export const GET = async () => {
try {

const client = new ConvexHttpClient(process.env.NEXT_PUBLIC_CONVEX_URL!);

const teamInfo = await client.query(api.teams.getAllTeam);

return NextResponse.json(teamInfo);
} catch (err) {
console.log(err)
}
};
Loading

0 comments on commit 0ae0e9a

Please sign in to comment.