Skip to content

Commit

Permalink
setting user default privileges to not an admin, adding @types/ws and…
Browse files Browse the repository at this point in the history
… fix url on models
  • Loading branch information
asere committed Aug 29, 2023
1 parent 7eeccf8 commit 1235199
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions BackEnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/mocha": "^9.0.0",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.5",
"@types/ws": "^8.5.4",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"eslint": "^7.31.0",
Expand Down
9 changes: 7 additions & 2 deletions BackEnd/src/models/Server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import mongoose from 'mongoose';
import { User } from './User'

var uniqueValidator = require('mongoose-unique-validator');
var slug = require('slug');
const domain = 'learn-ocaml.org';
Expand Down Expand Up @@ -42,11 +44,14 @@ var ServerSchema = new mongoose.Schema({

ServerSchema.plugin(uniqueValidator, { message: 'is already taken' });

ServerSchema.pre('validate', function (next) {
ServerSchema.pre('validate', async function (next) {
if (!(this as any).slug) {
(this as any).slugify();
}
(this as any).url = (this as any).author.username + '.' + (this as any).slug + '.' + domain;

console.log((this as any).author);
let user = await User.findOne({ _id: (this as any).author }, "username").exec();
(this as any).url = (this as any).slug + '-' + (user as any).username + '.' + domain;
next();
});

Expand Down
2 changes: 1 addition & 1 deletion BackEnd/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var UserSchema = new mongoose.Schema({
description: String,
place: String,
goal: String,
admin: { type: Boolean, default: true },
admin: { type: Boolean, default: false },
active: { type: Boolean, default: true },
authorized: { type: Boolean, default: false },
image: String,
Expand Down

0 comments on commit 1235199

Please sign in to comment.