Skip to content

Commit

Permalink
Updated endpoints and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
andresWeitzel committed Nov 5, 2023
1 parent 91623e2 commit b9eba11
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
21 changes: 21 additions & 0 deletions src/rate-plans/enums/pagination/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @description pagination errors names
* @returns the name value of the pagination error
* @example
*/
export const paginationNameValueError = {
ORDER_BY_NAME_VALUE_ERROR: 'OrderByNameValueError',
ORDER_AT_NAME_VALUE_ERROR: 'OrderAtNameValueError',
};

/**
* @description pagination errors description
* @returns the description value of the pagination error
* @example
*/
export const paginationDescriptionValueError = {
ORDER_BY_DESCRIPTION_VALUE_ERROR:
'It is not possible to apply sorting based on the requested orderBy value. Invalid field',
ORDER_AT_DESCRIPTION_VALUE_ERROR:
'It is not possible to apply sorting based on the requested orderAt value. Invalid field',
};
1 change: 1 addition & 0 deletions src/rate-plans/helpers/pagination/rate-plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const checkOrderBy = async (orderBy: string) => {
default:
orderBy = null;
}
console.log(orderBy);
return orderBy;
} catch (error) {
msgResponse = 'ERROR in checkOrderBy() helper function.';
Expand Down
47 changes: 24 additions & 23 deletions src/rate-plans/rate-plans.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import { Repository } from 'typeorm';
import { RatePlans } from './models/rate-plans.entity';
import { RatePlansDTO } from './models/rate-plans.dto';
//Enums
import { paginationNameValueError } from './enums/pagination/errors';
//Helpers
import { validateObject } from './helpers/models/validateObject';
import { checkOrderBy } from './helpers/pagination/rate-plans';
//Const-vars
import { checkOrderAt, checkOrderBy } from './helpers/pagination/rate-plans';
//const
const ORDER_BY_NAME_VALUE_ERROR =
paginationNameValueError.ORDER_BY_NAME_VALUE_ERROR;
const ORDER_AT_NAME_VALUE_ERROR =
paginationNameValueError.ORDER_AT_NAME_VALUE_ERROR;
//vars
let checkObj: any;
let ratePlansList: RatePlans[];
let ratePlanObj: RatePlans;
Expand All @@ -22,7 +28,6 @@ let pageSize: number;
let pageNro: number;
let orderBy: string;
let orderAt: string;

/**
* @description Rate plants service for all crud operations
* @param {Object} event Object type
Expand Down Expand Up @@ -99,10 +104,10 @@ export class RatePlansService {

/**
* @description Service to get a paginated listing of all rate plans
* @param {number} pageNro number type
* @param {number} pageSize number type
* @param {string} orderBy string type
* @param {string} orderAt string type
* @param {number} pageNroParam number type
* @param {number} pageSizeParam number type
* @param {string} orderByParam string type
* @param {string} orderAtParam string type
* @returns an object with the products paginated list
*/
async getAllRatePlans(
Expand All @@ -121,28 +126,24 @@ export class RatePlansService {
msgLog = null;

//-- start with pagination ---
pageNro =
pageNroParam == (null || undefined || NaN) ? pageNro : pageNroParam;
pageNro = pageNroParam != (null && undefined) ? pageNroParam : pageNro;
pageSize =
pageSizeParam == (null || undefined || NaN) ? pageSize : pageSizeParam;
orderBy =
orderByParam == (null || undefined || '') ? orderBy : orderByParam;
orderAt =
orderAtParam == (null || undefined || '') ? orderAt : orderAtParam;
pageSizeParam != (null && undefined) ? pageSizeParam : pageSize;
orderBy = orderByParam != (null && undefined) ? orderByParam : orderBy;
orderAt = orderAtParam != (null && undefined) ? orderAtParam : orderAt;

// orderBy = await checkOrderBy(orderBy);
orderBy = await checkOrderBy(orderBy);

// if(orderBy == (null || undefined)){
// return ORDER_BY_NAME_VALUE_ERROR;
// }
if (orderBy == (null || undefined)) {
return ORDER_BY_NAME_VALUE_ERROR;
}

// orderAt = await checkOrderAt(orderAt);
orderAt = await checkOrderAt(orderAt);

// if(orderAt == (undefined || null)){
// return ORDER_AT_NAME_VALUE_ERROR;
// }
if (orderAt == (undefined || null)) {
return ORDER_AT_NAME_VALUE_ERROR;
}

// order = [[orderBy, orderAt]];
//-- end with pagination ---

// --- start with database operations ---
Expand Down

0 comments on commit b9eba11

Please sign in to comment.