diff --git a/backend/src/insurance/insurance.controller.ts b/backend/src/insurance/insurance.controller.ts index 47eb260..e101f6b 100644 --- a/backend/src/insurance/insurance.controller.ts +++ b/backend/src/insurance/insurance.controller.ts @@ -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) {} @@ -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'}) + } + } } diff --git a/backend/src/insurance/insurance.schema.ts b/backend/src/insurance/insurance.schema.ts index 90f4bdd..7c9b7c9 100644 --- a/backend/src/insurance/insurance.schema.ts +++ b/backend/src/insurance/insurance.schema.ts @@ -8,6 +8,7 @@ export interface IInsurancePlan extends Document { eligibility: string; productId?: string; priceId?: string; + providerId: string; } const InsurancePlanSchema = new Schema( @@ -19,6 +20,7 @@ const InsurancePlanSchema = new Schema( eligibility: { type: String, required: true }, productId: { type: String, default: null }, priceId: { type: String, default: null }, + providerId: { type: String, required: true}, }, { timestamps: true } ); diff --git a/backend/src/insurance/insurance.service.ts b/backend/src/insurance/insurance.service.ts index 8c3ac7a..c79b254 100644 --- a/backend/src/insurance/insurance.service.ts +++ b/backend/src/insurance/insurance.service.ts @@ -84,4 +84,15 @@ export class InsuranceService { } return plan; } + + async getByProvider(providerId: string): Promise + { + const plans = await InsurancePlan.find({ providerId }); + + if (!plans || plans.length == 0) + { + throw new NotFoundException('Plans not found') + } + return plans; + } } diff --git a/backend/src/services/service.controller.ts b/backend/src/services/service.controller.ts index a54ae25..3f94195 100644 --- a/backend/src/services/service.controller.ts +++ b/backend/src/services/service.controller.ts @@ -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 { @@ -25,6 +31,7 @@ export class ServiceController } } + @Get() async getAllServices(@Res() response) { @@ -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."}) + } + } } diff --git a/backend/src/services/service.schema.ts b/backend/src/services/service.schema.ts index d116035..a10bcb5 100644 --- a/backend/src/services/service.schema.ts +++ b/backend/src/services/service.schema.ts @@ -7,6 +7,7 @@ export interface IService extends Document { location: string; eligibility: string; languagesSupported: string[]; + providerId: string; } const ServiceSchema = new Schema( @@ -17,6 +18,7 @@ const ServiceSchema = new Schema( location: { type: String, required: true }, eligibility: { type: String, required: true }, languagesSupported: { type: [String], default: [] }, + providerId: { type: String, required: true } }, { timestamps: true } ); diff --git a/backend/src/services/service.service.ts b/backend/src/services/service.service.ts index 4e25212..e9b95bd 100644 --- a/backend/src/services/service.service.ts +++ b/backend/src/services/service.service.ts @@ -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 { + const newService = new Service(createServiceDto); return newService.save(); } @@ -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 + { + console.log('providerid', providerId); + + const services = await Service.find({ providerId }); + + if (!services || services.length == 0) + { + throw new NotFoundException('Services not found') + } + return services; + } + } diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json new file mode 100644 index 0000000..6c46cc9 --- /dev/null +++ b/node_modules/.package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "healthcare-connect", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..6c46cc9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "healthcare-connect", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}