Added dto for Admin Panel, moved UserRole to dto
This commit is contained in:
		@@ -1,3 +1,8 @@
 | 
			
		||||
export * as Requests from './requests';
 | 
			
		||||
export * as Responses from './responses';
 | 
			
		||||
export { validateSync, validateAsync, validateAsyncInline } from './utils';
 | 
			
		||||
export {
 | 
			
		||||
	UserRole,
 | 
			
		||||
	validateSync,
 | 
			
		||||
	validateAsync,
 | 
			
		||||
	validateAsyncInline
 | 
			
		||||
} from './utils';
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								dto/src/requests/admin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								dto/src/requests/admin.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
import { BaseRequest } from './base';
 | 
			
		||||
import { IsEnum, IsNumber } from 'class-validator';
 | 
			
		||||
import { UserRole } from '../utils';
 | 
			
		||||
 | 
			
		||||
class AdminRequest extends BaseRequest {
 | 
			
		||||
	@IsNumber()
 | 
			
		||||
	user: number;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class SetUserRole extends AdminRequest {
 | 
			
		||||
	@IsEnum(UserRole)
 | 
			
		||||
	role: UserRole;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class LogoutAll extends AdminRequest {}
 | 
			
		||||
export class DeleteUser extends AdminRequest {}
 | 
			
		||||
export class DisableTfa extends AdminRequest {}
 | 
			
		||||
@@ -1,3 +1,4 @@
 | 
			
		||||
export * from './base';
 | 
			
		||||
export * as Auth from './auth';
 | 
			
		||||
export * as FS from './fs';
 | 
			
		||||
export * as Admin from './admin';
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										61
									
								
								dto/src/responses/admin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								dto/src/responses/admin.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
import { SuccessResponse } from './base';
 | 
			
		||||
import {
 | 
			
		||||
	IsArray,
 | 
			
		||||
	IsBoolean,
 | 
			
		||||
	IsEnum,
 | 
			
		||||
	IsNotEmpty,
 | 
			
		||||
	IsNumber,
 | 
			
		||||
	IsString,
 | 
			
		||||
	ValidateNested
 | 
			
		||||
} from 'class-validator';
 | 
			
		||||
import { UserRole, ValidateConstructor } from '../utils';
 | 
			
		||||
 | 
			
		||||
@ValidateConstructor
 | 
			
		||||
export class GetUsersEntry {
 | 
			
		||||
	constructor(
 | 
			
		||||
		id: number,
 | 
			
		||||
		gitlab: boolean,
 | 
			
		||||
		name: string,
 | 
			
		||||
		role: UserRole,
 | 
			
		||||
		tfaEnabled: boolean
 | 
			
		||||
	) {
 | 
			
		||||
		this.id = id;
 | 
			
		||||
		this.gitlab = gitlab;
 | 
			
		||||
		this.name = name;
 | 
			
		||||
		this.role = role;
 | 
			
		||||
		this.tfaEnabled = tfaEnabled;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@IsNumber()
 | 
			
		||||
	id: number;
 | 
			
		||||
 | 
			
		||||
	@IsBoolean()
 | 
			
		||||
	gitlab: boolean;
 | 
			
		||||
 | 
			
		||||
	@IsString()
 | 
			
		||||
	@IsNotEmpty()
 | 
			
		||||
	name: string;
 | 
			
		||||
 | 
			
		||||
	@IsEnum(UserRole)
 | 
			
		||||
	role: UserRole;
 | 
			
		||||
 | 
			
		||||
	@IsBoolean()
 | 
			
		||||
	tfaEnabled: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ValidateConstructor
 | 
			
		||||
export class GetUsers extends SuccessResponse {
 | 
			
		||||
	constructor(users: GetUsersEntry[]) {
 | 
			
		||||
		super();
 | 
			
		||||
		this.users = users;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@IsArray()
 | 
			
		||||
	@ValidateNested({ each: true })
 | 
			
		||||
	users: GetUsersEntry[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class LogoutAllUser extends SuccessResponse {}
 | 
			
		||||
export class DeleteUser extends SuccessResponse {}
 | 
			
		||||
export class SetUserRole extends SuccessResponse {}
 | 
			
		||||
export class DisableTfa extends SuccessResponse {}
 | 
			
		||||
@@ -2,3 +2,4 @@ export * from './base';
 | 
			
		||||
export * as Auth from './auth';
 | 
			
		||||
export * as FS from './fs';
 | 
			
		||||
export * as User from './user';
 | 
			
		||||
export * as Admin from './admin';
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,11 @@
 | 
			
		||||
import { validate, validateSync as _validateSync } from 'class-validator';
 | 
			
		||||
 | 
			
		||||
export enum UserRole {
 | 
			
		||||
	ADMIN = 2,
 | 
			
		||||
	USER = 1,
 | 
			
		||||
	DISABLED = 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function validateSync<T extends object>(data: T): void {
 | 
			
		||||
	const errors = _validateSync(data);
 | 
			
		||||
	if (errors.length > 0) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user