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

Created the endpoints for getProvider for insurance and service #56

Open
wants to merge 1 commit 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: 13 additions & 1 deletion backend/src/insurance/insurance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { InsuranceService } from './insurance.service';
import { IInsurancePlan } from './insurance.schema';
import { JwtGuard } from '../auth/jwt-auth.guard';

@UseGuards(JwtGuard)
@Controller('insurance-plan')
export class InsuranceController {
constructor(private readonly insuranceService: InsuranceService) {}
Expand Down Expand Up @@ -84,4 +83,17 @@ export class InsuranceController {
return res.status(404).json({message: 'Error: No insurances by that ID was found'})
}
}

@Get('/provider/:providerId')
async getInsurancePlanByProvider(@Param('providerId') providerId: string, @Res() res){
try
{
const plan = await this.insuranceService.getByProvider(providerId);
return res.status(200).json(plan);
}
catch(error)
{
return res.status(404).json({message: 'Error: No insurances by that provider ID was found'})
}
}
}
2 changes: 2 additions & 0 deletions backend/src/insurance/insurance.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IInsurancePlan extends Document {
eligibility: string;
productId?: string;
priceId?: string;
providerId: string;
}

const InsurancePlanSchema = new Schema<IInsurancePlan>(
Expand All @@ -19,6 +20,7 @@ const InsurancePlanSchema = new Schema<IInsurancePlan>(
eligibility: { type: String, required: true },
productId: { type: String, default: null },
priceId: { type: String, default: null },
providerId: { type: String, required: true},
},
{ timestamps: true }
);
Expand Down
11 changes: 11 additions & 0 deletions backend/src/insurance/insurance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,15 @@ export class InsuranceService {
}
return plan;
}

async getByProvider(providerId: string): Promise<IInsurancePlan[]>
{
const plans = await InsurancePlan.find({ providerId });

if (!plans || plans.length == 0)
{
throw new NotFoundException('Plans not found')
}
return plans;
}
}
26 changes: 24 additions & 2 deletions backend/src/services/service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import { Controller, Post, Get, Put, Delete, Res, Body, Param, Req, Query, UseGu
import { ServiceService } from './service.service';
import { CreateServiceDto } from './dto/create-service.dto';
import { JwtGuard } from '../auth/jwt-auth.guard';
import { RolesGuard } from 'src/auth/roles.guard';
import { AuthGuard } from '@nestjs/passport';
import { Roles } from 'src/auth/roles.decorator';
import { Request } from 'express';

@UseGuards(JwtGuard)
// @UseGuards(JwtGuard, RolesGuard, AuthGuard('jwt'))
@Controller('service')
export class ServiceController
{
constructor(private readonly serviceService: ServiceService) {}

@Roles('admin', 'provider')

@Post()
async createService(@Res() response, @Body() createServiceDto: CreateServiceDto)
async createService(@Res() response, @Body() createServiceDto: CreateServiceDto, @Req() req: Request)
{
try
{
Expand All @@ -25,6 +31,7 @@ export class ServiceController
}
}


@Get()
async getAllServices(@Res() response)
{
Expand Down Expand Up @@ -129,5 +136,20 @@ export class ServiceController
return res.status(400).json({ message: error.message });
}
}

@Get('provider/:providerId')
async filterServicesByProvider(
@Param('providerId') providerId: string,
@Res() res)
{
try
{
const services = await this.serviceService.getByProvider(providerId);
return res.status(200).json(services);
} catch (error: any)
{
return res.status(400).json({ message: "Error: Service not found."})
}
}
}

2 changes: 2 additions & 0 deletions backend/src/services/service.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IService extends Document {
location: string;
eligibility: string;
languagesSupported: string[];
providerId: string;
}

const ServiceSchema = new Schema<IService>(
Expand All @@ -17,6 +18,7 @@ const ServiceSchema = new Schema<IService>(
location: { type: String, required: true },
eligibility: { type: String, required: true },
languagesSupported: { type: [String], default: [] },
providerId: { type: String, required: true }
},
{ timestamps: true }
);
Expand Down
18 changes: 17 additions & 1 deletion backend/src/services/service.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { IService, Service } from './service.schema';
import { CreateServiceDto } from './dto/create-service.dto';
import { Request } from 'express';

@Injectable()
export class ServiceService {

async create(createServiceDto: CreateServiceDto): Promise<IService> {

const newService = new Service(createServiceDto);
return newService.save();
}
Expand Down Expand Up @@ -55,12 +57,26 @@ export class ServiceService {
console.log('Found Services:', services);

// Throw exception if no services are found
if (!services || services.length === 0) {
if (!services || services.length === 0)
{
throw new NotFoundException('Services not found');
}

return services;
}

async getByProvider(providerId: string): Promise<IService[]>
{
console.log('providerid', providerId);

const services = await Service.find({ providerId });

if (!services || services.length == 0)
{
throw new NotFoundException('Services not found')
}
return services;
}

}

6 changes: 6 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.