Skip to content

Commit

Permalink
backend: api: set permissions for book status documents
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswpark committed Feb 24, 2024
1 parent 96d3ba7 commit d7102df
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backend/src/app/api/v0/bookstatus/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sdk = require("node-appwrite");

import { NextRequest, NextResponse } from "next/server";
import { ID, Query } from "appwrite";
import { ID, Permission, Query, Role } from "appwrite";

import { client } from "@/app/appwrite";
import { construct_development_api_response } from "../dev_api_response";
Expand All @@ -18,6 +18,14 @@ enum BookStatus_Status {
DID_NOT_FINISH,
}

function bookStatusPermissions(user_id: string) {
return [
Permission.read(Role.user(user_id)),
Permission.update(Role.user(user_id)),
Permission.delete(Role.user(user_id)),
];
}

async function createBookStatus({
user_id,
edition_id,
Expand All @@ -36,6 +44,7 @@ async function createBookStatus({
edition_id,
status,
},
bookStatusPermissions,
);
return res.$id;
}
Expand Down Expand Up @@ -93,6 +102,7 @@ export async function POST(request: NextRequest) {
{
status: status,
},
bookStatusPermissions
);
}

Expand Down

0 comments on commit d7102df

Please sign in to comment.