From 10db08c9248582fcddad9b157012d8948b47ef86 Mon Sep 17 00:00:00 2001 From: Shikhar Vashistha <51105234+shikharvashistha@users.noreply.github.com> Date: Tue, 31 May 2022 07:34:44 +0000 Subject: [PATCH 1/4] feat: student schema changes --- package.json | 5 ++- src/app.module.ts | 6 ++- src/database.provider.ts | 20 +++++++++ src/entities/student.entity.ts | 70 ++++++++++++++++++++++++++++++ src/interface/student.interface.ts | 24 ++++++++++ 5 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 src/database.provider.ts create mode 100644 src/entities/student.entity.ts create mode 100644 src/interface/student.interface.ts diff --git a/package.json b/package.json index ca03a41..e8ac962 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,15 @@ "jwt-decode": "^3.1.2", "moment": "^2.29.3", "multer": "^1.4.4", + "mysql2": "^2.3.3", "object-resolve-path": "^1.1.1", + "pg": "^8.7.3", "reflect-metadata": "^0.1.13", "rimraf": "^3.0.2", "rxjs": "^7.2.0", "swagger-ui-express": "^4.3.0", - "templates.js": "^0.3.11" + "templates.js": "^0.3.11", + "typeorm": "^0.3.6" }, "devDependencies": { "@nestjs/cli": "^8.0.0", diff --git a/src/app.module.ts b/src/app.module.ts index ce7db72..6b966d9 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,4 +1,4 @@ -import { CacheModule, Module } from "@nestjs/common"; +import { Module } from "@nestjs/common"; import { AppController } from "./app.controller"; import { AppService } from "./app.service"; import { StudentModule } from "./student/student.module"; @@ -9,10 +9,12 @@ import { GroupModule } from "./group/group.module"; import { HolidayModule } from "./holiday/holiday.module"; import { ConfigurationModule } from "./configs/configuration.module"; import { ConfigModule } from "@nestjs/config"; +import { DatabaseProviders } from "./database.provider"; import { GroupMembershipModule } from "./groupMembership/groupMembership.module"; import { NotificationModule } from "./notification/notification.module"; import { TemplateModule } from "./template/template.module"; import { MulterModule } from "@nestjs/platform-express/multer"; + @Module({ imports: [ ConfigModule.forRoot(), @@ -31,6 +33,6 @@ import { MulterModule } from "@nestjs/platform-express/multer"; NotificationModule, ], controllers: [AppController], - providers: [AppService], + providers: [AppService, ...DatabaseProviders], }) export class AppModule {} diff --git a/src/database.provider.ts b/src/database.provider.ts new file mode 100644 index 0000000..4974a53 --- /dev/null +++ b/src/database.provider.ts @@ -0,0 +1,20 @@ +import { DataSource } from "typeorm"; + +export const DatabaseProviders = [ + { + provide: "DATA_SOURCE", + useFactory: async () => { + const dataSource = new DataSource({ + type: "postgres", + host: "localhost", + port: 5432, + database: "postgres", + password: "postgres", + username: "postgres", + entities: [__dirname + "./entities/**/*.ts"], + synchronize: true, + }); + return dataSource.initialize(); + }, + }, +]; diff --git a/src/entities/student.entity.ts b/src/entities/student.entity.ts new file mode 100644 index 0000000..68d8ae6 --- /dev/null +++ b/src/entities/student.entity.ts @@ -0,0 +1,70 @@ +import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; + +@Entity() +export class Student { + @PrimaryGeneratedColumn() + studentId: string; + + @Column({ type: "string" }) + aadhaar: string; + + @Column({ type: "string" }) + refStudentId: string; + + @Column({ type: "character varying" }) + firstName: string; + + @Column({ type: "character varying" }) + lastName: string; + + @Column({ type: "integer" }) + contactNumber: number; + + @Column({ type: "string" }) + email: string; + + @Column({ type: "character varying", length: 1 }) + gender: string; + + @Column({ type: "character varying", length: 1 }) + socialCategory: string; + + @Column({ type: "character varying", length: 1 }) + iscwsn: string; + + @Column({ type: "character varying", length: 1 }) + religion: string; + + @Column({ type: "character varying", length: 1 }) + singleGirl: string; + + @Column({ type: "real" }) + weight: number; + + @Column({ type: "real" }) + height: number; + + @Column({ type: "character varying", length: 1 }) + bloodGroup: string; + + @Column({ type: "date" }) + birthDate: Date; + + @Column({ type: "character varying", length: 1 }) + homeless: string; + + @Column({ type: "character varying", length: 1 }) + bpl: string; + + @Column({ type: "character varying", length: 1 }) + migrant: string; + + @Column({ type: "string" }) + schoolId: string; + + @Column({ type: "string" }) + classId: string; + + @Column({ type: "character varying", length: 1 }) + status: string; +} diff --git a/src/interface/student.interface.ts b/src/interface/student.interface.ts new file mode 100644 index 0000000..644bfbc --- /dev/null +++ b/src/interface/student.interface.ts @@ -0,0 +1,24 @@ +export interface StudentInterface extends Document { + readonly studentId: string; + readonly aadhaar: string; + readonly refStudentId: string; + readonly firstName: string; + readonly lastName: string; + readonly contactNumber: number; + readonly email: string; + readonly gender: string; + readonly socialCategory: string; + readonly iscwsn: string; + readonly religion: string; + readonly singleGirl: string; + readonly weight: number; + readonly height: number; + readonly bloodGroup: string; + readonly birthDate: Date; + readonly homeless: string; + readonly bpl: string; + readonly migrant: string; + readonly schoolId: string; + readonly classId: string; + readonly status: string; +} From 6b189fb0c8759f843cc63e3a6a248be82165481a Mon Sep 17 00:00:00 2001 From: Shikhar Vashistha <51105234+shikharvashistha@users.noreply.github.com> Date: Fri, 3 Jun 2022 12:47:56 +0000 Subject: [PATCH 2/4] feat: attendance adapter for postgres --- config | 15 +++ src/adapters/default/config.adapter.ts | 105 +++++++++--------- .../postgres/attendance.postgres.adapter.ts | 96 ++++++++++++++++ src/app.module.ts | 4 +- src/attendance/attendance.controller.spec.ts | 8 +- src/attendance/dto/attendance-response.dto.ts | 18 +-- src/attendance/dto/attendance-search.dto.ts | 6 + .../interfaces/attendance.interface.ts | 19 ++-- src/configs/dto/config.dto.ts | 15 ++- src/database.provider.ts | 20 ---- src/entities/student.entity.ts | 70 ------------ src/error-response.ts | 18 ++- src/group/dto/group-response.dto.ts | 10 +- src/group/interfaces/group.interface.ts | 10 +- src/interface/student.interface.ts | 24 ---- src/interfaces/entities/IStudent.ts | 40 +++---- src/school/dto/school-response.dto.ts | 28 ++--- src/school/interfaces/school.interface.ts | 28 ++--- src/school/school.controller.spec.ts | 8 +- src/student/interfaces/student.interface.ts | 44 ++++---- src/student/student.controller.spec.ts | 8 +- src/teacher/dto/teacher-response.dto.ts | 62 +++++------ src/teacher/teacher.controller.spec.ts | 8 +- 23 files changed, 332 insertions(+), 332 deletions(-) create mode 100644 config create mode 100644 src/adapters/postgres/attendance.postgres.adapter.ts delete mode 100644 src/database.provider.ts delete mode 100644 src/entities/student.entity.ts delete mode 100644 src/interface/student.interface.ts diff --git a/config b/config new file mode 100644 index 0000000..0430c93 --- /dev/null +++ b/config @@ -0,0 +1,15 @@ +config = { + user?: string, // default process.env.PGUSER || process.env.USER + password?: string or function, //default process.env.PGPASSWORD + host?: string, // default process.env.PGHOST + database?: string, // default process.env.PGDATABASE || user + port?: number, // default process.env.PGPORT + connectionString?: string, // e.g. postgres://user:password@host:5432/database + ssl?: any, // passed directly to node.TLSSocket, supports all tls.connect options + types?: any, // custom type parsers + statement_timeout?: number, // number of milliseconds before a statement in query will time out, default is no timeout + query_timeout?: number, // number of milliseconds before a query call will timeout, default is no timeout + application_name?: string, // The name of the application that created this Client instance + connectionTimeoutMillis?: number, // number of milliseconds to wait for connection, default is no timeout + idle_in_transaction_session_timeout?: number // number of milliseconds before terminating any session with an open idle transaction, default is no timeout +} \ No newline at end of file diff --git a/src/adapters/default/config.adapter.ts b/src/adapters/default/config.adapter.ts index 438b2de..7102692 100644 --- a/src/adapters/default/config.adapter.ts +++ b/src/adapters/default/config.adapter.ts @@ -15,8 +15,7 @@ export class ConfigService { constructor(private httpService: HttpService) {} url = `${process.env.BASEAPIURL}/Config`; - public async createConfig(request: any, configDto: ConfigDto) - { + public async createConfig(request: any, configDto: ConfigDto) { let axios = require("axios"); let data = { filters: { @@ -44,19 +43,18 @@ export class ConfigService { let result = resData.map((item: any) => new ConfigDto(item)); let configId = result.map(function (ConfigDto) { - return ConfigDto.configId - }) + return ConfigDto.configId; + }); - if (resData.length > 0) - { + if (resData.length > 0) { var udateData = configDto; var updateConfig = { - method: "put", - url: `${this.url}/${configId}`, - headers: { - Authorization: request.headers.authorization, - }, - data: udateData, + method: "put", + url: `${this.url}/${configId}`, + headers: { + Authorization: request.headers.authorization, + }, + data: udateData, }; const response = await axios(updateConfig); return new SuccessResponse({ @@ -64,39 +62,36 @@ export class ConfigService { message: " Ok.", data: response.data, }); - } - else - { + } else { return this.httpService - .post(`${this.url}`, configDto, { - headers: { - Authorization: request.headers.authorization, - }, - }) - .pipe( - map((axiosResponse: AxiosResponse) => { - return new SuccessResponse({ - statusCode: 200, - message: "Ok.", - data: axiosResponse.data, - }); - }), - catchError((e) => { - var error = new ErrorResponse({ - errorCode: e.response?.status, - errorMessage: e.response?.data?.params?.errmsg, - }); - throw new HttpException(error, e.response.status); + .post(`${this.url}`, configDto, { + headers: { + Authorization: request.headers.authorization, + }, }) - ); + .pipe( + map((axiosResponse: AxiosResponse) => { + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: axiosResponse.data, + }); + }), + catchError((e) => { + var error = new ErrorResponse({ + errorCode: e.response?.status, + errorMessage: e.response?.data?.params?.errmsg, + }); + throw new HttpException(error, e.response.status); + }) + ); } } public async getConfig(request: any) { let axios = require("axios"); let data = { - filters: { - }, + filters: {}, }; let globalConfig = { method: "post", @@ -104,13 +99,14 @@ export class ConfigService { headers: { Authorization: request.headers.authorization, }, - data: data + data: data, }; const globalConfigData = await axios(globalConfig); - let gobalConfigResult = - globalConfigData?.data && globalConfigData.data.map((item: any) => new ConfigDto(item)); - + let gobalConfigResult = + globalConfigData?.data && + globalConfigData.data.map((item: any) => new ConfigDto(item)); + // get Logged In user data const authToken = request.headers.authorization; const decoded: any = jwt_decode(authToken); @@ -133,11 +129,11 @@ export class ConfigService { const response = await axios(config); let teacherProfileData = - response?.data && response.data.map((item: any) => new TeacherDto(item)); - + response?.data && response.data.map((item: any) => new TeacherDto(item)); + let schoolId = teacherProfileData.map(function (TeacherDto) { - return TeacherDto.schoolId - }) + return TeacherDto.schoolId; + }); let teacherConfig = { filters: { @@ -157,16 +153,17 @@ export class ConfigService { }; const confifResponse = await axios(final); let overridenResult = - confifResponse?.data && confifResponse.data.map((item: any) => new ConfigDto(item)); + confifResponse?.data && + confifResponse.data.map((item: any) => new ConfigDto(item)); - var result = gobalConfigResult.filter(obj=> obj.contextId == '') + var result = gobalConfigResult.filter((obj) => obj.contextId == ""); - for(let i =0; iobj.key == result[i].key && obj.module == result[i].module) - if(overridenData.length>0) - { - result[i]=overridenData[0]; + for (let i = 0; i < result.length; i++) { + let overridenData = overridenResult.filter( + (obj) => obj.key == result[i].key && obj.module == result[i].module + ); + if (overridenData.length > 0) { + result[i] = overridenData[0]; } } @@ -176,4 +173,4 @@ export class ConfigService { data: result, }); } -} \ No newline at end of file +} diff --git a/src/adapters/postgres/attendance.postgres.adapter.ts b/src/adapters/postgres/attendance.postgres.adapter.ts new file mode 100644 index 0000000..1e7ac2e --- /dev/null +++ b/src/adapters/postgres/attendance.postgres.adapter.ts @@ -0,0 +1,96 @@ +import { Injectable } from "@nestjs/common"; +import { HttpService } from "@nestjs/axios"; +import { AttendanceDto } from "src/attendance/dto/attendance.dto"; +import { SuccessResponse } from "src/success-response"; +import { AttendanceSearchDto } from "src/attendance/dto/attendance-search.dto"; +import { Client } from "pg"; +import { AnyAaaaRecord } from "dns"; +@Injectable() +export class AttendanceService { + constructor(private httpService: HttpService) {} + url = `${process.env.BASEAPIURL}/Attendance`; + studentAPIUrl = `${process.env.BASEAPIURL}/Student`; + + public async getAttendance(attendanceId: AnyAaaaRecord) { + const client = new Client(); + client.connect(); + client.query( + `SELECT * FROM attendance WHERE id = '${attendanceId}'`, + (err, res) => { + if (err) { + console.log(err); + } else { + console.log(res.rows); + } + } + ); + client.end(); + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: [], + }); + } + + public async createAttendance(attendanceDto: AttendanceDto) { + const client = new Client(); + client.connect(); + client.query( + `INSERT INTO attendance (attendanceRecordId, studentId, attendance, date) VALUES ('${attendanceDto.attendanceId}', '${attendanceDto.userId}', '${attendanceDto.attendanceDate}', '${attendanceDto.attendance}')`, + (err, res) => { + if (err) { + console.log(err); + } else { + console.log(res.rows); + } + } + ); + client.end(); + } + + public async updateAttendance( + attendanceId: string, + attendanceDto: AttendanceDto + ) { + const client = new Client(); + client.connect(); + client.query( + `UPDATE attendance SET attendance = '${attendanceDto.attendance}' WHERE id = '${attendanceId}'`, + (err) => { + if (err) { + console.log(err); + } + } + ); + client.end(); + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: [], + }); + } + + public async searchAttendance( + request: any, + attendanceSearchDto: AttendanceSearchDto + ) { + const client = new Client(); + client.connect(); + client.query( + `SELECT * FROM attendance WHERE attendanceRecordId = '${attendanceSearchDto.attendanceRecordId}'`, + (err, res) => { + if (err) { + console.log(err); + } else { + console.log(res.rows); + } + } + ); + client.end(); + return new SuccessResponse({ + statusCode: 200, + message: "Ok.", + data: [], + }); + } +} diff --git a/src/app.module.ts b/src/app.module.ts index 6b966d9..18b3dc8 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -9,12 +9,10 @@ import { GroupModule } from "./group/group.module"; import { HolidayModule } from "./holiday/holiday.module"; import { ConfigurationModule } from "./configs/configuration.module"; import { ConfigModule } from "@nestjs/config"; -import { DatabaseProviders } from "./database.provider"; import { GroupMembershipModule } from "./groupMembership/groupMembership.module"; import { NotificationModule } from "./notification/notification.module"; import { TemplateModule } from "./template/template.module"; import { MulterModule } from "@nestjs/platform-express/multer"; - @Module({ imports: [ ConfigModule.forRoot(), @@ -33,6 +31,6 @@ import { MulterModule } from "@nestjs/platform-express/multer"; NotificationModule, ], controllers: [AppController], - providers: [AppService, ...DatabaseProviders], + providers: [AppService], }) export class AppModule {} diff --git a/src/attendance/attendance.controller.spec.ts b/src/attendance/attendance.controller.spec.ts index c27520f..77f7c09 100644 --- a/src/attendance/attendance.controller.spec.ts +++ b/src/attendance/attendance.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AttendanceController } from './attendance.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { AttendanceController } from "./attendance.controller"; -describe('AttendanceController', () => { +describe("AttendanceController", () => { let controller: AttendanceController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('AttendanceController', () => { controller = module.get(AttendanceController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); diff --git a/src/attendance/dto/attendance-response.dto.ts b/src/attendance/dto/attendance-response.dto.ts index a5f90da..a288c05 100644 --- a/src/attendance/dto/attendance-response.dto.ts +++ b/src/attendance/dto/attendance-response.dto.ts @@ -1,10 +1,10 @@ export interface AttendanceResponseDto { - attendanceId: string - attendance: string - date: string - subjectId: string - studentId: string - classId: string - teacherId: string - attendanceNote: string - } + attendanceId: string; + attendance: string; + date: string; + subjectId: string; + studentId: string; + classId: string; + teacherId: string; + attendanceNote: string; +} diff --git a/src/attendance/dto/attendance-search.dto.ts b/src/attendance/dto/attendance-search.dto.ts index 39f9e6b..cff0339 100644 --- a/src/attendance/dto/attendance-search.dto.ts +++ b/src/attendance/dto/attendance-search.dto.ts @@ -7,6 +7,12 @@ export class AttendanceSearchDto { }) limit: string; + @ApiProperty({ + type: String, + description: "attendanceRecordId", + }) + attendanceRecordId: string; + @ApiProperty({ type: Object, description: "Filters", diff --git a/src/attendance/interfaces/attendance.interface.ts b/src/attendance/interfaces/attendance.interface.ts index 1316feb..5a8c5e9 100644 --- a/src/attendance/interfaces/attendance.interface.ts +++ b/src/attendance/interfaces/attendance.interface.ts @@ -1,11 +1,10 @@ export interface AttendanceInterface { - attendanceId?: string - attendance?: string - date?: string - subjectId?: string - studentId?: string - classId?: string - teacherId?: string - attendanceNote?: string - - } + attendanceId?: string; + attendance?: string; + date?: string; + subjectId?: string; + studentId?: string; + classId?: string; + teacherId?: string; + attendanceNote?: string; +} diff --git a/src/configs/dto/config.dto.ts b/src/configs/dto/config.dto.ts index cdf7670..2c38cae 100644 --- a/src/configs/dto/config.dto.ts +++ b/src/configs/dto/config.dto.ts @@ -28,28 +28,32 @@ export class ConfigDto { @ApiProperty({ type: String, - description: "The value for the key eg: ['Present', 'Absent', 'Late'] for the attendance_states key", + description: + "The value for the key eg: ['Present', 'Absent', 'Late'] for the attendance_states key", }) @Expose() value: string; @ApiProperty({ type: String, - description: "If the config has been overriden at a school level the context will be school, otherwise it will be empty", + description: + "If the config has been overriden at a school level the context will be school, otherwise it will be empty", }) @Expose() context: string; @ApiProperty({ type: String, - description: "If this is a school level config (indicated by context = school), this field has the schoolId", + description: + "If this is a school level config (indicated by context = school), this field has the schoolId", }) @Expose() contextId: string; @ApiProperty({ type: Boolean, - description: "Indicates if this config is allowed to be updated by a user with another role (eg: can the deployer set this config to be updated by other roles)", + description: + "Indicates if this config is allowed to be updated by a user with another role (eg: can the deployer set this config to be updated by other roles)", }) @Expose() canOverride: boolean; @@ -63,7 +67,8 @@ export class ConfigDto { @ApiProperty({ type: Boolean, - description: "Is this config that can be passed on to the client side eg: to the react frontend. Configs like API credentials should not be allowed to be accessed in the frontend", + description: + "Is this config that can be passed on to the client side eg: to the react frontend. Configs like API credentials should not be allowed to be accessed in the frontend", }) @Expose() isPublic: boolean; diff --git a/src/database.provider.ts b/src/database.provider.ts deleted file mode 100644 index 4974a53..0000000 --- a/src/database.provider.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { DataSource } from "typeorm"; - -export const DatabaseProviders = [ - { - provide: "DATA_SOURCE", - useFactory: async () => { - const dataSource = new DataSource({ - type: "postgres", - host: "localhost", - port: 5432, - database: "postgres", - password: "postgres", - username: "postgres", - entities: [__dirname + "./entities/**/*.ts"], - synchronize: true, - }); - return dataSource.initialize(); - }, - }, -]; diff --git a/src/entities/student.entity.ts b/src/entities/student.entity.ts deleted file mode 100644 index 68d8ae6..0000000 --- a/src/entities/student.entity.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"; - -@Entity() -export class Student { - @PrimaryGeneratedColumn() - studentId: string; - - @Column({ type: "string" }) - aadhaar: string; - - @Column({ type: "string" }) - refStudentId: string; - - @Column({ type: "character varying" }) - firstName: string; - - @Column({ type: "character varying" }) - lastName: string; - - @Column({ type: "integer" }) - contactNumber: number; - - @Column({ type: "string" }) - email: string; - - @Column({ type: "character varying", length: 1 }) - gender: string; - - @Column({ type: "character varying", length: 1 }) - socialCategory: string; - - @Column({ type: "character varying", length: 1 }) - iscwsn: string; - - @Column({ type: "character varying", length: 1 }) - religion: string; - - @Column({ type: "character varying", length: 1 }) - singleGirl: string; - - @Column({ type: "real" }) - weight: number; - - @Column({ type: "real" }) - height: number; - - @Column({ type: "character varying", length: 1 }) - bloodGroup: string; - - @Column({ type: "date" }) - birthDate: Date; - - @Column({ type: "character varying", length: 1 }) - homeless: string; - - @Column({ type: "character varying", length: 1 }) - bpl: string; - - @Column({ type: "character varying", length: 1 }) - migrant: string; - - @Column({ type: "string" }) - schoolId: string; - - @Column({ type: "string" }) - classId: string; - - @Column({ type: "character varying", length: 1 }) - status: string; -} diff --git a/src/error-response.ts b/src/error-response.ts index ace9e80..9dfdd5d 100644 --- a/src/error-response.ts +++ b/src/error-response.ts @@ -1,15 +1,13 @@ import { Expose } from "class-transformer"; export class ErrorResponse { + @Expose() + errorCode: string; - @Expose() - errorCode: string + @Expose() + errorMessage: string; - @Expose() - errorMessage : string - - - constructor(partial: Partial) { - Object.assign(this, partial); - } -} \ No newline at end of file + constructor(partial: Partial) { + Object.assign(this, partial); + } +} diff --git a/src/group/dto/group-response.dto.ts b/src/group/dto/group-response.dto.ts index 2b46e73..dd7f568 100644 --- a/src/group/dto/group-response.dto.ts +++ b/src/group/dto/group-response.dto.ts @@ -1,6 +1,6 @@ export interface GroupResponseDto { - groupId: string - name: string - type: string - status: string - } \ No newline at end of file + groupId: string; + name: string; + type: string; + status: string; +} diff --git a/src/group/interfaces/group.interface.ts b/src/group/interfaces/group.interface.ts index 55c3f6b..328b6f2 100644 --- a/src/group/interfaces/group.interface.ts +++ b/src/group/interfaces/group.interface.ts @@ -1,6 +1,6 @@ export interface GroupInterface { - groupId?: string - name?: string - type?: string - status?: string - } \ No newline at end of file + groupId?: string; + name?: string; + type?: string; + status?: string; +} diff --git a/src/interface/student.interface.ts b/src/interface/student.interface.ts deleted file mode 100644 index 644bfbc..0000000 --- a/src/interface/student.interface.ts +++ /dev/null @@ -1,24 +0,0 @@ -export interface StudentInterface extends Document { - readonly studentId: string; - readonly aadhaar: string; - readonly refStudentId: string; - readonly firstName: string; - readonly lastName: string; - readonly contactNumber: number; - readonly email: string; - readonly gender: string; - readonly socialCategory: string; - readonly iscwsn: string; - readonly religion: string; - readonly singleGirl: string; - readonly weight: number; - readonly height: number; - readonly bloodGroup: string; - readonly birthDate: Date; - readonly homeless: string; - readonly bpl: string; - readonly migrant: string; - readonly schoolId: string; - readonly classId: string; - readonly status: string; -} diff --git a/src/interfaces/entities/IStudent.ts b/src/interfaces/entities/IStudent.ts index 194a91f..8cd815e 100644 --- a/src/interfaces/entities/IStudent.ts +++ b/src/interfaces/entities/IStudent.ts @@ -1,22 +1,22 @@ interface IStudent { - studentId: string - refId: string - aadhaar: string - firstName: string - lastName: string - schoolId: string - currentClassId: string - gender: string - socialCategory: string - iscwsn: string - religion: string - singleGirl: string - weight: string - height: string - bloodGroup: string - birthDate: string - homeless: string - bpl: string - migrant: string - status: string + studentId: string; + refId: string; + aadhaar: string; + firstName: string; + lastName: string; + schoolId: string; + currentClassId: string; + gender: string; + socialCategory: string; + iscwsn: string; + religion: string; + singleGirl: string; + weight: string; + height: string; + bloodGroup: string; + birthDate: string; + homeless: string; + bpl: string; + migrant: string; + status: string; } diff --git a/src/school/dto/school-response.dto.ts b/src/school/dto/school-response.dto.ts index ced6720..8435e09 100644 --- a/src/school/dto/school-response.dto.ts +++ b/src/school/dto/school-response.dto.ts @@ -1,15 +1,15 @@ export interface SchoolResponseDto { - schoolId: string - schoolName: string - email: string - schoolRefId: string - instituteManagement: string - address: string - schoolType: string - website: string - street: string - city:string - district: string - state: string - pincode: string - } \ No newline at end of file + schoolId: string; + schoolName: string; + email: string; + schoolRefId: string; + instituteManagement: string; + address: string; + schoolType: string; + website: string; + street: string; + city: string; + district: string; + state: string; + pincode: string; +} diff --git a/src/school/interfaces/school.interface.ts b/src/school/interfaces/school.interface.ts index 5444ece..aea9e0a 100644 --- a/src/school/interfaces/school.interface.ts +++ b/src/school/interfaces/school.interface.ts @@ -1,15 +1,15 @@ export interface SchoolInterface { - schoolId?: string - schoolName?: string - email?: string - schoolRefId?: string - instituteManagement?: string - address?: string - schoolType?: string - website?: string - street?: string - city?:string - district?: string - state?: string - pincode?: string - } \ No newline at end of file + schoolId?: string; + schoolName?: string; + email?: string; + schoolRefId?: string; + instituteManagement?: string; + address?: string; + schoolType?: string; + website?: string; + street?: string; + city?: string; + district?: string; + state?: string; + pincode?: string; +} diff --git a/src/school/school.controller.spec.ts b/src/school/school.controller.spec.ts index b056d89..6c749df 100644 --- a/src/school/school.controller.spec.ts +++ b/src/school/school.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { SchoolController } from './school.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { SchoolController } from "./school.controller"; -describe('SchoolController', () => { +describe("SchoolController", () => { let controller: SchoolController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('SchoolController', () => { controller = module.get(SchoolController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); diff --git a/src/student/interfaces/student.interface.ts b/src/student/interfaces/student.interface.ts index 2e3241f..db0d990 100644 --- a/src/student/interfaces/student.interface.ts +++ b/src/student/interfaces/student.interface.ts @@ -1,23 +1,23 @@ export interface StudentInterface { - studentId?: string - refId?: string - aadhaar?: string - firstName?: string - lastName?: string - schoolId?: string - currentClassId?: string - gender?: string - socialCategory?: string - iscwsn?: string - religion?: string - singleGirl?: string - weight?: string - height?: string - bloodGroup?: string - birthDate?: string - homeless?: string - bpl?: string - migrant?: string - status?: string - email?: string - } \ No newline at end of file + studentId?: string; + refId?: string; + aadhaar?: string; + firstName?: string; + lastName?: string; + schoolId?: string; + currentClassId?: string; + gender?: string; + socialCategory?: string; + iscwsn?: string; + religion?: string; + singleGirl?: string; + weight?: string; + height?: string; + bloodGroup?: string; + birthDate?: string; + homeless?: string; + bpl?: string; + migrant?: string; + status?: string; + email?: string; +} diff --git a/src/student/student.controller.spec.ts b/src/student/student.controller.spec.ts index 4182434..52ad318 100644 --- a/src/student/student.controller.spec.ts +++ b/src/student/student.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { StudentController } from './student.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { StudentController } from "./student.controller"; -describe('StudentController', () => { +describe("StudentController", () => { let controller: StudentController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('StudentController', () => { controller = module.get(StudentController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); diff --git a/src/teacher/dto/teacher-response.dto.ts b/src/teacher/dto/teacher-response.dto.ts index 26f742e..0ef106c 100644 --- a/src/teacher/dto/teacher-response.dto.ts +++ b/src/teacher/dto/teacher-response.dto.ts @@ -1,32 +1,32 @@ export interface TeacherResponseDto { - teacherId: string - firstName: string - lastName: string - contactNumber: string - email: string - gender: string - socialCategory: string - birthDate: string - designation: string - cadre: string - profQualification: string - joiningDate: string - subjectId: string - bloodGroup: string - maritalStatus: string - blockI: string - address: string - compSkills: string - disability: string - religion: string - homeDistance: string - roles: string - schoolId: string - acrId: string - retirementDate: string - workingStatus: string - osCreatedAt: string - osUpdatedAt: string - osCreatedBy: string - osUpdatedBy: string - } \ No newline at end of file + teacherId: string; + firstName: string; + lastName: string; + contactNumber: string; + email: string; + gender: string; + socialCategory: string; + birthDate: string; + designation: string; + cadre: string; + profQualification: string; + joiningDate: string; + subjectId: string; + bloodGroup: string; + maritalStatus: string; + blockI: string; + address: string; + compSkills: string; + disability: string; + religion: string; + homeDistance: string; + roles: string; + schoolId: string; + acrId: string; + retirementDate: string; + workingStatus: string; + osCreatedAt: string; + osUpdatedAt: string; + osCreatedBy: string; + osUpdatedBy: string; +} diff --git a/src/teacher/teacher.controller.spec.ts b/src/teacher/teacher.controller.spec.ts index 444e8fb..8ffe140 100644 --- a/src/teacher/teacher.controller.spec.ts +++ b/src/teacher/teacher.controller.spec.ts @@ -1,7 +1,7 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { TeacherController } from './teacher.controller'; +import { Test, TestingModule } from "@nestjs/testing"; +import { TeacherController } from "./teacher.controller"; -describe('TeacherController', () => { +describe("TeacherController", () => { let controller: TeacherController; beforeEach(async () => { @@ -12,7 +12,7 @@ describe('TeacherController', () => { controller = module.get(TeacherController); }); - it('should be defined', () => { + it("should be defined", () => { expect(controller).toBeDefined(); }); }); From 2b3675b7b356476356e36da80a455e8a200ce930 Mon Sep 17 00:00:00 2001 From: Shikhar Vashistha <51105234+shikharvashistha@users.noreply.github.com> Date: Thu, 9 Jun 2022 09:57:28 +0000 Subject: [PATCH 3/4] fix: conflicts --- src/adapters/default/config.adapter.ts | 66 ++++++++++++++------------ 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/adapters/default/config.adapter.ts b/src/adapters/default/config.adapter.ts index 7102692..aff3740 100644 --- a/src/adapters/default/config.adapter.ts +++ b/src/adapters/default/config.adapter.ts @@ -5,15 +5,12 @@ import { AxiosResponse } from "axios"; import { ConfigDto } from "src/configs/dto/config.dto"; import { first, map, Observable } from "rxjs"; import { SuccessResponse } from "src/success-response"; -import { catchError } from "rxjs/operators"; -import { ErrorResponse } from "src/error-response"; -import { ConfigSearchDto } from "src/configs/dto/config-search.dto"; import jwt_decode from "jwt-decode"; import { TeacherDto } from "../../teacher/dto/teacher.dto"; @Injectable() export class ConfigService { constructor(private httpService: HttpService) {} - url = `${process.env.BASEAPIURL}/Config`; + url = `${process.env.BASEAPIURL}Config`; public async createConfig(request: any, configDto: ConfigDto) { let axios = require("axios"); @@ -25,9 +22,6 @@ export class ConfigService { key: { eq: `${configDto.key}`, }, - contextId: { - eq: `${configDto.contextId}`, - }, }, }; @@ -63,28 +57,23 @@ export class ConfigService { data: response.data, }); } else { - return this.httpService - .post(`${this.url}`, configDto, { - headers: { - Authorization: request.headers.authorization, - }, - }) - .pipe( - map((axiosResponse: AxiosResponse) => { - return new SuccessResponse({ - statusCode: 200, - message: "Ok.", - data: axiosResponse.data, - }); - }), - catchError((e) => { - var error = new ErrorResponse({ - errorCode: e.response?.status, - errorMessage: e.response?.data?.params?.errmsg, - }); - throw new HttpException(error, e.response.status); - }) - ); + var createData = configDto; + var createConfig = { + method: "post", + url: `${this.url}`, + headers: { + Authorization: request.headers.authorization, + }, + data: createData, + }; + console.log(createConfig); + const response = await axios(createConfig); + + return new SuccessResponse({ + statusCode: 200, + message: " Ok.", + data: response.data, + }); } } @@ -173,4 +162,21 @@ export class ConfigService { data: result, }); } -} + + public async createModuleConfigs(request: any, configAllData: [Object]) { + configAllData.forEach((element) => { + element["data"].forEach((data) => { + data["module"] = element["module"]; + data["context"] = element["context"] ? element["context"] : ""; + data["contextId"] = element["contextId"] ? element["contextId"] : ""; + data["key"] = data["key"] ? data["key"] : ""; + data["value"] = data["value"] ? data["value"] : []; + data["isPublic"] = data["isPublic"] ? data["isPublic"] : true; + data["canOverride"] = data["canOverride"] ? data["canOverride"] : true; + data["overrideBy"] = data["overrideBy"] ? data["overrideBy"] : ""; + + this.createConfig(request, data); + }); + }); + } +} \ No newline at end of file From a16d7abe20eed95fdf929ec2e516740895f1c697 Mon Sep 17 00:00:00 2001 From: Shikhar Vashistha <51105234+shikharvashistha@users.noreply.github.com> Date: Mon, 4 Jul 2022 11:47:11 +0000 Subject: [PATCH 4/4] feat: Improved attendance search & config update --- .../postgres/attendance.postgres.adapter.ts | 5 ++-- config => src/adapters/postgres/config | 0 src/attendance/dto/attendance-search.dto.ts | 24 +++++++++++++++++++ src/notification/notification.module.ts | 6 ++--- 4 files changed, 29 insertions(+), 6 deletions(-) rename config => src/adapters/postgres/config (100%) diff --git a/src/adapters/postgres/attendance.postgres.adapter.ts b/src/adapters/postgres/attendance.postgres.adapter.ts index 1e7ac2e..065ec24 100644 --- a/src/adapters/postgres/attendance.postgres.adapter.ts +++ b/src/adapters/postgres/attendance.postgres.adapter.ts @@ -4,14 +4,13 @@ import { AttendanceDto } from "src/attendance/dto/attendance.dto"; import { SuccessResponse } from "src/success-response"; import { AttendanceSearchDto } from "src/attendance/dto/attendance-search.dto"; import { Client } from "pg"; -import { AnyAaaaRecord } from "dns"; @Injectable() export class AttendanceService { constructor(private httpService: HttpService) {} url = `${process.env.BASEAPIURL}/Attendance`; studentAPIUrl = `${process.env.BASEAPIURL}/Student`; - public async getAttendance(attendanceId: AnyAaaaRecord) { + public async getAttendance(attendanceId: string) { const client = new Client(); client.connect(); client.query( @@ -77,7 +76,7 @@ export class AttendanceService { const client = new Client(); client.connect(); client.query( - `SELECT * FROM attendance WHERE attendanceRecordId = '${attendanceSearchDto.attendanceRecordId}'`, + `SELECT * FROM attendance WHERE attendanceDate >= '${attendanceSearchDto.attendanceFromDate}' AND attendanceDate <= '${attendanceSearchDto.attendanceToDate} AND studentId = '${attendanceSearchDto.studentId}'`, (err, res) => { if (err) { console.log(err); diff --git a/config b/src/adapters/postgres/config similarity index 100% rename from config rename to src/adapters/postgres/config diff --git a/src/attendance/dto/attendance-search.dto.ts b/src/attendance/dto/attendance-search.dto.ts index cff0339..3c28424 100644 --- a/src/attendance/dto/attendance-search.dto.ts +++ b/src/attendance/dto/attendance-search.dto.ts @@ -7,12 +7,36 @@ export class AttendanceSearchDto { }) limit: string; + @ApiProperty({ + type: String, + description: "Student Id", + }) + studentId: string; + @ApiProperty({ type: String, description: "attendanceRecordId", }) attendanceRecordId: string; + @ApiProperty({ + type: Date, + description: "attendanceToDate", + }) + attendanceToDate: Date; + + @ApiProperty({ + type: Date, + description: "attendanceFromDate", + }) + attendanceFromDate: Date; + + @ApiProperty({ + type: String, + description: "attendance", + }) + attendance: string; + @ApiProperty({ type: Object, description: "Filters", diff --git a/src/notification/notification.module.ts b/src/notification/notification.module.ts index 645947b..9946b7a 100644 --- a/src/notification/notification.module.ts +++ b/src/notification/notification.module.ts @@ -1,8 +1,8 @@ import { CacheModule, Module } from "@nestjs/common"; import { HttpModule } from "@nestjs/axios"; import { NotificationService } from "src/adapters/sunbirdrc/notification.adapter"; -import { instantNotificationController} from "./instantNotification.controller"; -import {scheduleNotificationController} from "./scheduleNotification.controller" +import { instantNotificationController } from "./instantNotification.controller"; +import { scheduleNotificationController } from "./scheduleNotification.controller"; const ttl = process.env.TTL as never; @Module({ imports: [ @@ -11,7 +11,7 @@ const ttl = process.env.TTL as never; ttl: ttl, }), ], - controllers: [instantNotificationController,scheduleNotificationController], + controllers: [instantNotificationController, scheduleNotificationController], providers: [NotificationService], }) export class NotificationModule {}