Skip to content

Commit

Permalink
Merge pull request #5 from andresWeitzel/feature-02-add-rate-plans-en…
Browse files Browse the repository at this point in the history
…dpoints

feature-02-add-rate-plans-endpoints
  • Loading branch information
andresWeitzel authored Nov 5, 2023
2 parents 0bdba69 + b9eba11 commit 943aa57
Show file tree
Hide file tree
Showing 13 changed files with 423 additions and 195 deletions.
3 changes: 1 addition & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
}
export class AppService {}
1 change: 0 additions & 1 deletion src/database/database.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ import { databaseProviders } from './database.providers';
exports: [...databaseProviders],
})
export class DatabaseModule {}

6 changes: 3 additions & 3 deletions src/database/database.providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable prettier/prettier */
import 'dotenv/config';
import 'dotenv/config';
import { DataSource } from 'typeorm';
//Const-vars
let dataSource;
Expand All @@ -12,7 +12,7 @@ export const databaseProviders = [
dataSource = new DataSource({
type: 'mysql',
host: process.env.DATABASE_HOST,
port: 3306 ,
port: 3306,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
Expand All @@ -27,4 +27,4 @@ export const databaseProviders = [
return dataSource.initialize();
},
},
];
];
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable prettier/prettier */
//External
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { ValidationPipe } from '@nestjs/common';
import { useContainer } from 'class-validator';
//Module
import { AppModule } from './app.module';
//Const-vars
const APOLLO_PORT_VALUE = process.env.APOLLO_PORT_ONE_VALUE || process.env.APOLLO_PORT_TWO_VALUE;
const APOLLO_PORT_VALUE =
process.env.APOLLO_PORT_ONE_VALUE || process.env.APOLLO_PORT_TWO_VALUE;

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand All @@ -25,6 +26,5 @@ async function bootstrap() {
useContainer(app.select(AppModule), { fallbackOnErrors: true });
//--end with validations--
app.listen(APOLLO_PORT_VALUE);

}
bootstrap();
94 changes: 47 additions & 47 deletions src/rate-plans/enums/class-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@
/**
* @description enum class. This enum returns the class property name, values, or length for validations
*/
export enum RatePlansProperties{
//Decimal values
DECIMAL_PRECISION_VALUE = 6,
DECIMAL_SCALE_VALUE = 3,
//id field
NAME_VALUE_FOR_ID = 'id',
MIN_LENGTH_VALUE_FOR_ID = 9999999999999,
MAX_LENGTH_VALUE_FOR_ID = 200,
//name field
NAME_VALUE_FOR_NAME = 'name',
MIN_LENGTH_VALUE_FOR_NAME = 4,
MAX_LENGTH_VALUE_FOR_NAME = 200,
//description field
NAME_VALUE_FOR_DESCRIPTION = 'description',
MIN_LENGTH_VALUE_FOR_DESCRIPTION = 4,
MAX_LENGTH_VALUE_FOR_DESCRIPTION = 500,
//version_id field
NAME_VALUE_FOR_VERSION_ID = 'version_id',
MIN_VALUE_FOR_VERSION_ID = 1,
MAX_VALUE_FOR_VERSION_ID = 9999999999999,
//version_plan field
NAME_VALUE_FOR_VERSION_PLAN = 'version_plan',
MIN_LENGTH_VALUE_FOR_VERSION_PLAN = 1,
MAX_LENGTH_VALUE_FOR_VERSION_PLAN = 20,
//status field
NAME_VALUE_FOR_STATUS = 'status',
//type_plan field
NAME_VALUE_FOR_TYPE_PLAN = 'type_plan',
MIN_LENGTH_VALUE_FOR_TYPE_PLAN = 2,
MAX_LENGTH_VALUE_FOR_TYPE_PLAN = 200,
//suscription_charge field
NAME_VALUE_FOR_SUSCRIPTION_CHARGE = 'subscription_charge',
DEFAULT_VALUE_FOR_SUSCRIPTION_CHARGE = 2.99,
MIN_VALUE_FOR_SUSCRIPTION_CHARGE = 0.99,
MAX_VALUE_FOR_SUSCRIPTION_CHARGE = 100.0,
//number_of_tiers field
NAME_VALUE_FOR_NUMBER_OF_TIERS = 'number_of_tiers',
MIN_VALUE_FOR_NUMBER_OF_TIERS = 1,
MAX_VALUE_FOR_NUMBER_OF_TIERS = 10,
//creation_date field
NAME_VALUE_FOR_CREATION_DATE = 'creation_date',
//update_date field
NAME_VALUE_FOR_UPDATE_DATE = 'update_date',
//for dates
MIN_VALUE_FOR_CREATION_UPDATE_DATE = 10,
MAX_VALUE_FOR_CREATION_UPDATE_DATE = 40,
}
export enum RatePlansProperties {
//Decimal values
DECIMAL_PRECISION_VALUE = 6,
DECIMAL_SCALE_VALUE = 3,
//id field
NAME_VALUE_FOR_ID = 'id',
MIN_LENGTH_VALUE_FOR_ID = 9999999999999,
MAX_LENGTH_VALUE_FOR_ID = 200,
//name field
NAME_VALUE_FOR_NAME = 'name',
MIN_LENGTH_VALUE_FOR_NAME = 4,
MAX_LENGTH_VALUE_FOR_NAME = 200,
//description field
NAME_VALUE_FOR_DESCRIPTION = 'description',
MIN_LENGTH_VALUE_FOR_DESCRIPTION = 4,
MAX_LENGTH_VALUE_FOR_DESCRIPTION = 500,
//version_id field
NAME_VALUE_FOR_VERSION_ID = 'version_id',
MIN_VALUE_FOR_VERSION_ID = 1,
MAX_VALUE_FOR_VERSION_ID = 9999999999999,
//version_plan field
NAME_VALUE_FOR_VERSION_PLAN = 'version_plan',
MIN_LENGTH_VALUE_FOR_VERSION_PLAN = 1,
MAX_LENGTH_VALUE_FOR_VERSION_PLAN = 20,
//status field
NAME_VALUE_FOR_STATUS = 'status',
//type_plan field
NAME_VALUE_FOR_TYPE_PLAN = 'type_plan',
MIN_LENGTH_VALUE_FOR_TYPE_PLAN = 2,
MAX_LENGTH_VALUE_FOR_TYPE_PLAN = 200,
//suscription_charge field
NAME_VALUE_FOR_SUSCRIPTION_CHARGE = 'subscription_charge',
DEFAULT_VALUE_FOR_SUSCRIPTION_CHARGE = 2.99,
MIN_VALUE_FOR_SUSCRIPTION_CHARGE = 0.99,
MAX_VALUE_FOR_SUSCRIPTION_CHARGE = 100.0,
//number_of_tiers field
NAME_VALUE_FOR_NUMBER_OF_TIERS = 'number_of_tiers',
MIN_VALUE_FOR_NUMBER_OF_TIERS = 1,
MAX_VALUE_FOR_NUMBER_OF_TIERS = 10,
//creation_date field
NAME_VALUE_FOR_CREATION_DATE = 'creation_date',
//update_date field
NAME_VALUE_FOR_UPDATE_DATE = 'update_date',
//for dates
MIN_VALUE_FOR_CREATION_UPDATE_DATE = 10,
MAX_VALUE_FOR_CREATION_UPDATE_DATE = 40,
}
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',
};
10 changes: 5 additions & 5 deletions src/rate-plans/enums/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* @description enum class. This enum returns only published rate plans with the Published status value. Published rate plans are approved and available for use by devices.
*/
export enum Status{
PUBLISHED= 'Published',
ACTIVE= 'Active',
INACTIVE='Inactive'
}
export enum Status {
PUBLISHED = 'Published',
ACTIVE = 'Active',
INACTIVE = 'Inactive',
}
98 changes: 98 additions & 0 deletions src/rate-plans/helpers/pagination/rate-plans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//Const-vars
let msgResponse: string;
let msgLog: string;

/**
* @description checks the order by value of the query string param to assign a field value
* @param {String} orderBy String type
* @returns a string with the field value or null
*/
export const checkOrderBy = async (orderBy: string) => {
try {
msgResponse = null;
msgLog = null;

switch (orderBy.toLowerCase()) {
case 'id':
orderBy = 'id';
break;
case 'nombre':
case 'name':
orderBy = 'name';
break;
case 'descripcion':
case 'description':
orderBy = 'description';
break;
case 'version_id':
case 'versionid':
orderBy = 'version_id';
break;
case 'version_plan':
case 'versionplan':
orderBy = 'version_plan';
break;
case 'status':
orderBy = 'status';
break;
case 'type_plan':
case 'typeplan':
orderBy = 'type_plan';
break;
case 'subscription_charge':
case 'subscriptioncharge':
orderBy = 'subscription_charge';
break;
case 'number_of_tiers':
case 'numberoftiers':
orderBy = 'number_of_tiers';
break;
case 'creation_date':
case 'creationdate':
orderBy = 'creation_date';
break;
case 'update_date':
case 'updatedate':
orderBy = 'update_date';
break;
default:
orderBy = null;
}
console.log(orderBy);
return orderBy;
} catch (error) {
msgResponse = 'ERROR in checkOrderBy() helper function.';
msgLog = msgResponse + `Caused by ${error}`;
console.log(msgLog);
return null;
}
};

/**
* @description checks the order at value of the query string param to assign a field value
* @param {String} orderAt String type
* @returns a string with the field value or null
*/
export const checkOrderAt = async (orderAt: string) => {
try {
msgResponse = null;
msgLog = null;

switch (orderAt.toLowerCase()) {
case 'asc':
orderAt = 'ASC';
break;
case 'desc':
orderAt = 'DESC';
break;
default:
orderAt = null;
}
return orderAt;
} catch (error) {
msgResponse = 'ERROR in checkOrderAt() helper function.';
msgLog = msgResponse + `Caused by ${error}`;
console.log(msgLog);
return null;
}
};
Loading

0 comments on commit 943aa57

Please sign in to comment.