create stream info if not exists

This commit is contained in:
SrGooglo 2022-11-28 17:53:25 +00:00 committed by root
parent db50c6ec5a
commit 12ae6862bf

View File

@ -161,15 +161,26 @@ export default class StreamingController extends Controller {
user_id, user_id,
}) })
if (!info) {
info = new StreamingInfo({
user_id,
})
await info.save()
}
const category = await StreamingCategory.findOne({ const category = await StreamingCategory.findOne({
key: info.category key: info.category
}) }).catch((err) => {
console.error(err)
return {}
}) ?? {}
return res.json({ return res.json({
...info.toObject(), ...info.toObject(),
["category"]: { ["category"]: {
key: category.key, key: category?.key ?? "unknown",
label: category.label, label: category?.label ?? "Unknown",
} }
}) })
} }