/*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 .*/ //NPM Imports const {mongoose} = require('mongoose'); //Local Imports const permissionModel = require("./permissionSchema"); const defaultFlair = require("../../defaultFlair.json"); const flairSchema = new mongoose.Schema({ name:{ type: mongoose.SchemaTypes.String, required: true }, displayName:{ type: mongoose.SchemaTypes.String, required: true }, rank: { type: mongoose.SchemaTypes.String, enum: permissionModel.rankEnum, default: "user", required: true } }); flairSchema.statics.loadDefaults = async function(){ //For each entry in the defaultFlair.json file defaultFlair.forEach(async (flair) => { try{ //Look for flair matching the one from our file const foundFlair = await this.findOne({name: flair.name}); //if the flair doesn't exist if(!foundFlair){ const flairDB = await this.create(flair); console.log(`Loading default flair '${flair.name} into DB from defaultFlair.json`); } }catch(err){ if(flair != null){ console.log(`Error loading flair '${flair.name}':`); }else{ console.log("Error, null flair:"); } console.log(err); } }); } module.exports = mongoose.model("flair", flairSchema);