Skip to content

Commit

Permalink
Merge pull request #153 from Dhanashree-Patil95/change
Browse files Browse the repository at this point in the history
Task:PS-338-chore[change in response structure for list API]
  • Loading branch information
vaivk369 authored May 9, 2024
2 parents f4ea75d + a2b04f1 commit 6800b22
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 46 deletions.
6 changes: 2 additions & 4 deletions src/adapters/postgres/attendance-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,13 @@ export class PostgresAttendanceService {

// Process the data to calculate counts based on facets
const tree = await this.facetedSearch({ data: attendanceList, facets: facetFields });
// const result = Object.entries(tree).map(([key, value]) => ({ [key]: value }));

let result = [];
let result = {};
// Process the data to calculate counts based on facets
for (const facet of facetFields) {
const { field } = facet;
const tree = await this.facetedSearch({ data: attendanceList, facets: [facet] });
const formattedData = Object.entries(tree[field]).map(([key, value]) => ({ [key]: value }));
result.push({ [field]: formattedData }); // Modified the structure here
result[field] = tree[field];
}


Expand Down
42 changes: 0 additions & 42 deletions src/attendance/attendance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,46 +174,4 @@ export class AttendanceController {
return response.status(result.statusCode).json(result);
}

@Post("/average-report")
@ApiBasicAuth("access-token")
@ApiOkResponse({ description: "Average attendance Report" })
@ApiBadRequestResponse({ description: "Bad Request" })
@ApiInternalServerErrorResponse({ description: "Internal Server error" })
@ApiBody({ type: AttendanceStatsDto })
@SerializeOptions({
strategy: "excludeAll",
})
@UsePipes(ValidationPipe)
public async report(
@Headers() headers,
@Req() request: Request,
@Res() response: Response,
@Body() attendanceStatsDto: AttendanceStatsDto
) {
let tenantid = headers["tenantid"];

const result = await this.attendaceAdapter.buildAttenceAdapter().attendanceReport(
attendanceStatsDto
);
return response.status(result.statusCode).json(result);
}

/** No longer required in Shiksha 2.0 */
/*
@Get("usersegment/:attendance")
@UseInterceptors(ClassSerializerInterceptor)
// @ApiBasicAuth("access-token")
@ApiOkResponse({ description: " Ok." })
@ApiForbiddenResponse({ description: "Forbidden" })
@ApiQuery({ name: "groupId", required: false })
@ApiQuery({ name: "date" })
public async userSegment(
@Query("groupId") groupId: string,
@Param("attendance") attendance: string,
@Query("date") date: string,
@Req() request: Request
) {
return await this.service.userSegment(groupId, attendance, date, request);
}
*/
}
15 changes: 15 additions & 0 deletions src/attendance/dto/attendance-search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@
import { CohortMembersDto } from "src/cohortMembers/dto/cohortMembers.dto";
import { Type } from "class-transformer";


@ValidatorConstraint({ name: 'isNotAfterFromDate', async: false })
export class IsFromDateBeforeToDateConstraint implements ValidatorConstraintInterface {
validate(fromDate: Date, args: ValidationArguments) {
const toDate = args.object[args.constraints[0]];
const res = isSameDay(fromDate, toDate) || isBefore(fromDate, toDate);
return res
}

defaultMessage(args: ValidationArguments) {
return 'From Date must be before or equal to To Date';
}
}

export class AttendanceFiltersDto {
@ApiPropertyOptional({default:"yyyy-mm-dd"})
@IsOptional()
@Matches(/^\d{4}-\d{2}-\d{2}$/, { message: 'Please provide a valid date in the format yyyy-mm-dd' })
@Validate(IsFromDateBeforeToDateConstraint, ['toDate'])
fromDate?: Date;

@ApiPropertyOptional({default:"yyyy-mm-dd"})
Expand Down

0 comments on commit 6800b22

Please sign in to comment.