new Channels start w/ admin, chan rank api started
This commit is contained in:
parent
9d401ae6a8
commit
057537341a
5 changed files with 103 additions and 8 deletions
|
|
@ -19,17 +19,23 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
|
||||
//local imports
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
||||
const userModel = require('../../../schemas/userSchema.js');
|
||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||
|
||||
//api account functions
|
||||
module.exports.post = async function(req, res){
|
||||
try{
|
||||
//Get validation result
|
||||
const validResult = validationResult(req);
|
||||
const channel = matchedData(req);
|
||||
|
||||
|
||||
//If we data is valid
|
||||
if(validResult.isEmpty()){
|
||||
await channelModel.register(channel)
|
||||
//Set channel object from sanatized/validated data, and get user document from session data
|
||||
const channel = matchedData(req);
|
||||
const userDB = await userModel.findOne({user: req.session.user.user});
|
||||
|
||||
//register new channel with requesting user as owner
|
||||
await channelModel.register(channel, userDB);
|
||||
return res.sendStatus(200);
|
||||
}else{
|
||||
res.status(400);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue