Skip to content

Commit

Permalink
Added minimal variation for payload-decoder.controller.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
fcv-iteratorIt committed Oct 1, 2024
1 parent 9de635e commit 361992c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/controllers/admin-controller/payload-decoder.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { CreatePayloadDecoderDto } from "@dto/create-payload-decoder.dto";
import { DeleteResponseDto } from "@dto/delete-application-response.dto";
import { AuthenticatedRequest } from "@dto/internal/authenticated-request";
import { ListAllPayloadDecoderDto } from "@dto/list-all-payload-decoder.dto";
import { ListAllPayloadDecoderResponseDto } from "@dto/list-all-payload-decoders-response.dto";
import {
ListAllMinimalPayloadDecoderResponseDto,
ListAllPayloadDecoderResponseDto,
} from "@dto/list-all-payload-decoders-response.dto";
import { UpdatePayloadDecoderDto } from "@dto/update-payload-decoder.dto";
import { PayloadDecoder } from "@entities/payload-decoder.entity";
import { ErrorCodes } from "@enum/error-codes.enum";
Expand All @@ -49,9 +52,16 @@ import { ApiAuth } from "@auth/swagger-auth-decorator";
@ApiForbiddenResponse()
@ApiUnauthorizedResponse()
export class PayloadDecoderController {
private readonly logger = new Logger(PayloadDecoderController.name);

constructor(private payloadDecoderService: PayloadDecoderService) {}

private readonly logger = new Logger(PayloadDecoderController.name);
@Get("minimal")
@ApiOperation({ summary: "Get all Payload Decoders names" })
@Read()
async getMinimal(): Promise<ListAllMinimalPayloadDecoderResponseDto> {
return await this.payloadDecoderService.getMinimal();
}

@Get(":id")
@ApiOperation({ summary: "Find one Payload Decoder by id" })
Expand Down
5 changes: 5 additions & 0 deletions src/entities/dto/list-all-payload-decoders-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ListAllEntitiesResponseDto } from "@dto/list-all-entities-response.dto";
import { PayloadDecoder } from "@entities/payload-decoder.entity";
import { PickType } from "@nestjs/swagger";

export class ListAllPayloadDecoderResponseDto extends ListAllEntitiesResponseDto<PayloadDecoder> {}

export class ListAllMinimalPayloadDecoderResponseDto extends ListAllEntitiesResponseDto<MinimalPayloadDecoder> {}

export class MinimalPayloadDecoder extends PickType(PayloadDecoder, ["id", "name"]) {}
32 changes: 22 additions & 10 deletions src/services/data-management/payload-decoder.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { DeleteResult, In, Repository } from "typeorm";
import { DeleteResult, Repository } from "typeorm";

import { CreatePayloadDecoderDto } from "@dto/create-payload-decoder.dto";
import { ListAllEntitiesDto } from "@dto/list-all-entities.dto";
import { ListAllPayloadDecoderResponseDto } from "@dto/list-all-payload-decoders-response.dto";
import {
ListAllMinimalPayloadDecoderResponseDto,
ListAllPayloadDecoderResponseDto,
} from "@dto/list-all-payload-decoders-response.dto";
import { UpdatePayloadDecoderDto } from "@dto/update-payload-decoder.dto";
import { ErrorCodes } from "@entities/enum/error-codes.enum";
import { PayloadDecoder } from "@entities/payload-decoder.entity";
Expand All @@ -28,14 +31,13 @@ export class PayloadDecoderService {
});
}

private getSorting(query: ListAllEntitiesDto) {
const sorting: { [id: string]: string | number } = {};
if (query?.orderOn != null && (query.orderOn == "id" || query.orderOn == "name")) {
sorting[query.orderOn] = query.sort.toLocaleUpperCase();
} else {
sorting["id"] = "ASC";
}
return sorting;
async getMinimal(): Promise<ListAllMinimalPayloadDecoderResponseDto> {
const payloadDecoders = (await this.payloadDecoderRepository.find()).map(d => ({ id: d.id, name: d.name }));

return {
data: payloadDecoders,
count: payloadDecoders.length,
};
}

async findAndCountWithPagination(
Expand Down Expand Up @@ -80,6 +82,16 @@ export class PayloadDecoderService {
return await this.payloadDecoderRepository.delete(id);
}

private getSorting(query: ListAllEntitiesDto) {
const sorting: { [id: string]: string | number } = {};
if (query?.orderOn != null && (query.orderOn == "id" || query.orderOn == "name")) {
sorting[query.orderOn] = query.sort.toLocaleUpperCase();
} else {
sorting["id"] = "ASC";
}
return sorting;
}

private async mapDtoToPayloadDecoder(createDto: CreatePayloadDecoderDto, newPayloadDecoder: PayloadDecoder) {
newPayloadDecoder.name = createDto.name;
try {
Expand Down

0 comments on commit 361992c

Please sign in to comment.