Skip to content

Commit

Permalink
Merge pull request #1 from vishnuvinay89/release-1.0.0
Browse files Browse the repository at this point in the history
TaskId #228394 Schema changes for cohort and users and API Changes for creation of users and cohorts
  • Loading branch information
gouravmore authored Oct 21, 2024
2 parents dd11a70 + 9e7eca9 commit 51a881b
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 147 deletions.
3 changes: 2 additions & 1 deletion src/adapters/cohortservicelocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Response } from "express";
export interface IServicelocatorcohort {
getCohortsDetails(requiredData,response);
createCohort(request: any, cohortDto: CohortCreateDto,response);
searchCohort(tenantid, academicYearId, request: any, cohortSearchDto: CohortSearchDto,response);
// searchCohort(tenantid, academicYearId, request: any, cohortSearchDto: CohortSearchDto,response);
searchCohort(tenantid, request: any, cohortSearchDto: CohortSearchDto,response);
updateCohort(cohortId: string, request: any, cohortUpdateDto: CohortUpdateDto,response);
updateCohortStatus(cohortId: string, request: any,response);
getCohortHierarchyData(requiredData,response)
Expand Down
83 changes: 42 additions & 41 deletions src/adapters/postgres/cohort-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,21 @@ export class PostgresCohortService {
// Add validation for check both duplicate field ids exist or not
// and whatever user pass fieldIds is exist in field table or not

const academicYearId = cohortCreateDto.academicYearId;
// const academicYearId = cohortCreateDto.academicYearId;
const tenantId = cohortCreateDto.tenantId;

// verify if the academic year id is valid
const academicYear = await this.postgresAcademicYearService.getActiveAcademicYear(cohortCreateDto.academicYearId, tenantId);
// const academicYear = await this.postgresAcademicYearService.getActiveAcademicYear(cohortCreateDto.academicYearId, tenantId);

if (!academicYear) {
return APIResponse.error(
res,
apiId,
HttpStatus.NOT_FOUND.toLocaleString(),
API_RESPONSES.ACADEMICYEAR_NOT_FOUND,
HttpStatus.NOT_FOUND
);
}
// if (!academicYear) {
// return APIResponse.error(
// res,
// apiId,
// HttpStatus.NOT_FOUND.toLocaleString(),
// API_RESPONSES.ACADEMICYEAR_NOT_FOUND,
// HttpStatus.NOT_FOUND
// );
// }

if (cohortCreateDto.customFields && cohortCreateDto.customFields.length > 0) {
const validationResponse = await this.fieldsService.validateCustomField(cohortCreateDto, cohortCreateDto.type);
Expand All @@ -297,7 +297,7 @@ export class PostgresCohortService {
cohortCreateDto.createdBy = decoded?.sub;
cohortCreateDto.updatedBy = decoded?.sub;
cohortCreateDto.status = cohortCreateDto.status || 'active';
cohortCreateDto.attendanceCaptureImage = false;
// cohortCreateDto.attendanceCaptureImage = false;

const existData = await this.cohortRepository.find({
where: {
Expand Down Expand Up @@ -342,9 +342,10 @@ export class PostgresCohortService {
}

// add the year mapping entry in table with cohortId and academicYearId
await this.cohortAcademicYearService.insertCohortAcademicYear(response.cohortId, academicYearId, decoded?.sub, decoded?.sub);
// await this.cohortAcademicYearService.insertCohortAcademicYear(response.cohortId, academicYearId, decoded?.sub, decoded?.sub);

const resBody = new ReturnResponseBody({ ...response, academicYearId: academicYearId });
// const resBody = new ReturnResponseBody({ ...response, academicYearId: academicYearId });
const resBody = new ReturnResponseBody(response);
return APIResponse.success(
res,
apiId,
Expand Down Expand Up @@ -526,15 +527,15 @@ export class PostgresCohortService {

public async searchCohort(
tenantId: string,
academicYearId,
// academicYearId,
request: any,
cohortSearchDto: CohortSearchDto,
response
) {
const apiId = APIID.COHORT_LIST;
try {
let { limit, sort, offset, filters } = cohortSearchDto;
let cohortsByAcademicYear :CohortAcademicYear[];
// let cohortsByAcademicYear :CohortAcademicYear[];

offset = offset || 0;
limit = limit || 200;
Expand Down Expand Up @@ -578,14 +579,14 @@ export class PostgresCohortService {
const whereClause = {};
const searchCustomFields = {};

if(academicYearId) {
// check if the tenantId and academic year exist together
cohortsByAcademicYear = await this.cohortAcademicYearService.getCohortsAcademicYear(academicYearId, tenantId);
// if(academicYearId) {
// // check if the tenantId and academic year exist together
// cohortsByAcademicYear = await this.cohortAcademicYearService.getCohortsAcademicYear(academicYearId, tenantId);

if(cohortsByAcademicYear?.length === 0) {
return APIResponse.error(response, apiId, API_RESPONSES.COHORT_NOT_AVAILABLE_FOR_ACADEMIC_YEAR,API_RESPONSES.COHORT_NOT_AVAILABLE_FOR_ACADEMIC_YEAR ,HttpStatus.NOT_FOUND);
}
}
// if(cohortsByAcademicYear?.length === 0) {
// return APIResponse.error(response, apiId, API_RESPONSES.COHORT_NOT_AVAILABLE_FOR_ACADEMIC_YEAR,API_RESPONSES.COHORT_NOT_AVAILABLE_FOR_ACADEMIC_YEAR ,HttpStatus.NOT_FOUND);
// }
// }

if (filters && Object.keys(filters).length > 0) {

Expand Down Expand Up @@ -675,7 +676,6 @@ export class PostgresCohortService {
count = totalCount;

let cohortIds = userExistCohortGroup.map(cohortId => cohortId.cohortId);

let cohortAllData = await this.cohortRepository.find({
where: {
cohortId: In(cohortIds),
Expand Down Expand Up @@ -707,15 +707,16 @@ export class PostgresCohortService {

if (getCohortIdUsingCustomFields && getCohortIdUsingCustomFields.length > 0) {
let cohortIdsByFieldAndAcademicYear;
if(cohortsByAcademicYear?.length >= 1) {
cohortIdsByFieldAndAcademicYear = cohortsByAcademicYear.filter(({cohortId}) => getCohortIdUsingCustomFields.includes(cohortId))
}
// if(cohortsByAcademicYear?.length >= 1) {
// cohortIdsByFieldAndAcademicYear = cohortsByAcademicYear.filter(({cohortId}) => getCohortIdUsingCustomFields.includes(cohortId))
// }
const cohortIds = cohortIdsByFieldAndAcademicYear?.map(({cohortId}) => cohortId )
whereClause['cohortId'] = In(cohortIds)
} else if(cohortsByAcademicYear?.length >= 1) {
const cohortIds = cohortsByAcademicYear?.map(({cohortId}) => cohortId )
whereClause['cohortId'] = In(cohortIds)
}
// else if(cohortsByAcademicYear?.length >= 1) {
// const cohortIds = cohortsByAcademicYear?.map(({cohortId}) => cohortId )
// whereClause['cohortId'] = In(cohortIds)
// }

const [data, totalCount] = await this.cohortRepository.findAndCount({
where: whereClause,
Expand Down Expand Up @@ -852,17 +853,17 @@ export class PostgresCohortService {
public async getCohortHierarchyData(requiredData, res) {
// my cohort
let apiId = APIID.COHORT_LIST;
const userAcademicYear : any[] = await this.postgresCohortMembersService.isUserExistForYear(requiredData.academicYearId,requiredData.userId);

if(userAcademicYear.length !== 1) {
return APIResponse.error(
res,
apiId,
"BAD_REQUEST",
API_RESPONSES.USER_NOT_IN_ACADEMIC_YEAR,
HttpStatus.BAD_REQUEST
);
}
// const userAcademicYear : any[] = await this.postgresCohortMembersService.isUserExistForYear(requiredData.academicYearId,requiredData.userId);

// if(userAcademicYear.length !== 1) {
// return APIResponse.error(
// res,
// apiId,
// "BAD_REQUEST",
// API_RESPONSES.USER_NOT_IN_ACADEMIC_YEAR,
// HttpStatus.BAD_REQUEST
// );
// }

if (!requiredData.getChildData) {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/postgres/user-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,9 @@ export class PostgresUserService implements IServicelocator {
user.updatedBy = userCreateDto?.updatedBy || userCreateDto?.userId,
user.userId = userCreateDto?.userId,
user.state = userCreateDto?.state,
user.district = userCreateDto?.district,
user.address = userCreateDto?.address,
user.pincode = userCreateDto?.pincode
user.district = userCreateDto?.district
// user.address = userCreateDto?.address,
// user.pincode = userCreateDto?.pincode

if (userCreateDto?.dob) {
user.dob = new Date(userCreateDto.dob);
Expand Down
49 changes: 25 additions & 24 deletions src/cohort/cohort.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export class CohortController {
@ApiHeader({
name: "tenantid",
})
@ApiHeader({
name: "academicyearid",
})
// @ApiHeader({
// name: "academicyearid",
// })
public async createCohort(
@Headers() headers,
@Req() request: Request,
Expand All @@ -131,14 +131,14 @@ export class CohortController {
@Res() response: Response
) {
let tenantId = headers["tenantid"];
let academicYearId = headers["academicyearid"];
// let academicYearId = headers["academicyearid"];
if (!tenantId || !isUUID(tenantId)) {
throw new BadRequestException(API_RESPONSES.TENANTID_VALIDATION);
}
if (!academicYearId || !isUUID(academicYearId)) {
throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
}
cohortCreateDto.academicYearId = academicYearId;
// if (!academicYearId || !isUUID(academicYearId)) {
// throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
// }
// cohortCreateDto.academicYearId = academicYearId;
cohortCreateDto.tenantId = tenantId;
return await this.cohortAdapter.buildCohortAdapter().createCohort(
request,
Expand All @@ -162,26 +162,27 @@ export class CohortController {
@ApiHeader({
name: "tenantid",
})
@ApiHeader({
name: "academicyearid",
})
// @ApiHeader({
// name: "academicyearid",
// })
public async searchCohort(
@Headers() headers,
@Req() request: Request,
@Body() cohortSearchDto: CohortSearchDto,
@Res() response: Response
) {
let tenantId = headers["tenantid"];
let academicYearId = headers["academicyearid"];

// let academicYearId = headers["academicyearid"];
if (!tenantId || !isUUID(tenantId)) {
throw new BadRequestException(API_RESPONSES.TENANTID_VALIDATION);
}
if (!academicYearId || !isUUID(academicYearId)) {
throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
}
// if (!academicYearId || !isUUID(academicYearId)) {
// throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
// }
return await this.cohortAdapter.buildCohortAdapter().searchCohort(
tenantId,
academicYearId,
// academicYearId,
request,
cohortSearchDto,
response
Expand Down Expand Up @@ -243,9 +244,9 @@ export class CohortController {
@ApiInternalServerErrorResponse({ description: "Internal Server Error." })
@ApiBadRequestResponse({ description: "Bad Request" })
@ApiHeader({ name: "tenantid", })
@ApiHeader({
name: "academicyearid",
})
// @ApiHeader({
// name: "academicyearid",
// })
@ApiQuery({ name: "children", required: false, type: Boolean })
@ApiQuery({ name: "customField", required: false, type: Boolean })
public async getCohortsHierarachyData(
Expand All @@ -257,18 +258,18 @@ export class CohortController {
@Res() response: Response
) {
let tenantId = headers["tenantid"];
let academicYearId = headers["academicyearid"];
// let academicYearId = headers["academicyearid"];
if (!tenantId || !isUUID(tenantId)) {
throw new BadRequestException(API_RESPONSES.TENANTID_VALIDATION);
}
if (!academicYearId || !isUUID(academicYearId)) {
throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
}
// if (!academicYearId || !isUUID(academicYearId)) {
// throw new BadRequestException(API_RESPONSES.ACADEMICYEARID_VALIDATION);
// }
const getChildDataValueBoolean = children === 'true';
let fieldValueBooelan = customField === 'true'
let requiredData = {
userId: userId,
academicYearId: academicYearId,
// academicYearId: academicYearId,
getChildData: getChildDataValueBoolean,
customField: fieldValueBooelan
}
Expand Down
28 changes: 14 additions & 14 deletions src/cohort/dto/cohort-create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CohortCreateDto {
@Expose()
tenantId: string;

academicYearId: string;
// academicYearId: string;

@Expose()
createdAt: string;
Expand All @@ -24,13 +24,13 @@ export class CohortCreateDto {
updatedAt: string;

//programId
@ApiPropertyOptional({
type: String,
description: "The programId of the cohort",
default: "",
})
@Expose()
programId: string;
// @ApiPropertyOptional({
// type: String,
// description: "The programId of the cohort",
// default: "",
// })
// @Expose()
// programId: string;

//parentId
@ApiPropertyOptional({
Expand All @@ -42,8 +42,8 @@ export class CohortCreateDto {
parentId: string;

//referenceId
@Expose()
referenceId: string;
// @Expose()
// referenceId: string;

//name
@ApiProperty({
Expand Down Expand Up @@ -80,17 +80,17 @@ export class CohortCreateDto {
status: string;

//attendanceCaptureImage
@Expose()
attendanceCaptureImage: boolean;
// @Expose()
// attendanceCaptureImage: boolean;

//image need for future
// @Expose()
// @ApiPropertyOptional({ type: "string", format: "binary" })
// image: string;

//metadata
@Expose()
metadata: string;
// @Expose()
// metadata: string;

//createdBy
@Expose()
Expand Down
Loading

0 comments on commit 51a881b

Please sign in to comment.