-
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 #1 from OpusCapita/feature/refactor
service refactor
- Loading branch information
Showing
22 changed files
with
246 additions
and
779 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 |
---|---|---|
@@ -1,50 +1,30 @@ | ||
import { checkIfTypeIsString, checkRequestQueryParamsForGetOrRemove } from "../../../_helpers/RequestParamsHelper"; | ||
import { checkIfTypeIsString } from "../../../_common/utils/Request.utils"; | ||
import { checkFetchingRequestQueryParamsForGetOrDelete } from "../../../_common/utils/FetchingRequest.utils"; | ||
|
||
import Credential from '../../../_common/models/Credential.model'; | ||
import { HttpRequest } from "@azure/functions"; | ||
import { throwIfDatabaseResourceNotExists } from "../../../_common/utils/DatabaseResponse.utils"; | ||
|
||
export const get = async (req: HttpRequest) => { | ||
const { id_connection } = req.query; | ||
|
||
try { | ||
// Chack body params | ||
checkRequestQueryParamsForGetOrRemove(id_connection); | ||
// Chack body params | ||
checkFetchingRequestQueryParamsForGetOrDelete(id_connection); | ||
|
||
// Check connection | ||
checkIfTypeIsString(id_connection, 'id_connection'); | ||
// Check connection | ||
checkIfTypeIsString(id_connection, 'id_connection'); | ||
|
||
// Check if row with id_connection already exists | ||
const response_from_db = await Credential.get(id_connection); | ||
// Check if row with id_connection already exists | ||
const response_from_db = await Credential.get(id_connection); | ||
|
||
if (!response_from_db) { | ||
return { | ||
status: 404, | ||
body: { | ||
status: 'Not found', | ||
description: 'Resource with the provided id_connection not exists.' | ||
} | ||
}; | ||
} | ||
// If not exists throw error 404 - Not found | ||
throwIfDatabaseResourceNotExists(response_from_db, 'id_connection'); | ||
|
||
return { | ||
status: 200, | ||
body: { | ||
status: 'OK', | ||
payload: response_from_db | ||
} | ||
}; | ||
} | ||
catch (error) { | ||
if (error.status) { | ||
return error; | ||
return { | ||
status: 200, | ||
body: { | ||
status: 'OK', | ||
payload: response_from_db | ||
} | ||
|
||
return { | ||
status: 500, | ||
body: { | ||
status: 'Internal error', | ||
description: 'An unexpected error occurred. Please try again later.' | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
} |
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
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
Oops, something went wrong.