-
Notifications
You must be signed in to change notification settings - Fork 13
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 #77 from Xitija/my-cohort
PS-1931 - API to create dynamic form. PS-2109 API to move cohort to academic year
- Loading branch information
Showing
17 changed files
with
452 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CohortAcademicYearDto } from "src/cohortAcademicYear/dto/cohort-academicyear.dto"; | ||
import { Request, Response } from "express"; | ||
|
||
export interface IServiceLocatorCohortAcademicYear { | ||
createCohortAcademicYear( | ||
tenantId: string, | ||
request: Request, | ||
cohortAcademicYearDto: CohortAcademicYearDto, | ||
response: Response | ||
); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
Controller, Headers, Post, UseFilters, UsePipes, Req, | ||
Res, ValidationPipe, | ||
BadRequestException, | ||
Body | ||
} from '@nestjs/common'; | ||
import { ApiBadRequestResponse, ApiBasicAuth, ApiBody, ApiCreatedResponse, ApiHeader, ApiInternalServerErrorResponse, ApiTags } from '@nestjs/swagger'; | ||
import { APIID } from '@utils/api-id.config'; | ||
import { API_RESPONSES } from '@utils/response.messages'; | ||
import { isUUID } from 'class-validator'; | ||
import { Response, Request } from 'express'; | ||
import { AllExceptionsFilter } from 'src/common/filters/exception.filter'; | ||
import { CohortAcademicYearDto } from './dto/cohort-academicyear.dto'; | ||
import { CohortAcademicYearAdapter } from './cohortacademicyearsadaptor'; | ||
|
||
@ApiTags("CohortAcademicYear") | ||
@Controller('cohort-academic-year') | ||
export class CohortAcademicYearController { | ||
|
||
constructor(private readonly cohortAcademicYearAdapter: CohortAcademicYearAdapter) { } | ||
|
||
@UseFilters(new AllExceptionsFilter(APIID.ADD_COHORT_TO_ACADEMIC_YEAR)) | ||
@Post("/create") | ||
@ApiBasicAuth("access-token") | ||
@ApiCreatedResponse({ description: "Form has been created successfully." }) | ||
@ApiBadRequestResponse({ description: "Bad request." }) | ||
@ApiInternalServerErrorResponse({ description: "Internal Server Error." }) | ||
@UsePipes(new ValidationPipe()) | ||
@ApiBody({ type: CohortAcademicYearDto }) | ||
@ApiHeader({ | ||
name: "tenantid", | ||
}) | ||
public async createCohortAcademicYear( | ||
@Headers() headers, | ||
@Req() request: Request, | ||
@Body() cohortAcademicYearDto: CohortAcademicYearDto, | ||
@Res() response: Response | ||
) { | ||
let tenantId = headers["tenantid"]; | ||
if (tenantId && !isUUID(tenantId)) { | ||
throw new BadRequestException(API_RESPONSES.TENANTID_VALIDATION); | ||
} | ||
return this.cohortAcademicYearAdapter.buildAcademicYears().createCohortAcademicYear(tenantId, request, cohortAcademicYearDto, response); | ||
} | ||
} |
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,10 +1,25 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { CohortAcademicYear } from "./entities/cohortAcademicYear.entity"; | ||
import { CohortAcademicYearService } from "../adapters/postgres/cohortAcademicYear-adapter"; | ||
// import { CohortAcademicYearController } from './cohortAcademicYear.controller'; | ||
import { CohortAcademicYearController } from "./cohortAcademicYear.controller"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { CohortAcademicYearAdapter } from "./cohortacademicyearsadaptor"; | ||
import { PostgresAcademicYearService } from "src/adapters/postgres/academicyears-adapter"; | ||
import { PostgresModule } from "src/adapters/postgres/postgres-module"; | ||
import { Cohort } from "src/cohort/entities/cohort.entity"; | ||
import { AcademicYear } from "src/academicyears/entities/academicyears-entity"; | ||
|
||
@Module({ | ||
imports: [], | ||
// controllers: [CohortAcademicYearController], | ||
providers: [CohortAcademicYearService], | ||
imports: [ | ||
PostgresModule, | ||
TypeOrmModule.forFeature([ | ||
CohortAcademicYear, | ||
Cohort, | ||
AcademicYear | ||
]), | ||
], | ||
controllers: [CohortAcademicYearController], | ||
providers: [CohortAcademicYearAdapter, CohortAcademicYearService, PostgresAcademicYearService], | ||
exports: [CohortAcademicYearService] | ||
}) | ||
export class CohortAcademicYearModule {} | ||
export class CohortAcademicYearModule { } |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { IServiceLocatorCohortAcademicYear } from "src/adapters/cohortacademicyearservicelocator"; | ||
import { CohortAcademicYearService } from "src/adapters/postgres/cohortAcademicYear-adapter"; | ||
|
||
@Injectable() | ||
export class CohortAcademicYearAdapter { | ||
constructor( | ||
private readonly postgresProviders: CohortAcademicYearService | ||
) {} | ||
buildAcademicYears(): IServiceLocatorCohortAcademicYear { | ||
let adapter: IServiceLocatorCohortAcademicYear; | ||
switch (process.env.ADAPTERSOURCE) { | ||
case "postgres": | ||
adapter = this.postgresProviders; | ||
} | ||
return adapter; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
IsNotEmpty, | ||
IsUUID, | ||
} from "class-validator"; | ||
import { ApiProperty } from "@nestjs/swagger"; | ||
import { Expose } from "class-transformer"; | ||
|
||
export class CohortAcademicYearDto { | ||
|
||
@ApiProperty({ | ||
type: String, | ||
description: "cohortId", | ||
default: "", | ||
}) | ||
@Expose() | ||
@IsNotEmpty() | ||
@IsUUID(undefined, { message: "Cohort Id must be a valid UUID" }) | ||
cohortId: string; | ||
|
||
@ApiProperty({ | ||
type: String, | ||
description: "academicYearId", | ||
default: "", | ||
}) | ||
@Expose() | ||
@IsNotEmpty() | ||
@IsUUID(undefined, { message: "Academic Year Id must be a valid UUID" }) | ||
academicYearId: string; | ||
|
||
createdBy: string; | ||
|
||
updatedBy: string; | ||
|
||
} |
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.