user role + module alias

This commit is contained in:
2022-10-16 15:28:42 +02:00
parent f6a7415884
commit 0c3a3546e6
14 changed files with 70 additions and 29 deletions

View File

@ -1,3 +1,4 @@
import './paths';
import Server from './framework/express/server';
import ip from 'ip';
import UserModel from './framework/mongo/user';

View File

@ -2,6 +2,7 @@ import {
UserCtor,
UserInfo,
UserInfoWithPassword,
UserRoles,
UserWithPasswordCtor,
} from '@core';
import { generateHash } from '../functions/password';
@ -9,17 +10,20 @@ import { Entity } from './entity';
export class User extends Entity implements UserInfo {
username: string;
role: keyof typeof UserRoles;
constructor(raw: UserCtor) {
super(raw);
this.username = raw.username ? raw.username : '';
this.username = raw.username || '';
this.role = raw.role || UserRoles.USER;
}
Info(): UserInfo {
return {
uuid: this.uuid,
username: this.username,
role: this.role,
};
}
}
@ -37,6 +41,7 @@ export class UserWithPassword extends User implements UserInfoWithPassword {
return {
uuid: this.uuid,
username: this.username,
role: this.role,
password: this.password,
};
}

5
api/src/paths.ts Normal file
View File

@ -0,0 +1,5 @@
import { addAliases } from 'module-alias';
addAliases({
'@core': `${__dirname}/../../core/src`,
});