Created channel perms schema and api routes.
This commit is contained in:
parent
9dbbc4e924
commit
8384e732f3
21 changed files with 250 additions and 20 deletions
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
const config = require('../../config.json');
|
||||
const userModel = require('../schemas/userSchema');
|
||||
const permissionModel = require('../schemas/permissionSchema');
|
||||
const channelModel = require('../schemas/channelSchema');
|
||||
const channelModel = require('../schemas/channel/channelSchema');
|
||||
const {exceptionHandler} = require("../utils/loggerUtils");
|
||||
|
||||
//register page functions
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const channelModel = require('../../../schemas/channelSchema.js');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
||||
|
||||
//api list channel functions
|
||||
module.exports.get = async function(req, res){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const channelModel = require('../../../schemas/channelSchema');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
|
||||
//api account functions
|
||||
module.exports.post = async function(req, res){
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//local imports
|
||||
const channelModel = require('../../../schemas/channelSchema');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
|
||||
//api account functions
|
||||
|
|
|
|||
73
src/controllers/api/channel/permissionsController.js
Normal file
73
src/controllers/api/channel/permissionsController.js
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*Canopy - The next generation of stoner streaming software
|
||||
Copyright (C) 2024 Rainbownapkin and the TTN Community
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//NPM imports
|
||||
const {validationResult, matchedData} = require('express-validator');
|
||||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
||||
|
||||
//api account functions
|
||||
module.exports.get = async function(req, res){
|
||||
try{
|
||||
const validResult = validationResult(req);
|
||||
|
||||
if(validResult.isEmpty()){
|
||||
const data = matchedData(req);
|
||||
const channel = await channelModel.findOne({name: data.chanName});
|
||||
|
||||
|
||||
if(channel == null){
|
||||
throw new Error("Channel not found.");
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
return res.send(channel.permissions);
|
||||
}else{
|
||||
res.status(400);
|
||||
res.send({errors: validResult.array()})
|
||||
}
|
||||
}catch(err){
|
||||
exceptionHandler(res, err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.post = async function(req, res){
|
||||
try{
|
||||
const validResult = validationResult(req);
|
||||
|
||||
if(validResult.isEmpty()){
|
||||
const data = matchedData(req);
|
||||
const channel = await channelModel.findOne({name: data.chanName});
|
||||
const permissionsMap = new Map(Object.entries(data.channelPermissionsMap));
|
||||
|
||||
if(channel == null){
|
||||
throw new Error("Channel not found.");
|
||||
}
|
||||
|
||||
res.status(200);
|
||||
return res.send(await channel.updateChannelPerms(permissionsMap));
|
||||
}else{
|
||||
res.status(400);
|
||||
res.send({errors: validResult.array()})
|
||||
}
|
||||
}catch(err){
|
||||
exceptionHandler(res, err);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const channelModel = require('../../../schemas/channelSchema');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
|
||||
//api account functions
|
||||
module.exports.post = async function(req, res){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const channelModel = require('../../../schemas/channelSchema');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
|
||||
//api account functions
|
||||
module.exports.get = async function(req, res){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const config = require('../../config.json');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../utils/loggerUtils.js');
|
||||
const channelModel = require('../schemas/channelSchema');
|
||||
const channelModel = require('../schemas/channel/channelSchema');
|
||||
|
||||
//root index functions
|
||||
module.exports.get = async function(req, res){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ const config = require('../../config.json');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../utils/loggerUtils.js');
|
||||
const channelModel = require('../schemas/channelSchema');
|
||||
const channelModel = require('../schemas/channel/channelSchema');
|
||||
|
||||
//root index functions
|
||||
module.exports.get = async function(req, res){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue