diff --git a/src/rate-plans/enums/pagination/errors.ts b/src/rate-plans/enums/pagination/errors.ts new file mode 100644 index 0000000..161c9f7 --- /dev/null +++ b/src/rate-plans/enums/pagination/errors.ts @@ -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', +}; diff --git a/src/rate-plans/helpers/pagination/rate-plans.ts b/src/rate-plans/helpers/pagination/rate-plans.ts index 888ba51..4a71bfb 100644 --- a/src/rate-plans/helpers/pagination/rate-plans.ts +++ b/src/rate-plans/helpers/pagination/rate-plans.ts @@ -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.'; diff --git a/src/rate-plans/rate-plans.service.ts b/src/rate-plans/rate-plans.service.ts index c8ce8dd..ed38aa4 100644 --- a/src/rate-plans/rate-plans.service.ts +++ b/src/rate-plans/rate-plans.service.ts @@ -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; @@ -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 @@ -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( @@ -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 ---