import { Logger, Get, Query, Delete, Post, Body, Param, UseGuards } from "@nestjs/common";
import { AuthGuard } from "@nestjs/passport";
import { AuthModule } from "src/auth/auth.module";
import { FindManyOptions } from "typeorm";
import { PcdTransactionService } from "./pcd-transaction.service";

export class PcdTransactionController<T> {

    private logger = new Logger('PcdTransactionController'); // for logging

    constructor(
        private service: PcdTransactionService<T>
    ) { }
    @UseGuards(AuthGuard())
    @Get()
    async findList(@Query() filter: FindManyOptions, ): Promise<T[]> {
        return await this.service.findList(filter);
    }

    @Get('/:id')
    async findOne(@Query() filter: FindManyOptions,@Param('id') id: string , ): Promise<T> {
        return await this.service.findOne(filter, id);
    }

    @Post()
    async createOne(@Body() body: T, ): Promise<T> {
        return await this.service.createOne(body,);
    }

    @Delete('/:id')
    async delete(@Query() filter: FindManyOptions,@Param('id') id: string , ): Promise<any> {
        return await this.service.deleteOne(filter,id, );
    }
}