-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from andresWeitzel/feature-04-add-rate-plans-de…
…lete feature-04-add-rate-plans-delete
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable prettier/prettier */ | ||
//External | ||
import { Resolver, Args, Mutation } from '@nestjs/graphql'; | ||
import { ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { Delete } from '@nestjs/common'; | ||
//Models | ||
import { RatePlans } from '.././models/rate-plans.entity'; | ||
//Service | ||
import { DeleteRatePlansService } from '.././services/delete.service'; | ||
//const-vars | ||
let ratePlanResult: any; | ||
let msgResponse: string; | ||
let msgLog: string; | ||
|
||
//Check | ||
@Resolver() | ||
@ApiTags('DeleteRatePlansResolver') | ||
export class DeleteRatePlansResolver { | ||
constructor(private deletePlansService: DeleteRatePlansService) {} | ||
|
||
/** | ||
* @description function for delete a rate plan to database | ||
* @param {number} inputId number type | ||
* @returns a response with the rate plan object and status code | ||
*/ | ||
@Delete('/id/:inputId') | ||
@ApiOperation({ summary: 'Delete a rate plans' }) | ||
@Mutation(() => RatePlans, { name: 'deleteRatePlan' }) | ||
async deleteRatePlan( | ||
@Args({ name: 'inputId' }) inputId: number, | ||
): Promise<string | any> { | ||
try { | ||
msgResponse = null; | ||
msgLog = null; | ||
|
||
// --- start with database operations --- | ||
ratePlanResult = await this.deletePlansService.delete(inputId); | ||
if (ratePlanResult != null || ratePlanResult != undefined) { | ||
return `The Rate plan with the id ${inputId} has been successfully deleted`; | ||
} | ||
// --- end with database operations --- | ||
} catch (error) { | ||
msgResponse = | ||
'ERROR in deleteRatePlan function for DeleteRatePlansResolver class'; | ||
msgLog = msgResponse + `Caused by ${error}`; | ||
console.log(msgLog); | ||
return msgResponse; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable prettier/prettier */ | ||
//External | ||
import { Injectable, Inject } from '@nestjs/common'; | ||
import { Repository } from 'typeorm'; | ||
//Models | ||
import { RatePlans } from '../models/rate-plans.entity'; | ||
//Const-vars | ||
let deletedRatePlan: any; | ||
let ratePlanOld:any; | ||
let msgResponse: string; | ||
let msgLog: string; | ||
|
||
/** | ||
* @description Class service for delete a rate plan | ||
* @param {Object} event Object type | ||
*/ | ||
@Injectable() | ||
export class DeleteRatePlansService { | ||
constructor( | ||
@Inject('RATE_PLANS_REPOSITORY') | ||
private ratePlansRepository: Repository<RatePlans>, | ||
) {} | ||
|
||
/** | ||
* @description function to delete a rate plan | ||
* @param {number} inputId number type | ||
* @returns an object with the ratePlan | ||
*/ | ||
async delete(inputId: number): Promise<string | any> { | ||
try { | ||
msgResponse = null; | ||
msgLog = null; | ||
|
||
ratePlanOld = this.ratePlansRepository.findOne(({ | ||
where: { | ||
id: inputId, | ||
}, | ||
})); | ||
|
||
deletedRatePlan = this.ratePlansRepository.remove(ratePlanOld); | ||
|
||
return deletedRatePlan; | ||
|
||
} catch (error) { | ||
msgResponse = 'ERROR in delete function for DeleteRatePlansService class'; | ||
msgLog = msgResponse + `Caused by ${error}`; | ||
console.log(msgLog); | ||
return msgResponse; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters