@@ -34,7 +34,6 @@ export const addAlbum: RequestHandler = async (req: Request<object, object, NewA
3434 ( body . artist_name === undefined && body . artist_id === undefined )
3535 ) {
3636 res . status ( 400 ) . json ( {
37- status : 400 ,
3837 message : 'Missing Parameters: album_title, label, genre_id, format_id, artist_name, or artist_id' ,
3938 } ) ;
4039 } else {
@@ -49,10 +48,10 @@ export const addAlbum: RequestHandler = async (req: Request<object, object, NewA
4948 }
5049 }
5150 if ( ! artist_id ) {
52- res . status ( 400 ) ;
53- res . send (
54- "Artist doesn't exist or hasn't released an album in this genre before. Add a new artist entry to the library"
55- ) ;
51+ res . status ( 400 ) . json ( {
52+ message :
53+ "Artist doesn't exist or hasn't released an album in this genre before. Add a new artist entry to the library" ,
54+ } ) ;
5655 } else {
5756 try {
5857 const new_album : NewAlbum = {
@@ -98,14 +97,13 @@ export const searchForAlbum: RequestHandler = async (
9897 query . album_title === undefined &&
9998 ( query . code_letters === undefined || query . code_artist_number === undefined )
10099 ) {
101- res . status ( 400 ) ;
102- res . send (
103- 'Missing query parameter. Query must include: artist_name, album_title, or code_letters, code_artist_number, and code_number'
104- ) ;
100+ res . status ( 400 ) . json ( {
101+ message :
102+ 'Missing query parameter. Query must include: artist_name, album_title, or code_letters, code_artist_number, and code_number' ,
103+ } ) ;
105104 } else if ( query . code_letters !== undefined && query . code_artist_number !== undefined ) {
106105 //quickly look up albums by that artist
107- res . status ( 501 ) ;
108- res . send ( 'TODO: Library Code Lookup' ) ;
106+ res . status ( 501 ) . json ( { message : 'TODO: Library Code Lookup' } ) ;
109107 } else {
110108 try {
111109 const response = await libraryService . fuzzySearchLibrary ( query . artist_name , query . album_title , query . n ) ;
@@ -128,8 +126,7 @@ export const addArtist: RequestHandler = async (req: Request<object, object, New
128126 const { body } = req ;
129127 //TODO auto_generate artist code letters and make it an optional parameter
130128 if ( body . artist_name === undefined || body . code_letters === undefined || body . genre_id === undefined ) {
131- res . status ( 400 ) ;
132- res . send ( 'Missing Request Parameters: artist_name, code_letters, or genre_id' ) ;
129+ res . status ( 400 ) . json ( { message : 'Missing Request Parameters: artist_name, code_letters, or genre_id' } ) ;
133130 } else {
134131 try {
135132 const generatedArtistNumber = await libraryService . generateArtistNumber ( body . code_letters , body . genre_id ) ;
@@ -166,7 +163,7 @@ export const getRotation: RequestHandler = async (req, res, next) => {
166163export type RotationAddRequest = Omit < NewRotationRelease , 'id' > ;
167164export const addRotation : RequestHandler < object , unknown , NewRotationRelease > = async ( req , res , next ) => {
168165 if ( req . body . album_id === undefined || req . body . play_freq === undefined ) {
169- res . status ( 400 ) . send ( 'Missing Parameters: album_id or play_freq' ) ;
166+ res . status ( 400 ) . json ( { message : 'Missing Parameters: album_id or play_freq' } ) ;
170167 } else {
171168 try {
172169 const rotationRelease : RotationRelease = await libraryService . addToRotation ( req . body ) ;
@@ -187,16 +184,16 @@ export const killRotation: RequestHandler<object, unknown, KillRotationRelease>
187184 const { body } = req ;
188185
189186 if ( body . rotation_id === undefined ) {
190- res . status ( 400 ) . send ( 'Bad Request, Missing Parameter: rotation_id' ) ;
187+ res . status ( 400 ) . json ( { message : 'Bad Request, Missing Parameter: rotation_id' } ) ;
191188 } else if ( body . kill_date !== undefined && ! libraryService . isISODate ( body . kill_date ) ) {
192- res . status ( 400 ) . send ( 'Bad Request, Incorrect Date Format: kill_date should be of form YYYY-MM-DD' ) ;
189+ res . status ( 400 ) . json ( { message : 'Bad Request, Incorrect Date Format: kill_date should be of form YYYY-MM-DD' } ) ;
193190 } else {
194191 try {
195192 const updatedRotation : RotationRelease = await libraryService . killRotationInDB ( body . rotation_id , body . kill_date ) ;
196193 if ( updatedRotation !== undefined ) {
197194 res . status ( 200 ) . json ( updatedRotation ) ;
198195 } else {
199- res . status ( 400 ) . json ( { status : 400 , message : 'Rotation entry not found' } ) ;
196+ res . status ( 400 ) . json ( { message : 'Rotation entry not found' } ) ;
200197 }
201198 } catch ( e ) {
202199 console . error ( 'Failed to update rotation kill_date' ) ;
@@ -220,7 +217,7 @@ export const getFormats: RequestHandler = async (req, res, next) => {
220217export const addFormat : RequestHandler = async ( req , res , next ) => {
221218 const { body } = req ;
222219 if ( body . name === undefined ) {
223- res . status ( 400 ) . send ( 'Bad Request, Missing Parameter: name' ) ;
220+ res . status ( 400 ) . json ( { message : 'Bad Request, Missing Parameter: name' } ) ;
224221 } else {
225222 try {
226223 const newFormat : NewAlbumFormat = {
@@ -245,7 +242,7 @@ export const getGenres: RequestHandler = async (req, res) => {
245242export const addGenre : RequestHandler = async ( req , res , next ) => {
246243 const { body } = req ;
247244 if ( body . name === undefined || body . description === undefined ) {
248- res . status ( 400 ) . send ( 'Bad Request, Parameters name and description are required.' ) ;
245+ res . status ( 400 ) . json ( { message : 'Bad Request, Parameters name and description are required.' } ) ;
249246 } else {
250247 try {
251248 const newGenre : NewGenre = {
@@ -271,7 +268,7 @@ export const getAlbum: RequestHandler<object, unknown, unknown, { album_id: stri
271268 const { query } = req ;
272269 if ( query . album_id === undefined ) {
273270 console . error ( 'Bad Request, missing album identifier: album_id' ) ;
274- res . status ( 400 ) . send ( 'Bad Request, missing album identifier: album_id' ) ;
271+ res . status ( 400 ) . json ( { message : 'Bad Request, missing album identifier: album_id' } ) ;
275272 } else {
276273 try {
277274 const album = await libraryService . getAlbumFromDB ( parseInt ( query . album_id ) ) ;
0 commit comments