Skip to content

Commit

Permalink
Merge pull request #244 from souravbhowmik1999/attendanceOffset
Browse files Browse the repository at this point in the history
Attendance : Set Offset on attendance module
  • Loading branch information
vaivk369 authored Jul 16, 2024
2 parents 6d1046b + a911931 commit bcaa836
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 46 deletions.
37 changes: 18 additions & 19 deletions src/adapters/hasura/services/fields.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { ErrorResponse } from "src/error-response";

@Injectable()
export class FieldsService {
constructor() {}
constructor() { }

//fields
async createFields(request:any,fieldsDto: FieldsDto) {
try{
async createFields(request: any, fieldsDto: FieldsDto) {
try {
var axios = require("axios");

//add render json object
Expand Down Expand Up @@ -54,7 +54,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand Down Expand Up @@ -124,12 +124,12 @@ export class FieldsService {
}

public async getFieldsContext(
request:any,
request: any,
tenantId: string,
context: string,
contextId: string
) {
try{
try {
var axios = require("axios");

var data = {
Expand Down Expand Up @@ -223,7 +223,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand All @@ -233,9 +233,8 @@ export class FieldsService {
}

async searchFields(request: any, tenantId: string, fieldsSearchDto: FieldsSearchDto) {
try{
try {
var axios = require("axios");

let offset = 0;
if (fieldsSearchDto.page > 1) {
offset = (fieldsSearchDto.limit) * (fieldsSearchDto.page - 1);
Expand Down Expand Up @@ -301,7 +300,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand Down Expand Up @@ -440,7 +439,7 @@ export class FieldsService {
if (payload.label) {
fieldSchema.coreSchema["title"] = payload.label;
}

if (payload.pattern) {
fieldSchema.coreSchema["pattern"] = payload.pattern;
}
Expand Down Expand Up @@ -474,7 +473,7 @@ export class FieldsService {

//field values
async createFieldValues(request: any, fieldValuesDto: FieldValuesDto) {
try{
try {
var axios = require("axios");

let query = "";
Expand Down Expand Up @@ -511,7 +510,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand Down Expand Up @@ -637,8 +636,8 @@ export class FieldsService {
return response;
}

async searchFieldValues(request:any, fieldValuesSearchDto: FieldValuesSearchDto) {
try{
async searchFieldValues(request: any, fieldValuesSearchDto: FieldValuesSearchDto) {
try {
var axios = require("axios");

let offset = 0;
Expand Down Expand Up @@ -689,7 +688,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand All @@ -698,8 +697,8 @@ export class FieldsService {
}
}

async searchFieldValuesFilter(request:any,filter: any) {
try{
async searchFieldValuesFilter(request: any, filter: any) {
try {
let obj_filter = [];
Object.keys(filter).forEach((item) => {
Object.keys(filter[item]).forEach((e) => {
Expand Down Expand Up @@ -739,7 +738,7 @@ export class FieldsService {

const response = await axios(config);
return response;
}catch (e) {
} catch (e) {
console.error(e);
return new ErrorResponse({
errorCode: "400",
Expand Down
31 changes: 8 additions & 23 deletions src/adapters/postgres/attendance-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,10 @@ export class PostgresAttendanceService {

async searchAttendance(tenantId: string, request: any, attendanceSearchDto: AttendanceSearchDto) {
try {
let { limit, page, filters, facets, sort } = attendanceSearchDto;
// Set default limit to 0 if not provided
if (!limit) {
limit = 20;
}

let offset = 0;
// Calculate offset based on page number
if (page > 1) {
offset = (limit) * (page - 1);
}
let { limit, offset, filters, facets, sort } = attendanceSearchDto;
// Set default limit 0 and offset 20 if not provided
limit = limit ? limit : 20;
offset = offset ? offset : 0;

// Get column names from metadata
const attendanceKeys = this.attendanceRepository.metadata.columns.map((column) => column.propertyName);
Expand Down Expand Up @@ -684,17 +677,9 @@ export class PostgresAttendanceService {
attendanceSearchDto: AttendanceDateDto
) {
try {


let { limit, page } = attendanceSearchDto;
if (!limit) {
limit = '0';
}

let offset = 0;
if (page > 1) {
offset = parseInt(limit) * (page - 1);
}
let { limit, offset } = attendanceSearchDto;
limit = limit ? limit : 0;
offset = offset ? offset : 0;

const fromDate = new Date(attendanceSearchDto.fromDate);
const toDate = new Date(attendanceSearchDto.toDate);
Expand All @@ -713,7 +698,7 @@ export class PostgresAttendanceService {

const [results, totalCount] = await this.attendanceRepository.findAndCount({
where: whereClause,
take: parseInt(limit),
take: limit,
skip: offset,
});

Expand Down
6 changes: 3 additions & 3 deletions src/attendance/dto/attendance-date.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ export class AttendanceDateDto {
toDate: Date;

@ApiProperty({
type: String,
type: Number,
description: "Limit",
})
limit: string;
limit: number;

@ApiProperty({
type: Number,
description: "number",
})
page: number;
offset: number;

@ApiProperty({
type: Object,
Expand Down
2 changes: 1 addition & 1 deletion src/attendance/dto/attendance-search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class AttendanceSearchDto {
type: Number,
description: "number",
})
page: number;
offset: number;

@ApiPropertyOptional({
type: AttendanceFiltersDto,
Expand Down

0 comments on commit bcaa836

Please sign in to comment.