-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 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 }); | ||
} | ||
|
||
const updatedWrittenBy = Array.isArray(writtenBy) | ||
? writtenBy.filter(writer => writer !== memberEmail) | ||
: []; | ||
|
||
await client.mutation(api.files.updateRead, { _id: fileId, writtenBy:updatedWrittenBy }); | ||
|
||
return new Response("Changed to Public!!", { status: 200 }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters