@mbc-cqrs-serverless/cli
Version:
a CLI to get started with MBC CQRS serverless framework
86 lines (77 loc) • 2.56 kB
text/typescript
import {
CommandService,
DataService,
DetailDto,
IInvoke,
INVOKE_CONTEXT,
SearchDto,
} from '@mbc-cqrs-serverless/core'
import {
Body,
Controller,
Get,
Logger,
NotFoundException,
Param,
Post,
Query,
} from '@nestjs/common'
import { ApiTags } from '@nestjs/swagger'
import { SampleCommandDto } from './dto/sample-command.dto'
import { SampleCommandEntity } from './entity/sample-command.entity'
import { SampleDataEntity } from './entity/sample-data.entity'
import { SampleDataListEntity } from './entity/sample-data-list.entity'
import { SampleService } from './sample.service'
export class SampleController {
private readonly logger = new Logger(SampleController.name)
constructor(
private readonly commandService: CommandService,
private readonly dataService: DataService,
private readonly sampleService: SampleService,
) {}
async publishCommand(
invokeContext: IInvoke,
sampleDto: SampleCommandDto,
): Promise<SampleDataEntity> {
this.logger.debug('cmd:', sampleDto)
this.logger.debug('commandService:' + this.commandService.tableName)
const item = await this.commandService.publishAsync(sampleDto, {
invokeContext,
})
return new SampleDataEntity(item as SampleDataEntity)
}
async getCommand(
detailDto: DetailDto,
): Promise<SampleCommandEntity> {
this.logger.debug('commandService:' + this.commandService.tableName)
const item = await this.commandService.getItem(detailDto)
if (!item) {
throw new NotFoundException('Sample command not found')
}
this.logger.debug('item:', item)
return new SampleCommandEntity(item as SampleCommandEntity)
}
async getData( detailDto: DetailDto): Promise<SampleDataEntity> {
this.logger.debug('dataService:' + this.dataService.tableName)
const item = await this.dataService.getItem(detailDto)
if (!item) {
throw new NotFoundException('Sample data not found')
}
this.logger.debug('item:', item)
return new SampleDataEntity(item as SampleDataEntity)
}
async listDataByPk( pk: string): Promise<SampleDataListEntity> {
const res = await this.dataService.listItemsByPk(pk)
return new SampleDataListEntity(res as SampleDataListEntity)
}
async searchData( searchDto: SearchDto) {
return await this.sampleService.searchData(searchDto)
}
}