Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum validations #144

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Question/enums/question.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export enum classList {
class1 = "class1",
class2 = "class2",
class3 = "class3",
class4 = "class4",
class5 = "class5",
class6 = "class6",
class7 = "class7",
class8 = "class8",
class9 = "class9",
class10 = "class10",
class11 = "class11",
class12 = "class12",
}
20 changes: 19 additions & 1 deletion src/Question/question.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { IServicelocator } from "src/adapters/questionservicelocator";
import { KhanAcademyQuestionToken } from "src/adapters/khanAcademy/khanAcademy.adapter";
import { QuestionDto } from "./dto/question.dto";
import { HasuraQuestionToken } from "src/adapters/hasura/question.adapter";
import { classList } from "./enums/question.enum";

@ApiTags("Question")
@Controller("question")
Expand Down Expand Up @@ -123,7 +124,24 @@ export class QuestionController {
@Get(":adapter/subjectlist")
@UseInterceptors(ClassSerializerInterceptor, CacheInterceptor)
@ApiOkResponse({ description: "Get all subject list" })
@ApiQuery({ name: "gradeLevel", required: true })
@ApiQuery({
name: "gradeLevel",
enum: [
classList.class1,
classList.class2,
classList.class3,
classList.class4,
classList.class5,
classList.class6,
classList.class7,
classList.class8,
classList.class9,
classList.class10,
classList.class11,
classList.class12,
],
required: true,
})
@ApiForbiddenResponse({ description: "Forbidden" })
public async getSubjectList(
@Param("adapter") adapter: string,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/hasura/trackassessment.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { catchError, map } from "rxjs";
import { SuccessResponse } from "src/success-response";
import { TrackAssessmentDto } from "src/trackAssessment/dto/trackassessment.dto";
import { ErrorResponse } from "src/error-response";
import { Status } from "../../trackAssessment/enums/statuses.enum";
import { Status } from "../../trackAssessment/enums/trackAssessment.enum";

@Injectable()
export class TrackAssessmentService {
Expand Down
6 changes: 6 additions & 0 deletions src/attendance/attendance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import {
UploadedFile,
CacheInterceptor,
Query,
Inject,
CACHE_MANAGER,
ValidationPipe,
UsePipes,
} from "@nestjs/common";
import { AttendanceDto } from "./dto/attendance.dto";
import { FileInterceptor } from "@nestjs/platform-express";
Expand Down Expand Up @@ -75,6 +79,7 @@ export class AttendanceController {
@ApiBody({ type: AttendanceDto })
@ApiForbiddenResponse({ description: "Forbidden" })
@UseInterceptors(ClassSerializerInterceptor)
@UsePipes(new ValidationPipe({}))
public async createAttendace(
@Req() request: Request,
@Body() attendaceDto: AttendanceDto,
Expand Down Expand Up @@ -107,6 +112,7 @@ export class AttendanceController {
@ApiBody({ type: AttendanceDto })
@ApiForbiddenResponse({ description: "Forbidden" })
@UseInterceptors(ClassSerializerInterceptor)
@UsePipes(new ValidationPipe({}))
public async updateAttendace(
@Param("id") attendanceId: string,
@Req() request: Request,
Expand Down
138 changes: 135 additions & 3 deletions src/attendance/dto/attendance.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Exclude, Expose } from "class-transformer";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsEnum, IsIn, IsNotEmpty, IsString } from "class-validator";
import {
attendance,
remark,
subjectList,
userType,
} from "../enums/attendance.enums";

export class AttendanceDto {
@Expose()
Expand All @@ -14,10 +21,20 @@ export class AttendanceDto {
@ApiPropertyOptional()
schoolId: string;

@IsString()
@IsNotEmpty()
@IsIn([userType.student, userType.teacher, userType.mentor, userType.monitor])
@IsEnum(userType)
@ApiPropertyOptional({
type: String,
description: "The userType of the attendance",
default: "",
enum: [
userType.student,
userType.teacher,
userType.mentor,
userType.monitor,
],
})
@Expose()
userType: string;
Expand All @@ -38,13 +55,94 @@ export class AttendanceDto {
@Expose()
groupId: string;

@IsString()
@IsNotEmpty()
@IsIn([
subjectList.hindi,
subjectList.english,
subjectList.bengali,
subjectList.marathi,
subjectList.science,
subjectList.sanskrit,
subjectList.geography,
subjectList.spanish,
subjectList.tamil,
subjectList.telugu,
subjectList.kannada,
subjectList.arabicbidaytularebia,
subjectList.balbharatikannada,
subjectList.cocurricular,
subjectList.evs,
subjectList.evspart1,
subjectList.evspart2,
subjectList.gujarati,
subjectList.defencestudies,
subjectList.gulhaafarsi,
subjectList.history,
subjectList.historyandcivics,
subjectList.historyandpoliticalscience,
subjectList.khelekaresikhe,
subjectList.khelokarusikhu,
subjectList.khelukarushiku,
subjectList.kumarbharatikannada,
subjectList.marathishikshaksanhita,
subjectList.mathematics,
subjectList.playdolearn,
subjectList.scholarshipenglish,
subjectList.scholarshipintelligencetest,
subjectList.scholarshipmarathi,
subjectList.scholarshipmathematics,
subjectList.secretarialpracticesp,
subjectList.selfdevelopment,
subjectList.urdu,
])
@IsEnum(subjectList)
@ApiProperty({
type: String,
description: "The topicid of the attendance",
default: "",
enum: [
subjectList.hindi,
subjectList.english,
subjectList.bengali,
subjectList.marathi,
subjectList.science,
subjectList.sanskrit,
subjectList.geography,
subjectList.spanish,
subjectList.tamil,
subjectList.telugu,
subjectList.kannada,
subjectList.arabicbidaytularebia,
subjectList.balbharatikannada,
subjectList.cocurricular,
subjectList.evs,
subjectList.evspart1,
subjectList.evspart2,
subjectList.gujarati,
subjectList.defencestudies,
subjectList.gulhaafarsi,
subjectList.history,
subjectList.historyandcivics,
subjectList.historyandpoliticalscience,
subjectList.khelekaresikhe,
subjectList.khelokarusikhu,
subjectList.khelukarushiku,
subjectList.kumarbharatikannada,
subjectList.marathishikshaksanhita,
subjectList.mathematics,
subjectList.playdolearn,
subjectList.scholarshipenglish,
subjectList.scholarshipintelligencetest,
subjectList.scholarshipmarathi,
subjectList.scholarshipmathematics,
subjectList.secretarialpracticesp,
subjectList.selfdevelopment,
subjectList.urdu,
],
})
@Expose()
@ApiPropertyOptional()
@Expose()
topicId: string;

@ApiProperty({
Expand All @@ -64,18 +162,52 @@ export class AttendanceDto {
@Expose()
attendanceDate: string;

@ApiProperty({
@IsString()
@IsNotEmpty()
@IsIn([
attendance.present,
attendance.absent,
attendance.unmarked,
attendance.specialDuty,
attendance.onleave,
])
@IsEnum(attendance)
@ApiPropertyOptional({
type: String,
description: "The attendance of the attendance",
default: "",
enum: [
attendance.present,
attendance.absent,
attendance.unmarked,
attendance.specialDuty,
attendance.onleave,
],
})
@Expose()
attendance: string;

@ApiProperty({
@IsString()
@IsNotEmpty()
@IsIn([
remark.present,
remark.absent,
remark.unmarked,
remark.specialDuty,
remark.onleave,
])
@IsEnum(remark)
@ApiPropertyOptional({
type: String,
description: "The remark of the attendance",
default: "",
enum: [
remark.present,
remark.absent,
remark.unmarked,
remark.specialDuty,
remark.onleave,
],
})
@Expose()
@ApiPropertyOptional()
Expand Down
64 changes: 64 additions & 0 deletions src/attendance/enums/attendance.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export enum userType {
teacher = "teacher",
mentor = "mentor",
monitor = "monitor",
student = "student",
}

export enum attendance {
present = "present",
absent = "absent",
unmarked = "unmarked",
specialDuty = "specialDuty",
onleave = "onleave",
}

export enum remark {
present = "present",
absent = "absent",
unmarked = "unmarked",
specialDuty = "specialDuty",
onleave = "onLeave",
}

export enum subjectList {
hindi = "hindi",
mathematics = "mathematics",
bengali = "bengali",
marathi = "marathi",
english = "english",
balbharatikannada = "balbharatikannada",
cocurricular = "cocurricular",
khelokarusikhu = "khelokarusikhu",
tamil = "tamil",
marathishikshaksanhita = "marathishikshaksanhita",
khelukarushiku = "khelukarushiku",
playdolearn = "playdolearn",
telugu = "telugu",
sindhi = "sindhi",
gujarati = "gujarati",
urdu = "urdu",
khelekaresikhe = "khelekaresikhe",
kannada = "kannada",
geography = "geography",
evs = "evs",
evspart1 = "evspart1",
evspart2 = "evspart2",
scholarshipmarathi = "scholarshipmarathi",
scholarshipintelligencetest = "scholarshipintelligencetest",
scholarshipenglish = "scholarshipenglish",
scholarshipmathematics = "scholarshipmathematics",
historyandcivics = "historyandcivics",
sugambharatikannada = "sugambharatikannada",
science = "science",
sanskrit = "sanskrit",
history = "history",
arabicbidaytularebia = "arabicbidaytularebia",
defencestudies = "defencestudies",
kumarbharatikannada = "kumarbharatikannada",
historyandpoliticalscience = "historyandpoliticalscience",
selfdevelopment = "selfdevelopment",
spanish = "spanish",
gulhaafarsi = "gulhaafarsi",
secretarialpracticesp = "secretarialpracticesp",
}
4 changes: 4 additions & 0 deletions src/courseTracking/courseTracking.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
Body,
Query,
Put,
ValidationPipe,
UsePipes,
} from "@nestjs/common";
import { CourseTrackingService } from "src/adapters/hasura/courseTracking.adapter";
import { CourseTrackingDto } from "./dto/courseTracking.dto";
Expand Down Expand Up @@ -94,6 +96,7 @@ export class CourseTrackingController {
})
@ApiForbiddenResponse({ description: "Forbidden" })
@UseInterceptors(ClassSerializerInterceptor)
@UsePipes(new ValidationPipe({}))
@ApiQuery({ name: "progressDetail", required: false })
@ApiQuery({ name: "courseId", required: false })
@ApiQuery({ name: "userId", required: false })
Expand Down Expand Up @@ -136,6 +139,7 @@ export class CourseTrackingController {
@ApiCreatedResponse({ description: "Course Tracking list." })
@ApiForbiddenResponse({ description: "Forbidden" })
@UseInterceptors(ClassSerializerInterceptor)
@UsePipes(new ValidationPipe({}))
@SerializeOptions({
strategy: "excludeAll",
})
Expand Down
22 changes: 20 additions & 2 deletions src/courseTracking/dto/courseTracking.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Exclude, Expose } from "class-transformer";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsEnum, IsIn, IsNotEmpty, IsString } from "class-validator";
import { source, status } from "../enums/courseTracking.enum";

export class CourseTrackingDto {
@Expose()
Expand Down Expand Up @@ -33,11 +35,27 @@ export class CourseTrackingDto {
@Expose()
certificate: string;

@ApiProperty({})
@IsString()
@IsNotEmpty()
@IsIn([status.complete, status.inprogress, status.pending])
@IsEnum(status)
@ApiProperty({
type: String,

default: "",
enum: [status.complete, status.inprogress, status.pending],
})
@Expose()
status: string;

@ApiProperty({})
@IsString()
@IsNotEmpty()
@IsIn([source.diksha, source.khanAcademy])
@IsEnum(source)
@ApiProperty({
description: "source of course",
enum: [source.diksha, source.khanAcademy],
})
@Expose()
source: string;

Expand Down
Loading