Fix bug
This commit is contained in:
parent
78d5e7507f
commit
1d6338fd64
@ -31,7 +31,7 @@ export default {
|
|||||||
* mediaController.create()
|
* mediaController.create()
|
||||||
*/
|
*/
|
||||||
create: async function (req: Request, res: Response) {
|
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);
|
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' });
|
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 {
|
try {
|
||||||
const mediaTable = req.baseUrl.includes('movies') ? Table.movies : Table.series;
|
const mediaTable = req.baseUrl.includes('movies') ? Table.movies : Table.series;
|
||||||
const mediaFound = await MediaModel.findOne(mediaTable, mediaCode);
|
const mediaFound = await MediaModel.findOne(mediaTable, cleanCode);
|
||||||
if (mediaFound) {
|
if (mediaFound.length != 0) {
|
||||||
return res.status(409).json({ message: 'Media already exists' });
|
return res.status(409).json({ message: 'Media already exists' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ export default {
|
|||||||
webImg: mData.Poster,
|
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);
|
return res.status(201).json(media);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return res.status(500).json({ message: 'Error when creating media' });
|
return res.status(500).json({ message: 'Error when creating media' });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user