Skip to content
Snippets Groups Projects
Commit 29636923 authored by Etienne LOUPIAS's avatar Etienne LOUPIAS
Browse files

feat(dashboard) : get user orientations

parent b919bc66
No related branches found
No related tags found
1 merge request!479Draft: feat(dashboard) : create dashboard !
Pipeline #123555 passed
import { Body, Controller, Get, Logger, Post, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Logger, Post, Request, UseGuards } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { OrientationDto } from './dto/orientation.dto';
import { IOrientation } from './interfaces/orientation.interface';
import { OrientationService } from './orientation.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { RolesGuard } from '../users/guards/roles.guard';
import { Roles } from '../users/decorators/roles.decorator';
@ApiTags('orientation')
@Controller('orientation')
......@@ -14,12 +16,23 @@ export class OrientationController {
@Get()
@UseGuards(JwtAuthGuard)
@ApiOperation({ summary: 'Get user orientations' })
@ApiResponse({ status: 200, description: 'Return user orientations with populated details.' })
@ApiResponse({ status: 500, description: 'Internal server error.' })
public async find(@Request() req): Promise<IOrientation[]> {
this.logger.debug('find for user ' + req.user._id);
return this.orientationService.find(req.user._id);
}
@Get('admin')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiOperation({ summary: 'Get all orientations with full details' })
@ApiResponse({ status: 200, description: 'Return all orientations with populated details.' })
@ApiResponse({ status: 500, description: 'Internal server error.' })
public async findAllWithDetails(): Promise<IOrientation[]> {
this.logger.debug('findAllWithDetails');
return this.orientationService.findAll();
return this.orientationService.find();
}
@Post()
......
......@@ -4,9 +4,14 @@ import { OrientationController } from './orientation.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { Orientation, OrientationSchema } from './orientation.schema';
import { CategoriesModule } from '../categories/categories.module';
import { UsersModule } from '../users/users.module';
@Module({
imports: [MongooseModule.forFeature([{ name: Orientation.name, schema: OrientationSchema }]), CategoriesModule],
imports: [
MongooseModule.forFeature([{ name: Orientation.name, schema: OrientationSchema }]),
CategoriesModule,
UsersModule,
],
providers: [OrientationService],
controllers: [OrientationController],
})
......
......@@ -5,6 +5,7 @@ import { customStructureDto, OrientationDto } from './dto/orientation.dto';
import { IOrientation } from './interfaces/orientation.interface';
import { Orientation, OrientationDocument } from './orientation.schema';
import { CategoriesService } from '../categories/services/categories.service';
import { UsersService } from '../users/services/users.service';
@Injectable()
export class OrientationService {
......@@ -12,6 +13,7 @@ export class OrientationService {
constructor(
@InjectModel(Orientation.name) private OrientationModel: Model<OrientationDocument>,
private userService: UsersService,
private categoriesService: CategoriesService
) {}
......@@ -25,8 +27,15 @@ export class OrientationService {
}
}
public async findAll(): Promise<IOrientation[]> {
public async find(userId: string = null, structureId: string = null): Promise<IOrientation[]> {
try {
if (structureId) {
this.logger.log(`find for structureId=${structureId}`);
} else if (userId) {
this.logger.log(`find for userId=${userId}`);
const user = await this.userService.findById(userId, true);
}
const orientations = await this.OrientationModel.find()
.populate('structureChoice', 'structureName')
.populate('socialWorker', 'name surname')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment