Skip to content

Commit

Permalink
Merge pull request #90 from souravbhowmik1999/loggerIntregration
Browse files Browse the repository at this point in the history
PS-2365 User service logger implementation
  • Loading branch information
Shubham4026 authored Nov 25, 2024
2 parents 3609b31 + dcc88b3 commit e8618e2
Show file tree
Hide file tree
Showing 14 changed files with 968 additions and 235 deletions.
282 changes: 279 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"rxjs": "^7.2.0",
"swagger-ui-express": "^4.3.0",
"templates.js": "^0.3.11",
"typeorm": "^0.3.20"
"typeorm": "^0.3.20",
"winston": "^3.11.0"
},
"devDependencies": {
"@nestjs/cli": "^8.0.0",
Expand Down Expand Up @@ -104,4 +105,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
108 changes: 82 additions & 26 deletions src/adapters/postgres/cohort-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PostgresAcademicYearService } from "./academicyears-adapter";
import { API_RESPONSES } from "@utils/response.messages";
import { CohortAcademicYear } from "src/cohortAcademicYear/entities/cohortAcademicYear.entity";
import { PostgresCohortMembersService } from "./cohortMembers-adapter";
import { LoggerUtil } from "src/common/logger/LoggerUtil";

@Injectable()
export class PostgresCohortService {
Expand Down Expand Up @@ -73,8 +74,8 @@ export class PostgresCohortService {
return APIResponse.error(
res,
apiId,
"BAD_REQUEST",
`No Cohort Found for this cohort ID`,
API_RESPONSES.BAD_REQUEST,
API_RESPONSES.COHORT_NOT_FOUND,
HttpStatus.BAD_REQUEST
);
}
Expand All @@ -85,11 +86,16 @@ export class PostgresCohortService {
return this.handleCohortDataResponse(cohorts, res, apiId);
}
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
res,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand All @@ -109,13 +115,15 @@ export class PostgresCohortService {
};
result.cohortData.push(cohortData);
}

LoggerUtil.log(
API_RESPONSES.COHORT_DATA_RESPONSE,
)
return APIResponse.success(
res,
apiId,
result,
HttpStatus.OK,
"Cohort list fetched successfully"
API_RESPONSES.COHORT_LIST,
);
}

Expand All @@ -138,14 +146,18 @@ export class PostgresCohortService {
),
};
resultDataList.push(resultData);

LoggerUtil.log(
API_RESPONSES.CHILD_DATA,
)
}

return APIResponse.success(
res,
apiId,
resultDataList,
HttpStatus.OK,
"Cohort hierarchy fetched successfully"
API_RESPONSES.COHORT_HIERARCHY,
);
}

Expand Down Expand Up @@ -269,6 +281,10 @@ export class PostgresCohortService {
};
});

LoggerUtil.log(
API_RESPONSES.COHORT_FIELD_DETAILS,
)

result = await Promise.all(result);
return result;
}
Expand Down Expand Up @@ -354,8 +370,8 @@ export class PostgresCohortService {
return APIResponse.error(
res,
apiId,
`Cohort name already exist.Please provide another name.`,
`Cohort already exists`,
API_RESPONSES.COHORT_NAME_EXIST,
API_RESPONSES.COHORT_EXISTS,
HttpStatus.CONFLICT
);
}
Expand Down Expand Up @@ -408,19 +424,27 @@ export class PostgresCohortService {
...response,
academicYearId: academicYearId,
});
LoggerUtil.log(
API_RESPONSES.CREATE_COHORT,
)
return APIResponse.success(
res,
apiId,
resBody,
HttpStatus.CREATED,
"Cohort Created Successfully."
API_RESPONSES.CREATE_COHORT
);
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
res,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down Expand Up @@ -592,12 +616,15 @@ export class PostgresCohortService {
}
}

LoggerUtil.log(
API_RESPONSES.COHORT_UPDATED_SUCCESSFULLY,
)
return APIResponse.success(
res,
apiId,
response?.affected,
HttpStatus.OK,
"Cohort updated successfully."
API_RESPONSES.COHORT_UPDATED_SUCCESSFULLY
);
} else {
return APIResponse.error(
Expand All @@ -609,11 +636,16 @@ export class PostgresCohortService {
);
}
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
res,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down Expand Up @@ -891,11 +923,16 @@ export class PostgresCohortService {
);
}
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
response,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down Expand Up @@ -947,11 +984,16 @@ export class PostgresCohortService {
);
}
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
response,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down Expand Up @@ -1002,6 +1044,10 @@ export class PostgresCohortService {
});
}

LoggerUtil.log(
API_RESPONSES.COHORT_HIERARCHY,
)

return hierarchy;
}

Expand All @@ -1019,7 +1065,7 @@ export class PostgresCohortService {
return APIResponse.error(
res,
apiId,
"BAD_REQUEST",
API_RESPONSES.BAD_REQUEST,
API_RESPONSES.USER_NOT_IN_ACADEMIC_YEAR,
HttpStatus.BAD_REQUEST
);
Expand All @@ -1032,7 +1078,7 @@ export class PostgresCohortService {
return APIResponse.error(
res,
apiId,
"BAD_REQUEST",
API_RESPONSES.BAD_REQUEST,
`No Cohort Found for this User ID`,
HttpStatus.BAD_REQUEST
);
Expand Down Expand Up @@ -1067,11 +1113,16 @@ export class PostgresCohortService {
"Cohort list fetched successfully"
);
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
res,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down Expand Up @@ -1122,14 +1173,19 @@ export class PostgresCohortService {
apiId,
resultDataList,
HttpStatus.OK,
"Cohort hierarchy fetched successfully"
API_RESPONSES.COHORT_HIERARCHY
);
} catch (error) {
const errorMessage = error.message || "Internal server error";
LoggerUtil.error(
`${API_RESPONSES.SERVER_ERROR}`,
`Error: ${error.message}`,
apiId
)
const errorMessage = error.message || API_RESPONSES.SERVER_ERROR;
return APIResponse.error(
res,
apiId,
"Internal Server Error",
API_RESPONSES.SERVER_ERROR,
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
Expand Down
Loading

0 comments on commit e8618e2

Please sign in to comment.