Skip to content
Open
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
8 changes: 4 additions & 4 deletions apps/backend/controllers/library.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const addAlbum: RequestHandler = async (req: Request<object, object, NewA

type AlbumQueryParams = {
artist_name?: string;
album_title?: string;
album_name?: string;
code_letters?: string;
code_artist_number?: string;
code_number?: number;
Expand All @@ -95,20 +95,20 @@ export const searchForAlbum: RequestHandler = async (
const { query } = req;
if (
query.artist_name === undefined &&
query.album_title === undefined &&
query.album_name === undefined &&
(query.code_letters === undefined || query.code_artist_number === undefined)
) {
res.status(400);
res.send(
'Missing query parameter. Query must include: artist_name, album_title, or code_letters, code_artist_number, and code_number'
'Missing query parameter. Query must include: artist_name, album_name, or code_letters, code_artist_number, and code_number'
);
} else if (query.code_letters !== undefined && query.code_artist_number !== undefined) {
//quickly look up albums by that artist
res.status(501);
res.send('TODO: Library Code Lookup');
} else {
try {
const response = await libraryService.fuzzySearchLibrary(query.artist_name, query.album_title, query.n);
const response = await libraryService.fuzzySearchLibrary(query.artist_name, query.album_name, query.n);
res.status(200).json(response);
} catch (e) {
console.error("Error: Couldn't get album");
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/library.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Library Catalog', () => {
});

test('searches by album title', async () => {
const res = await auth.get('/library').query({ album_title: 'Keep it Like a Secret' }).expect(200);
const res = await auth.get('/library').query({ album_name: 'Keep it Like a Secret' }).expect(200);

expectArray(res);
expect(res.body.length).toBeGreaterThan(0);
Expand All @@ -43,7 +43,7 @@ describe('Library Catalog', () => {
test('searches by both artist and album', async () => {
const res = await auth
.get('/library')
.query({ artist_name: 'Built to Spill', album_title: 'Keep it' })
.query({ artist_name: 'Built to Spill', album_name: 'Keep it' })
.expect(200);

expectArray(res);
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/library_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ exports.getAlbumInfo = async (album_id, access_token) => {
*
* @param {object} searchParams - Search parameters
* @param {string} [searchParams.artist_name] - Artist name
* @param {string} [searchParams.album_title] - Album title
* @param {string} [searchParams.album_name] - Album name
* @param {number} [searchParams.n] - Number of results
* @param {string} access_token - Authorization token
* @returns {Promise<object>} Search results
*/
exports.searchLibrary = async (searchParams, access_token) => {
const params = new URLSearchParams();
if (searchParams.artist_name) params.append('artist_name', searchParams.artist_name);
if (searchParams.album_title) params.append('album_title', searchParams.album_title);
if (searchParams.album_name) params.append('album_name', searchParams.album_name);
if (searchParams.n) params.append('n', searchParams.n.toString());

const res = await fetch(`${url}/library?${params.toString()}`, {
Expand Down
Loading