Fix bug
This commit is contained in:
parent
78d5e7507f
commit
1d6338fd64
@ -31,7 +31,7 @@ export default {
|
||||
* mediaController.create()
|
||||
*/
|
||||
create: async function (req: Request, res: Response) {
|
||||
const mediaCode = req.body.code;
|
||||
const mediaCode: string = req.body.code;
|
||||
|
||||
const omdb_key = await UserModel.getValue(values.omdb_key);
|
||||
|
||||
@ -39,10 +39,14 @@ export default {
|
||||
return res.status(500).json({ message: 'Error when creating media' });
|
||||
}
|
||||
|
||||
// remove the tt in front in DB its stored as number
|
||||
const sub = mediaCode.substring(2);
|
||||
const cleanCode = parseInt(sub);
|
||||
|
||||
try {
|
||||
const mediaTable = req.baseUrl.includes('movies') ? Table.movies : Table.series;
|
||||
const mediaFound = await MediaModel.findOne(mediaTable, mediaCode);
|
||||
if (mediaFound) {
|
||||
const mediaFound = await MediaModel.findOne(mediaTable, cleanCode);
|
||||
if (mediaFound.length != 0) {
|
||||
return res.status(409).json({ message: 'Media already exists' });
|
||||
}
|
||||
|
||||
@ -61,7 +65,7 @@ export default {
|
||||
webImg: mData.Poster,
|
||||
};
|
||||
|
||||
const savedMedia = await MediaModel.save(mediaTable, mediaCode, mData.Title, mData.Released, mData.Poster);
|
||||
const savedMedia = await MediaModel.save(mediaTable, cleanCode, mData.Title, mData.Released, mData.Poster);
|
||||
return res.status(201).json(media);
|
||||
} catch (err) {
|
||||
return res.status(500).json({ message: 'Error when creating media' });
|
||||
|
Loading…
x
Reference in New Issue
Block a user