Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

jobs:
"run-jest-tests":
runs-on: cs5500-self-hosted
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand Down
19 changes: 10 additions & 9 deletions pages/books.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import Book from '../models/book';
import Author from '../models/author';
import express from 'express';
import Book from "../models/book";
import Author from "../models/author";
import express from "express";

const router = express.Router();


const showBooks = async (): Promise<string[] | void> => {
try {
const books = await Book.getAllBooksWithAuthors('title author', {title: 1});
const books = await Book.getAllBooksWithAuthors("title author", {
title: 1,
});
return books.map((b) => {
const authorName = new Author(b.author).name; // Assuming 'Author' returns the author's name
return `${b._id} : ${b.title} : ${authorName}`;
});
} catch (err) {
console.log('Could not get books ' + err);
console.log("Could not get books " + err);
}
}
};
/**
* @route GET /books
* @returns an array of strings, where each string contains the book ID, title, and author name
* @returns - a message indicating that no books were found if an error occurs
*/
router.get('/', async (_, res) => {
router.get("/", async (_, res) => {
try {
const data = await showBooks();
res.send(data);
} catch {
res.send('No books found');
res.send("No books found");
}
});

Expand Down
Loading