feat(SPG-321) REST API Read User Privileges
parent
11cd564433
commit
21ac7c4475
|
@ -0,0 +1,10 @@
|
|||
import { BaseStatusModel } from "src/core/modules/data/model/base-status.model";
|
||||
import { TABLE_NAME } from "src/core/strings/constants/table.constants";
|
||||
import { Column, Entity } from "typeorm";
|
||||
import { UserPrivilegeEntity } from "../../domain/entities/user-privilege.entity";
|
||||
|
||||
@Entity(TABLE_NAME.USER_PRIVILEGE)
|
||||
export class UserPrivilegeModel extends BaseStatusModel<UserPrivilegeEntity> implements UserPrivilegeEntity {
|
||||
@Column('varchar', { name: 'name', length: 125 })
|
||||
name: string;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { UserPrivilegeEntity } from "../../domain/entities/user-privilege.entity";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { UserPrivilegeModel } from "../model/user-privilege.model";
|
||||
import { CONNECTION_NAME } from "src/core/strings/constants/base.constants";
|
||||
import { Repository } from "typeorm";
|
||||
import { BaseReadService } from "src/core/modules/data/service/base-read.service";
|
||||
|
||||
@Injectable()
|
||||
export class UserPrivilegeReadService extends BaseReadService<UserPrivilegeEntity> {
|
||||
|
||||
constructor(
|
||||
@InjectRepository(UserPrivilegeModel, CONNECTION_NAME.DEFAULT)
|
||||
private repo: Repository<UserPrivilegeModel>,
|
||||
) {
|
||||
super(repo);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import { BaseFilterEntity } from "src/core/modules/domain/entities/base-filter.entity";
|
||||
|
||||
export interface FilterUserPrivilegeEntity extends BaseFilterEntity {
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { BaseDetailManager } from "src/core/modules/domain/usecase/managers/base-detail.manager";
|
||||
import { UserPrivilegeEntity } from "../../entities/user-privilege.entity";
|
||||
import { FindOneOptions } from "typeorm";
|
||||
import { TABLE_NAME } from "src/core/strings/constants/table.constants";
|
||||
|
||||
@Injectable()
|
||||
export class DetailUserPrivilegeManager extends BaseDetailManager<UserPrivilegeEntity> {
|
||||
|
||||
get setFindProperties(): any {
|
||||
return {
|
||||
id: this.dataId
|
||||
}
|
||||
}
|
||||
|
||||
get selectData(): string[] {
|
||||
return [
|
||||
'id',
|
||||
];
|
||||
}
|
||||
|
||||
get relationData(): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
async prepareData(): Promise<void> {
|
||||
this.tableName = TABLE_NAME.USER_PRIVILEGE;
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { BaseUpdateStatusManager } from "src/core/modules/domain/usecase/managers/base-update-status.manager";
|
||||
import { UserPrivilegeEntity } from "../../entities/user-privilege.entity";
|
||||
import { EventTopics } from "src/core/strings/constants/interface.constants";
|
||||
import { UserPrivilegeModel } from "../../../data/model/user-privilege.model";
|
||||
import { UserPrivilegeChangeStatusEvent } from "../../entities/event/user-privilege-change-status.event";
|
||||
|
||||
@Injectable()
|
||||
export class InactiveUserPrivilegeManager extends BaseUpdateStatusManager<UserPrivilegeEntity> {
|
||||
|
||||
getResult(): string {
|
||||
return `Success inactive data ${this.result.name}`;
|
||||
}
|
||||
|
||||
async validateProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get entityTarget(): any {
|
||||
return UserPrivilegeModel;
|
||||
}
|
||||
|
||||
get eventTopics(): EventTopics[] {
|
||||
return [
|
||||
{
|
||||
topic: UserPrivilegeChangeStatusEvent,
|
||||
data: this.data,
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { BaseIndexManager } from "src/core/modules/domain/usecase/managers/base-index.manager";
|
||||
import { UserPrivilegeEntity } from "../../entities/user-privilege.entity";
|
||||
import { SelectQueryBuilder } from "typeorm";
|
||||
import { BaseFilterEntity } from "src/core/modules/domain/entities/base-filter.entity";
|
||||
import { TABLE_NAME } from "src/core/strings/constants/table.constants";
|
||||
import { Param } from "src/core/helpers/query/specific-search.helper";
|
||||
|
||||
@Injectable()
|
||||
export class IndexUserPrivilegeManager extends BaseIndexManager<UserPrivilegeEntity> {
|
||||
|
||||
async prepareData(): Promise<void> {
|
||||
this.tableName = TABLE_NAME.USER_PRIVILEGE;
|
||||
return
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
get specificFilter(): Param[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<UserPrivilegeEntity>
|
||||
): SelectQueryBuilder<UserPrivilegeEntity> {
|
||||
|
||||
if (this.filterParam.q) {
|
||||
queryBuilder.andWhere('status = :q', {
|
||||
q: this.filterParam.q
|
||||
})
|
||||
}
|
||||
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
setFilterSearch(): string[] {
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
import { Injectable } from "@nestjs/common";
|
||||
import { IndexUserPrivilegeManager } from "./managers/index-user-privilege.manager";
|
||||
import { UserPrivilegeReadService } from "../../data/service/user-privilege-read.service";
|
||||
import { UserPrivilegeEntity } from "../entities/user-privilege.entity";
|
||||
import { PaginationResponse } from "src/core/response/domain/ok-response.interface";
|
||||
import { BaseReadOrchestrator } from "src/core/modules/domain/usecase/orchestrators/base-read.orchestrator";
|
||||
import { DetailUserPrivilegeManager } from "./managers/detail-user-privilege.manager";
|
||||
|
||||
@Injectable()
|
||||
export class UserPrivilegeReadOrchestrator extends BaseReadOrchestrator<UserPrivilegeEntity> {
|
||||
|
||||
constructor(
|
||||
private indexManager: IndexUserPrivilegeManager,
|
||||
private detailManager: DetailUserPrivilegeManager,
|
||||
private serviceData: UserPrivilegeReadService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async index(params): Promise<PaginationResponse<UserPrivilegeEntity>> {
|
||||
this.indexManager.setFilterParam(params)
|
||||
this.indexManager.setService(this.serviceData)
|
||||
await this.indexManager.execute()
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async detail(dataId: string): Promise<UserPrivilegeEntity> {
|
||||
this.detailManager.setData(dataId);
|
||||
this.detailManager.setService(this.serviceData);
|
||||
await this.detailManager.execute();
|
||||
return this.detailManager.getResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
import { BaseFilterDto } from "src/core/modules/infrastructure/dto/base-filter.dto";
|
||||
import { FilterUserPrivilegeEntity } from "../../domain/entities/filter-user-privilege.entity";
|
||||
|
||||
export class FilterUserPrivilegeDto extends BaseFilterDto implements FilterUserPrivilegeEntity {}
|
|
@ -0,0 +1,34 @@
|
|||
import { Controller, Get, Param, Query, Req } from "@nestjs/common";
|
||||
import { FilterUserPrivilegeDto } from "./dto/filter-user-privilege.dto";
|
||||
import { Pagination } from "src/core/response";
|
||||
import { PaginationResponse } from "src/core/response/domain/ok-response.interface";
|
||||
import { UserPrivilegeEntity } from "../domain/entities/user-privilege.entity";
|
||||
import { UserPrivilegeReadOrchestrator } from "../domain/usecases/user-privilege-read.orchestrator";
|
||||
import { ApiTags } from "@nestjs/swagger";
|
||||
import { MODULE_NAME } from "src/core/strings/constants/module.constants";
|
||||
import { Unprotected } from "src/core/guards";
|
||||
|
||||
@ApiTags(`${MODULE_NAME.USER_PRIVILEGE.split('-').join(' ')} - read`)
|
||||
@Controller(MODULE_NAME.USER_PRIVILEGE)
|
||||
@Unprotected()
|
||||
export class UserPrivilegeReadController {
|
||||
constructor(
|
||||
private orchestrator: UserPrivilegeReadOrchestrator
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@Pagination()
|
||||
async index(
|
||||
@Query() params: FilterUserPrivilegeDto
|
||||
): Promise<PaginationResponse<UserPrivilegeEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
|
||||
@Get(':id')
|
||||
async detail(
|
||||
@Param('id') id: string,
|
||||
): Promise<UserPrivilegeEntity> {
|
||||
return await this.orchestrator.detail(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
import { Module } from "@nestjs/common";
|
||||
import { UserPrivilegeModel } from "./data/model/user-privilege.model";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { CONNECTION_NAME } from "src/core/strings/constants/base.constants";
|
||||
import { UserPrivilegeDataService } from "./data/service/user-privilege-data.service";
|
||||
import { UserPrivilegeReadService } from "./data/service/user-privilege-read.service";
|
||||
import { UserPrivilegeReadController } from "./infrastructure/user-privilege-read.controller";
|
||||
import { UserPrivilegeReadOrchestrator } from "./domain/usecases/user-privilege-read.orchestrator";
|
||||
import { UserPrivilegeDataController } from "./infrastructure/user-privilege-data.controller";
|
||||
import { UserPrivilegeDataOrchestrator } from "./domain/usecases/user-privilege-data.orchestrator";
|
||||
import { CreateUserPrivilegeManager } from "./domain/usecases/managers/create-user-privilege.manager";
|
||||
import { CqrsModule } from "@nestjs/cqrs";
|
||||
import { IndexUserPrivilegeManager } from "./domain/usecases/managers/index-user-privilege.manager";
|
||||
import { DeleteUserPrivilegeManager } from "./domain/usecases/managers/delete-user-privilege.manager";
|
||||
import { UpdateUserPrivilegeManager } from "./domain/usecases/managers/update-user-privilege.manager";
|
||||
import { ActiveUserPrivilegeManager } from "./domain/usecases/managers/active-user-privilege.manager";
|
||||
import { ConfirmUserPrivilegeManager } from "./domain/usecases/managers/confirm-user-privilege.manager";
|
||||
import { InactiveUserPrivilegeManager } from "./domain/usecases/managers/inactive-user-privilege.manager";
|
||||
import { DetailUserPrivilegeManager } from "./domain/usecases/managers/detail-user-privilege.manager";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot(),
|
||||
TypeOrmModule.forFeature([UserPrivilegeModel], CONNECTION_NAME.DEFAULT),
|
||||
CqrsModule,
|
||||
],
|
||||
controllers: [
|
||||
UserPrivilegeDataController,
|
||||
UserPrivilegeReadController
|
||||
],
|
||||
providers: [
|
||||
IndexUserPrivilegeManager,
|
||||
DetailUserPrivilegeManager,
|
||||
CreateUserPrivilegeManager,
|
||||
DeleteUserPrivilegeManager,
|
||||
UpdateUserPrivilegeManager,
|
||||
ActiveUserPrivilegeManager,
|
||||
ConfirmUserPrivilegeManager,
|
||||
InactiveUserPrivilegeManager,
|
||||
|
||||
UserPrivilegeDataService,
|
||||
UserPrivilegeReadService,
|
||||
|
||||
UserPrivilegeDataOrchestrator,
|
||||
UserPrivilegeReadOrchestrator,
|
||||
],
|
||||
})
|
||||
export class UserPrivilegeModule {}
|
Loading…
Reference in New Issue