diff --git a/src/adapters/hasura/altProgram.adapter.ts b/src/adapters/hasura/altProgram.adapter.ts index 1cfa38e..d6855d1 100644 --- a/src/adapters/hasura/altProgram.adapter.ts +++ b/src/adapters/hasura/altProgram.adapter.ts @@ -7,6 +7,8 @@ import { IProgramServicelocator } from "../programservicelocator"; import { ErrorResponse } from "src/error-response"; import { UpdateALTProgramDto } from "src/altProgram/dto/updateAltProgram.dto"; import { ALTProgramSearch } from "src/altProgram/dto/searchAltProgram.dto"; +import { getUserRole } from "./adapter.utils"; +import jwt_decode from "jwt-decode"; @Injectable() export class ProgramService implements IProgramServicelocator { @@ -32,7 +34,7 @@ export class ProgramService implements IProgramServicelocator { return programResponse; } - public async getProgramDetailsById(request: any,programId: string) { + public async getProgramDetailsById(request: any, programId: string) { const programData = { query: `query GetProgramDetailsById ($programId:uuid!) { AssessProgram_by_pk(programId:$programId) { @@ -55,7 +57,7 @@ export class ProgramService implements IProgramServicelocator { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, "Content-Type": "application/json", }, data: programData, @@ -111,7 +113,7 @@ export class ProgramService implements IProgramServicelocator { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, "Content-Type": "application/json", }, data: programData, @@ -140,6 +142,9 @@ export class ProgramService implements IProgramServicelocator { } public async createProgram(request: any, programdto: ProgramDto) { + const decoded: any = jwt_decode(request.headers.authorization); + const altUserRoles = + decoded["https://hasura.io/jwt/claims"]["x-hasura-allowed-roles"]; const programSchema = new ProgramDto(programdto); let newProgramData = ""; Object.keys(programdto).forEach((key) => { @@ -160,12 +165,13 @@ export class ProgramService implements IProgramServicelocator { }`, variables: {}, }; - const configData = { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, + "x-hasura-role": getUserRole(altUserRoles), + "Content-Type": "application/json", }, data: programData, @@ -181,7 +187,6 @@ export class ProgramService implements IProgramServicelocator { } const result = response.data.data.insert_AssessProgram_one; - return new SuccessResponse({ statusCode: 200, message: "Ok.", @@ -190,7 +195,7 @@ export class ProgramService implements IProgramServicelocator { } // public async updateProgram( - // request: any, + // request: any, // programId: string, // updateAltProgramDto: UpdateALTProgramDto // ) { @@ -259,8 +264,14 @@ export class ProgramService implements IProgramServicelocator { // }); // } - public async searchALTProgram(request: any,altProgramSearch: ALTProgramSearch) { + public async searchALTProgram( + request: any, + altProgramSearch: ALTProgramSearch + ) { var axios = require("axios"); + const decoded: any = jwt_decode(request.headers.authorization); + const altUserRoles = + decoded["https://hasura.io/jwt/claims"]["x-hasura-allowed-roles"]; let query = ""; Object.keys(altProgramSearch.filters).forEach((e) => { @@ -295,7 +306,9 @@ export class ProgramService implements IProgramServicelocator { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, + "x-hasura-role": getUserRole(altUserRoles), + "Content-Type": "application/json", }, data: searchData, diff --git a/src/adapters/hasura/altProgramAssociation.adapter.ts b/src/adapters/hasura/altProgramAssociation.adapter.ts index f349270..fa6ac06 100644 --- a/src/adapters/hasura/altProgramAssociation.adapter.ts +++ b/src/adapters/hasura/altProgramAssociation.adapter.ts @@ -7,6 +7,8 @@ import { ProgramAssociationDto } from "src/altProgramAssociation/dto/altProgramA import { UpdateALTProgramAssociationDto } from "src/altProgramAssociation/dto/updateAltProgramAssociation.dto"; import { ErrorResponse } from "src/error-response"; import { ALTProgramAssociationSearch } from "src/altProgramAssociation/dto/searchAltProgramAssociation.dto"; +import jwt_decode from "jwt-decode"; +import { getUserRole } from "./adapter.utils"; Injectable(); export class ALTProgramAssociationService { @@ -61,7 +63,7 @@ export class ALTProgramAssociationService { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, "Content-Type": "application/json", }, data: subjectListData, @@ -114,7 +116,7 @@ export class ALTProgramAssociationService { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, "Content-Type": "application/json", }, data: TermsProgramtoRulesData, @@ -143,12 +145,15 @@ export class ALTProgramAssociationService { programAssociationDto: ProgramAssociationDto ) { const programSchema = new ProgramAssociationDto(programAssociationDto); - + const decoded: any = jwt_decode(request.headers.authorization); + const altUserRoles = + decoded["https://hasura.io/jwt/claims"]["x-hasura-allowed-roles"]; let newProgramAssociationData = ""; + Object.keys(programAssociationDto).forEach((key) => { if ( - programAssociationDto[key] && - programAssociationDto[key] != "" && + // programAssociationDto[key] && + // programAssociationDto[key] != "" && Object.keys(programSchema).includes(key) ) { newProgramAssociationData += `${key}: ${JSON.stringify( @@ -157,27 +162,41 @@ export class ALTProgramAssociationService { } }); + const rulesString = JSON.stringify(programAssociationDto.rules); + const programData = { - query: `mutation CreateProgram { - insert_ProgramTermAssoc_one(object: {${newProgramAssociationData}}) { - progAssocNo - } - }`, - variables: {}, + query: ` mutation CreateProgram($rules: String) { + insert_ProgramTermAssoc_one(object: { + board: "${programAssociationDto.board}", + medium: "${programAssociationDto.medium}", + grade: "${programAssociationDto.grade}", + subject: "${programAssociationDto.subject}", + programId: "${programAssociationDto.programId}", + rules: $rules + }) { + progAssocNo + board + medium + grade + } + }`, + variables: { + rules: rulesString, + }, }; - const configData = { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, + "x-hasura-role": getUserRole(altUserRoles), + "Content-Type": "application/json", }, data: programData, }; const response = await this.axios(configData); - if (response?.data?.errors) { return new ErrorResponse({ errorCode: response.data.errors[0].extensions, @@ -301,7 +320,7 @@ export class ALTProgramAssociationService { method: "post", url: process.env.ALTHASURA, headers: { - "Authorization": request.headers.authorization, + Authorization: request.headers.authorization, "Content-Type": "application/json", }, data: searchData, diff --git a/src/altProgram/dto/searchAltProgram.dto.ts b/src/altProgram/dto/searchAltProgram.dto.ts index 7360950..bb1138c 100644 --- a/src/altProgram/dto/searchAltProgram.dto.ts +++ b/src/altProgram/dto/searchAltProgram.dto.ts @@ -9,11 +9,24 @@ export class ALTProgramSearch { limit: number; @ApiProperty({ - type: ProgramDto, + type: Number, + description: "Page", + }) + page: number; + + @ApiProperty({ + type: Object, description: "Filters", }) @ApiPropertyOptional() - filters: ProgramDto; + filters: Object; + + // @ApiProperty({ + // type: Object, + // description: "Filters", + // }) + // @ApiPropertyOptional() + // filters: object; constructor(partial: Partial) { Object.assign(this, partial); diff --git a/src/altProgramAssociation/dto/altProgramAssociation.dto.ts b/src/altProgramAssociation/dto/altProgramAssociation.dto.ts index 0503c17..d9dcddf 100644 --- a/src/altProgramAssociation/dto/altProgramAssociation.dto.ts +++ b/src/altProgramAssociation/dto/altProgramAssociation.dto.ts @@ -47,10 +47,12 @@ export class ProgramAssociationDto { @IsString() @IsNotEmpty() @ApiProperty({ - type: String, + type: Object, description: "Rules of respctive courses", }) - rules: string; + rules: object; + + @Expose() @IsUUID() @@ -61,11 +63,7 @@ export class ProgramAssociationDto { }) programId: string; - @Expose() - created_at: string; - - @Expose() - updated_at: string; + constructor(obj: any) { Object.assign(this, obj); diff --git a/src/altProgramAssociation/dto/searchAltProgramAssociation.dto.ts b/src/altProgramAssociation/dto/searchAltProgramAssociation.dto.ts index ea88a37..ca5eaf1 100644 --- a/src/altProgramAssociation/dto/searchAltProgramAssociation.dto.ts +++ b/src/altProgramAssociation/dto/searchAltProgramAssociation.dto.ts @@ -8,13 +8,26 @@ export class ALTProgramAssociationSearch { }) limit: number; + @ApiProperty({ - type: ProgramAssociationDto, + type: Number, + description: "Page", + }) + page: number; + + // @ApiProperty({ + // type: ProgramAssociationDto, + // description: "Filters", + // }) + // @ApiPropertyOptional() + // filters: ProgramAssociationDto; + + @ApiProperty({ + type: Object, description: "Filters", }) @ApiPropertyOptional() - filters: ProgramAssociationDto; - + filters: Object; constructor(partial: Partial) { Object.assign(this, partial); } diff --git a/src/groupMembership/dto/groupMembership-search.dto.ts b/src/groupMembership/dto/groupMembership-search.dto.ts index 402dbb3..de85c3b 100644 --- a/src/groupMembership/dto/groupMembership-search.dto.ts +++ b/src/groupMembership/dto/groupMembership-search.dto.ts @@ -15,11 +15,11 @@ export class GroupMembershipSearchDto { page: number; @ApiProperty({ - type: GroupMembershipDto, + type: Object, description: "Filters", }) @ApiPropertyOptional() - filters: GroupMembershipDto; + filters: Object; constructor(partial: Partial) { Object.assign(this, partial); diff --git a/src/groupMembership/dto/groupMembership.dto.ts b/src/groupMembership/dto/groupMembership.dto.ts index 87d4de6..a32210b 100644 --- a/src/groupMembership/dto/groupMembership.dto.ts +++ b/src/groupMembership/dto/groupMembership.dto.ts @@ -6,13 +6,13 @@ export class GroupMembershipDto { @Expose() groupMembershipId: string; - // @ApiProperty() + @ApiProperty() @Expose() groupId: string; - // @ApiProperty() + @ApiProperty() @Expose() - schoolId: string; + schoolUdise: string; @ApiProperty() @Expose() @@ -20,7 +20,7 @@ export class GroupMembershipDto { @IsUUID() userId: string; - // @ApiProperty() + @ApiProperty() @Expose() role: string;