Skip to content

Commit

Permalink
Improved log managment on user-mgnt dbhelper
Browse files Browse the repository at this point in the history
  • Loading branch information
mushrafulhoque-dsi committed Jun 17, 2019
1 parent 05a2ae1 commit 969e4b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
27 changes: 18 additions & 9 deletions packages/search/src/elasticsearch/dbhelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@ export const indexComposition = async (
} catch (err) {
// tslint:disable-next-line:no-console
console.log(err)
throw err
}
}

export const updateComposition = async (id: string, body: ICompositionBody) => {
const response = await client.update({
index: 'ocrvs',
type: 'compositions',
id,
body: {
doc: body
}
})
try {
const response = await client.update({
index: 'ocrvs',
type: 'compositions',
id,
body: {
doc: body
}
})

return response
return response
} catch (err) {
// tslint:disable-next-line:no-console
console.log(err)
throw err
}
}

export const searchComposition = async (body: ICompositionBody) => {
Expand All @@ -46,6 +53,7 @@ export const searchComposition = async (body: ICompositionBody) => {
} catch (err) {
// tslint:disable-next-line:no-console
console.log(err)
return null
}
}

Expand All @@ -66,5 +74,6 @@ export const searchByCompositionId = async (compositionId: string) => {
} catch (err) {
// tslint:disable-next-line:no-console
console.log(err)
return null
}
}
12 changes: 4 additions & 8 deletions packages/search/src/elasticsearch/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ export async function detectDuplicates(
}

export async function getCreatedBy(compositionId: string) {
let results
try {
results = await searchByCompositionId(compositionId)
} catch (error) {
console.log(error)
}
const results = await searchByCompositionId(compositionId)
const result =
results &&
results.hits.hits &&
(results.hits.hits[0] && (results.hits.hits[0]._source as ICompositionBody))

Expand All @@ -83,9 +79,9 @@ export async function getCreatedBy(compositionId: string) {

function findDuplicateIds(
compositionIdentifier: string,
results: SearchResponse<{}>
results: SearchResponse<{}> | null
) {
const hits = results.hits.hits
const hits = (results && results.hits.hits) || []
return hits
.filter(
hit =>
Expand Down

0 comments on commit 969e4b2

Please sign in to comment.