feat(SPG-953): penyesuaian API Create dan Update pengguna baru dengan menambahkan opsi admin antrian
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
283b783007
commit
52c82a9a41
|
@ -13,6 +13,8 @@ import { EventTopics } from 'src/core/strings/constants/interface.constants';
|
||||||
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
import { UserModel } from 'src/modules/user-related/user/data/models/user.model';
|
||||||
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';
|
||||||
import { UserLoginEvent } from '../entities/login.event';
|
import { UserLoginEvent } from '../entities/login.event';
|
||||||
|
import { Not } from 'typeorm';
|
||||||
|
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LoginManager extends BaseCustomManager<UserEntity> {
|
export class LoginManager extends BaseCustomManager<UserEntity> {
|
||||||
|
@ -36,6 +38,7 @@ export class LoginManager extends BaseCustomManager<UserEntity> {
|
||||||
where: {
|
where: {
|
||||||
username: this.data.username,
|
username: this.data.username,
|
||||||
status: STATUS.ACTIVE,
|
status: STATUS.ACTIVE,
|
||||||
|
role: Not(UserRole.QUEUE_ADMIN),
|
||||||
},
|
},
|
||||||
relations: [
|
relations: [
|
||||||
'user_privilege',
|
'user_privilege',
|
||||||
|
|
|
@ -15,12 +15,7 @@ import { SALT_OR_ROUNDS } from 'src/core/strings/constants/base.constants';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CreateUserManager extends BaseCreateManager<UserEntity> {
|
export class CreateUserManager extends BaseCreateManager<UserEntity> {
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
let role = UserRole.STAFF;
|
|
||||||
if (this.data.is_super_admin || !this.data.user_privilege)
|
|
||||||
role = UserRole.SUPERADMIN;
|
|
||||||
|
|
||||||
Object.assign(this.data, {
|
Object.assign(this.data, {
|
||||||
role: role,
|
|
||||||
password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
|
password: await hashPassword(this.data.password, SALT_OR_ROUNDS),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ export class DetailUserManager extends BaseDetailManager<UserEntity> {
|
||||||
`${this.tableName}.status`,
|
`${this.tableName}.status`,
|
||||||
`${this.tableName}.name`,
|
`${this.tableName}.name`,
|
||||||
`${this.tableName}.username`,
|
`${this.tableName}.username`,
|
||||||
|
`${this.tableName}.role`,
|
||||||
`${this.tableName}.created_at`,
|
`${this.tableName}.created_at`,
|
||||||
`${this.tableName}.creator_name`,
|
`${this.tableName}.creator_name`,
|
||||||
`${this.tableName}.updated_at`,
|
`${this.tableName}.updated_at`,
|
||||||
|
|
|
@ -41,6 +41,7 @@ export class IndexUserManager extends BaseIndexManager<UserEntity> {
|
||||||
`${this.tableName}.status`,
|
`${this.tableName}.status`,
|
||||||
`${this.tableName}.name`,
|
`${this.tableName}.name`,
|
||||||
`${this.tableName}.username`,
|
`${this.tableName}.username`,
|
||||||
|
`${this.tableName}.role`,
|
||||||
`${this.tableName}.created_at`,
|
`${this.tableName}.created_at`,
|
||||||
`${this.tableName}.creator_name`,
|
`${this.tableName}.creator_name`,
|
||||||
`${this.tableName}.updated_at`,
|
`${this.tableName}.updated_at`,
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
columnUniques,
|
columnUniques,
|
||||||
validateRelations,
|
validateRelations,
|
||||||
} from 'src/core/strings/constants/interface.constants';
|
} from 'src/core/strings/constants/interface.constants';
|
||||||
import { UserRole } from '../../../constants';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
|
export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
|
||||||
|
@ -17,14 +16,6 @@ export class UpdateUserManager extends BaseUpdateManager<UserEntity> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async beforeProcess(): Promise<void> {
|
async beforeProcess(): Promise<void> {
|
||||||
let role = UserRole.STAFF;
|
|
||||||
if (this.data.is_super_admin || !this.data.user_privilege)
|
|
||||||
role = UserRole.SUPERADMIN;
|
|
||||||
|
|
||||||
Object.assign(this.data, {
|
|
||||||
role: role,
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,14 +15,9 @@ export class UpdateUserDto extends BaseStatusDto implements UserEntity {
|
||||||
@IsString()
|
@IsString()
|
||||||
username: string;
|
username: string;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({ name: 'role', required: true, example: UserRole.STAFF })
|
||||||
name: 'is_super_admin',
|
@IsString()
|
||||||
type: Boolean,
|
role: UserRole;
|
||||||
required: true,
|
|
||||||
example: false,
|
|
||||||
})
|
|
||||||
@IsBoolean()
|
|
||||||
is_super_admin: boolean;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
name: 'user_privilege',
|
name: 'user_privilege',
|
||||||
|
@ -45,9 +40,6 @@ export class UpdateUserDto extends BaseStatusDto implements UserEntity {
|
||||||
@Exclude()
|
@Exclude()
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
@Exclude()
|
|
||||||
role: UserRole;
|
|
||||||
|
|
||||||
@Exclude()
|
@Exclude()
|
||||||
refresh_token: string;
|
refresh_token: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,14 +31,9 @@ export class UserDto extends BaseStatusDto implements UserEntity {
|
||||||
@ValidateIf((body) => body.user_privilege)
|
@ValidateIf((body) => body.user_privilege)
|
||||||
user_privilege: UserPrivilegeModel;
|
user_privilege: UserPrivilegeModel;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({ name: 'role', required: true, example: UserRole.STAFF })
|
||||||
name: 'is_super_admin',
|
@IsString()
|
||||||
type: Boolean,
|
role: UserRole;
|
||||||
required: true,
|
|
||||||
example: false,
|
|
||||||
})
|
|
||||||
@IsBoolean()
|
|
||||||
is_super_admin: boolean;
|
|
||||||
|
|
||||||
@Exclude()
|
@Exclude()
|
||||||
share_margin: number;
|
share_margin: number;
|
||||||
|
@ -46,9 +41,6 @@ export class UserDto extends BaseStatusDto implements UserEntity {
|
||||||
@Exclude()
|
@Exclude()
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
@Exclude()
|
|
||||||
role: UserRole;
|
|
||||||
|
|
||||||
@Exclude()
|
@Exclude()
|
||||||
refresh_token: string;
|
refresh_token: string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue