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

Create & search altprogram & altprogramassociation #37

Open
wants to merge 2 commits into
base: altv1
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
31 changes: 22 additions & 9 deletions src/adapters/hasura/altProgram.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -181,7 +187,6 @@ export class ProgramService implements IProgramServicelocator {
}

const result = response.data.data.insert_AssessProgram_one;

return new SuccessResponse({
statusCode: 200,
message: "Ok.",
Expand All @@ -190,7 +195,7 @@ export class ProgramService implements IProgramServicelocator {
}

// public async updateProgram(
// request: any,
// request: any,
// programId: string,
// updateAltProgramDto: UpdateALTProgramDto
// ) {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand Down
49 changes: 34 additions & 15 deletions src/adapters/hasura/altProgramAssociation.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions src/altProgram/dto/searchAltProgram.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ALTProgramSearch>) {
Object.assign(this, partial);
Expand Down
12 changes: 5 additions & 7 deletions src/altProgramAssociation/dto/altProgramAssociation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -61,11 +63,7 @@ export class ProgramAssociationDto {
})
programId: string;

@Expose()
created_at: string;

@Expose()
updated_at: string;


constructor(obj: any) {
Object.assign(this, obj);
Expand Down
19 changes: 16 additions & 3 deletions src/altProgramAssociation/dto/searchAltProgramAssociation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ALTProgramAssociationSearch>) {
Object.assign(this, partial);
}
Expand Down
4 changes: 2 additions & 2 deletions src/groupMembership/dto/groupMembership-search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export class GroupMembershipSearchDto {
page: number;

@ApiProperty({
type: GroupMembershipDto,
type: Object,
description: "Filters",
})
@ApiPropertyOptional()
filters: GroupMembershipDto;
filters: Object;

constructor(partial: Partial<GroupMembershipSearchDto>) {
Object.assign(this, partial);
Expand Down
8 changes: 4 additions & 4 deletions src/groupMembership/dto/groupMembership.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ export class GroupMembershipDto {
@Expose()
groupMembershipId: string;

// @ApiProperty()
@ApiProperty()
@Expose()
groupId: string;

// @ApiProperty()
@ApiProperty()
@Expose()
schoolId: string;
schoolUdise: string;

@ApiProperty()
@Expose()
@IsNotEmpty()
@IsUUID()
userId: string;

// @ApiProperty()
@ApiProperty()
@Expose()
role: string;

Expand Down