Skip to content

Commit

Permalink
Merge pull request #103 from arati-tekdi/main
Browse files Browse the repository at this point in the history
Changes for userId
  • Loading branch information
Shubham4026 authored Nov 26, 2024
2 parents e8618e2 + 7eaefe9 commit a6c01c7
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 173 deletions.
16 changes: 5 additions & 11 deletions src/adapters/cohortservicelocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@ import { Response } from "express";

export interface IServicelocatorcohort {
getCohortsDetails(requiredData, response);
createCohort(request: any, cohortDto: CohortCreateDto, response);
createCohort(cohortDto: CohortCreateDto, response);
searchCohort(
tenantid,
academicYearId,
request: any,
tenantid: string,
academicYearId: string,
cohortSearchDto: CohortSearchDto,
response
);
updateCohort(
cohortId: string,
request: any,
cohortUpdateDto: CohortUpdateDto,
response
);
updateCohortStatus(cohortId: string, request: any, response);
updateCohort(cohortId: string, cohortUpdateDto: CohortUpdateDto, response);
updateCohortStatus(cohortId: string, response, userId: string);
getCohortHierarchyData(requiredData, response);
}
44 changes: 12 additions & 32 deletions src/adapters/postgres/cohort-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class PostgresCohortService {
private readonly cohortAcademicYearService: CohortAcademicYearService,
private readonly postgresAcademicYearService: PostgresAcademicYearService,
private readonly postgresCohortMembersService: PostgresCohortMembersService
) { }
) {}

public async getCohortsDetails(requiredData, res) {
const apiId = APIID.COHORT_READ;
Expand Down Expand Up @@ -301,11 +301,7 @@ export class PostgresCohortService {
return { valid: true, fieldId: "true" };
}

public async createCohort(
request: any,
cohortCreateDto: CohortCreateDto,
res
) {
public async createCohort(cohortCreateDto: CohortCreateDto, res) {
const apiId = APIID.COHORT_CREATE;
try {
// Add validation for check both duplicate field ids exist or not
Expand Down Expand Up @@ -351,10 +347,6 @@ export class PostgresCohortService {
);
}
}

const decoded: any = jwt_decode(request.headers.authorization);
cohortCreateDto.createdBy = decoded?.sub;
cohortCreateDto.updatedBy = decoded?.sub;
cohortCreateDto.status = cohortCreateDto.status || "active";
cohortCreateDto.attendanceCaptureImage = false;

Expand Down Expand Up @@ -416,8 +408,8 @@ export class PostgresCohortService {
await this.cohortAcademicYearService.insertCohortAcademicYear(
response.cohortId,
academicYearId,
decoded?.sub,
decoded?.sub
cohortCreateDto.createdBy,
cohortCreateDto.updatedBy
);

const resBody = new ReturnResponseBody({
Expand Down Expand Up @@ -453,7 +445,6 @@ export class PostgresCohortService {

public async updateCohort(
cohortId: string,
request: any,
cohortUpdateDto: CohortUpdateDto,
res
) {
Expand All @@ -465,10 +456,6 @@ export class PostgresCohortService {
inactive: ["active", "archived"],
};
try {
const decoded: any = jwt_decode(request.headers.authorization);
cohortUpdateDto.updatedBy = decoded?.sub;
cohortUpdateDto.createdBy = decoded?.sub;

if (!isUUID(cohortId)) {
return APIResponse.error(
res,
Expand Down Expand Up @@ -561,8 +548,8 @@ export class PostgresCohortService {
const contextType = cohortUpdateDto.type
? [cohortUpdateDto.type]
: existingCohorDetails?.type
? [existingCohorDetails.type]
: [];
? [existingCohorDetails.type]
: [];
const allCustomFields = await this.fieldsService.findCustomFields(
"COHORT",
contextType
Expand All @@ -574,9 +561,9 @@ export class PostgresCohortService {
fieldDetail[`${fieldId}`]
? fieldDetail
: {
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
...fieldDetail,
[`${fieldId}`]: { fieldAttributes, fieldParams, name },
},
{}
);
for (const fieldValues of cohortUpdateDto.customFields) {
Expand Down Expand Up @@ -654,8 +641,7 @@ export class PostgresCohortService {

public async searchCohort(
tenantId: string,
academicYearId,
request: any,
academicYearId: string,
cohortSearchDto: CohortSearchDto,
response
) {
Expand All @@ -668,7 +654,6 @@ export class PostgresCohortService {
offset = offset || 0;
limit = limit || 200;


const emptyValueKeys = {};
let emptyKeysString = "";

Expand Down Expand Up @@ -885,8 +870,6 @@ export class PostgresCohortService {
// whereClause["cohortId"] = In(cohortIds);
// }



const [data, totalCount] = await this.cohortRepository.findAndCount({
where: whereClause,
order,
Expand Down Expand Up @@ -939,12 +922,9 @@ export class PostgresCohortService {
}
}

public async updateCohortStatus(cohortId: string, request: any, response) {
public async updateCohortStatus(cohortId: string, response, userId: string) {
const apiId = APIID.COHORT_DELETE;
try {
const decoded: any = jwt_decode(request.headers.authorization);
const updatedBy = decoded?.sub;

if (!isUUID(cohortId)) {
return APIResponse.error(
response,
Expand All @@ -959,7 +939,7 @@ export class PostgresCohortService {
if (checkData === true) {
const query = `UPDATE public."Cohort"
SET "status" = 'archived',
"updatedBy" = '${updatedBy}'
"updatedBy" = '${userId}'
WHERE "cohortId" = $1`;
const affectedrows = await this.cohortRepository.query(query, [
cohortId,
Expand Down
Loading

0 comments on commit a6c01c7

Please sign in to comment.