Skip to content

Commit

Permalink
backend: change edition to book 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 dc65a2c commit 1efad4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend/docs/api/v0/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Example query: `host/api/v0/bookstatus?user_id=a1b2c3d4...`

Method: `POST`

You must supply `user_id`, `edition_id`, and `status` enum in the body. (Not the search queries!)
You must supply `user_id`, `book_id`, and `status` enum in the body. (Not the search queries!)
14 changes: 7 additions & 7 deletions backend/src/app/api/v0/bookstatus/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ function bookStatusPermissions(user_id: string) {

async function createBookStatus({
user_id,
edition_id,
book_id,
status,
}: {
user_id: string;
edition_id: string;
book_id: string;
status: BookStatus_Status;
}) {
let res = await databases.createDocument(
Expand All @@ -41,7 +41,7 @@ async function createBookStatus({
ID.unique(),
{
user_id,
edition_id,
book_id,
status,
},
bookStatusPermissions,
Expand Down Expand Up @@ -73,10 +73,10 @@ export async function GET(request: NextRequest) {
export async function POST(request: NextRequest) {
const data = await request.json();
const user_id = data.user_id;
const edition_id = data.edition_id;
const book_id = data.book_id;
const status = data.status;

if (!user_id || !edition_id || status) {
if (!user_id || !book_id || status) {
return NextResponse.json(
{ message: `Parameters not supplied.` },
{ status: 400 },
Expand All @@ -85,12 +85,12 @@ export async function POST(request: NextRequest) {

let db_query = await databases.listDocuments(MAIN_DB_ID, BOOK_STAT_COL_ID, [
Query.equal("user_id", user_id),
Query.equal("edition_id", edition_id),
Query.equal("book_id", book_id),
]);

if (db_query.total == 0) {
// Create new object
createBookStatus({ user_id, edition_id, status });
createBookStatus({ user_id, book_id, status });
} else {
const book_status_id = db_query.documents[0].$id;

Expand Down

0 comments on commit 1efad4b

Please sign in to comment.