mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-03-24 11:05:49 +00:00
new authorization
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { UsernameDto } from './username.dto';
|
||||
|
||||
export class AddUsernameRequestDto extends UsernameDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
userId: string;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import {
|
||||
ArrayMinSize,
|
||||
IsArray,
|
||||
IsNotEmpty,
|
||||
IsString,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { UsernameDto } from './username.dto';
|
||||
|
||||
export class CreateAuthenticationRequestDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
userId: string;
|
||||
|
||||
@Type(() => UsernameDto)
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
usernames: UsernameDto[];
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class DeleteAuthenticationRequestDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
userId: string;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Type } from '@modules/authentication/core/domain/username.types';
|
||||
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||
import { IsValidUsername } from './validators/decorators/is-valid-username.decorator';
|
||||
|
||||
export class UsernameDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsValidUsername({
|
||||
message: 'Invalid username',
|
||||
})
|
||||
name: string;
|
||||
|
||||
@IsEnum(Type)
|
||||
@IsNotEmpty()
|
||||
type: Type;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Type } from '@modules/authentication/core/domain/username.types';
|
||||
import {
|
||||
registerDecorator,
|
||||
ValidationOptions,
|
||||
ValidationArguments,
|
||||
isEmail,
|
||||
isPhoneNumber,
|
||||
} from 'class-validator';
|
||||
|
||||
export function IsValidUsername(validationOptions?: ValidationOptions) {
|
||||
return function (object: any, propertyName: string) {
|
||||
registerDecorator({
|
||||
name: 'isValidUsername',
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate(value: any, args: ValidationArguments) {
|
||||
const usernameType: Type = args.object['type'];
|
||||
switch (usernameType) {
|
||||
case Type.PHONE:
|
||||
return isPhoneNumber(value);
|
||||
case Type.EMAIL:
|
||||
return isEmail(value);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user