-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,587 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
apps/api/src/modules/signalement/dto/update-signalement-dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Signalement } from 'libs/openapi-signalement'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { ArrayMinSize, IsEnum } from 'class-validator'; | ||
|
||
export class UpdateSignalementDTO { | ||
@ApiProperty({ | ||
type: String, | ||
required: true, | ||
nullable: false, | ||
isArray: true, | ||
}) | ||
@ArrayMinSize(1) | ||
ids: string[]; | ||
|
||
@ApiProperty({ required: true, nullable: false, enum: Signalement.status }) | ||
@IsEnum(Signalement.status) | ||
status: Signalement.status; | ||
} |
59 changes: 59 additions & 0 deletions
59
apps/api/src/modules/signalement/signalement.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Body, | ||
Controller, | ||
HttpStatus, | ||
Inject, | ||
Put, | ||
Req, | ||
Res, | ||
UseGuards, | ||
forwardRef, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiBody, | ||
ApiOperation, | ||
ApiParam, | ||
ApiResponse, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { Response } from 'express'; | ||
|
||
import { AdminGuard } from '@/lib/guards/admin.guard'; | ||
import { CustomRequest } from '@/lib/types/request.type'; | ||
import { SignalementService } from './signalement.service'; | ||
import { UpdateSignalementDTO } from './dto/update-signalement-dto'; | ||
|
||
@ApiTags('signalements') | ||
@Controller('signalements') | ||
export class SignalementController { | ||
constructor( | ||
@Inject(forwardRef(() => SignalementService)) | ||
private signalementService: SignalementService, | ||
) {} | ||
|
||
@Put(':baseLocaleId') | ||
@ApiOperation({ | ||
summary: 'Update signalements', | ||
operationId: 'updateSignalements', | ||
}) | ||
@ApiParam({ name: 'baseLocaleId', required: true, type: String }) | ||
@ApiBody({ type: UpdateSignalementDTO, required: true }) | ||
@ApiResponse({ | ||
status: HttpStatus.OK, | ||
type: Boolean, | ||
}) | ||
@ApiBearerAuth('admin-token') | ||
@UseGuards(AdminGuard) | ||
async create( | ||
@Req() req: CustomRequest, | ||
@Body() updateSignalementDTO: UpdateSignalementDTO, | ||
@Res() res: Response, | ||
) { | ||
await this.signalementService.updateMany( | ||
req.baseLocale, | ||
updateSignalementDTO, | ||
); | ||
res.status(HttpStatus.OK).json(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Module, MiddlewareConsumer, forwardRef } from '@nestjs/common'; | ||
|
||
import { BaseLocaleMiddleware } from '@/modules/base_locale/base_locale.middleware'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { BaseLocaleModule } from '../base_locale/base_locale.module'; | ||
import { SignalementService } from './signalement.service'; | ||
import { SignalementController } from './signalement.controller'; | ||
|
||
@Module({ | ||
imports: [ConfigModule, forwardRef(() => BaseLocaleModule)], | ||
providers: [SignalementService], | ||
controllers: [SignalementController], | ||
exports: [SignalementService], | ||
}) | ||
export class SignalementModule { | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer.apply(BaseLocaleMiddleware).forRoutes(SignalementController); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
BaseLocale, | ||
StatusBaseLocalEnum, | ||
} from '@/shared/entities/base_locale.entity'; | ||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
import { UpdateSignalementDTO } from './dto/update-signalement-dto'; | ||
import { | ||
SignalementsService, | ||
OpenAPI as OpenAPISignalement, | ||
} from 'libs/openapi-signalement'; | ||
|
||
@Injectable() | ||
export class SignalementService { | ||
constructor(private configService: ConfigService) { | ||
OpenAPISignalement.BASE = this.configService.get('API_SIGNALEMENT_URL'); | ||
OpenAPISignalement.TOKEN = this.configService.get( | ||
'API_SIGNALEMENT_CLIENT_SECRET', | ||
); | ||
} | ||
|
||
async updateMany( | ||
baseLocale: BaseLocale, | ||
updateSignalementDTO: UpdateSignalementDTO, | ||
) { | ||
const { ids, status } = updateSignalementDTO; | ||
|
||
if (baseLocale.status !== StatusBaseLocalEnum.PUBLISHED) { | ||
throw new HttpException( | ||
'BaseLocale is not published', | ||
HttpStatus.PRECONDITION_FAILED, | ||
); | ||
} | ||
|
||
for (const signalementId of ids) { | ||
const fetchedSignalement = | ||
await SignalementsService.getSignalementById(signalementId); | ||
|
||
if (!fetchedSignalement) { | ||
throw new HttpException( | ||
`Signalement ${signalementId} not found`, | ||
HttpStatus.NOT_FOUND, | ||
); | ||
} | ||
|
||
if (baseLocale.commune !== fetchedSignalement.codeCommune) { | ||
throw new HttpException( | ||
`Communes do not match for signalement ${signalementId}`, | ||
HttpStatus.PRECONDITION_FAILED, | ||
); | ||
} | ||
|
||
await SignalementsService.updateSignalement(signalementId, { | ||
status, | ||
}); | ||
} | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.