new Channels start w/ admin, chan rank api started

This commit is contained in:
rainbow napkin 2024-11-24 07:54:04 -05:00
parent 9d401ae6a8
commit 057537341a
5 changed files with 103 additions and 8 deletions

View file

@ -60,7 +60,7 @@ const channelSchema = new mongoose.Schema({
ref: "user"
},
rank: {
type: mongoose.SchemaTypes.Boolean,
type: mongoose.SchemaTypes.String,
required: true,
enum: permissionModel.rankEnum
}
@ -79,7 +79,7 @@ channelSchema.pre('save', async function (next){
});
//statics
channelSchema.statics.register = async function(channelObj){
channelSchema.statics.register = async function(channelObj, ownerObj){
const {name, description, thumbnail} = channelObj;
const chanDB = await this.findOne({ name });
@ -88,7 +88,12 @@ channelSchema.statics.register = async function(channelObj){
throw new Error("Channel name already taken!");
}else{
const id = await statModel.incrementChannelCount();
const newChannel = await this.create((thumbnail ? {id, name, description, thumbnail} : {id, name, description}));
const rankList = [{
user: ownerObj._id,
rank: "admin"
}];
const newChannel = await this.create((thumbnail ? {id, name, description, thumbnail, rankList} : {id, name, description, rankList}));
}
}
@ -142,6 +147,19 @@ channelSchema.methods.updateChannelPerms = async function(permissionsMap){
return this.permissions;
}
channelSchema.methods.setUserRank = async function(userDB,rank){
//Create rank object based on input
const rankObj = {
user: userDB._id,
rank: rank
}
//Add it to rank list
this.rankList.push(rankObj);
//Save our channel and return rankList
await this.save();
return this.rankList;
}
channelSchema.methods.getChannelRankFromUser = async function(userDB){
}
@ -156,9 +174,9 @@ channelSchema.methods.nuke = async function(confirm){
}
//Annoyingly there isnt a good way to do this from 'this'
var oldUser = await module.exports.deleteOne(this);
var oldChan = await module.exports.deleteOne({_id: this._id});
if(oldUser == null){
if(oldChan.deletedCount == 0){
throw new Error("Server Error: Unable to delete channel! Please report this error to your server administrator, and with timestamp.");
}
}