File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
src/management/identities Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,18 @@ export class IdentitiesActivationController extends AbstractController {
1515 @Post ( 'activation' )
1616 @ApiOperation ( { summary : 'active/desactive l identité' } )
1717 @ApiResponse ( { status : HttpStatus . OK } )
18- public async activation ( @Res ( ) res : Response , @Body ( ) body :ActivationDto ) : Promise < Response > {
19- const data = this . _service . activation ( body . id , body . status )
20- return res . status ( HttpStatus . OK ) . json ( {
21- statusCode : HttpStatus . OK ,
22- data,
23- } ) ;
18+ public async activation ( @Res ( ) res : Response , @Body ( ) body : ActivationDto ) : Promise < Response > {
19+ try {
20+ const data = await this . _service . activation ( body . id , body . status ) ;
21+ return res . status ( HttpStatus . OK ) . json ( {
22+ statusCode : HttpStatus . OK ,
23+ data,
24+ } ) ;
25+ } catch ( error ) {
26+ return res . status ( HttpStatus . BAD_REQUEST ) . json ( {
27+ statusCode : HttpStatus . BAD_REQUEST ,
28+ message : error . message ,
29+ } ) ;
30+ }
2431 }
2532}
Original file line number Diff line number Diff line change 11import { AbstractIdentitiesService } from '~/management/identities/abstract-identities.service' ;
22import { Identities } from '~/management/identities/_schemas/identities.schema' ;
3- import { BadRequestException } from '@nestjs/common' ;
3+ import { BadRequestException , HttpException } from '@nestjs/common' ;
44import { DataStatusEnum } from '~/management/identities/_enums/data-status' ;
55import { JobState } from '~/core/jobs/_enums/state.enum' ;
66
@@ -12,7 +12,10 @@ export class IdentitiesActivationService extends AbstractIdentitiesService {
1212 try {
1313 identity = await this . findById < Identities > ( id ) ;
1414 } catch ( error ) {
15- throw new BadRequestException ( 'Id1 not found' ) ;
15+ throw new HttpException ( 'Id not found' , 400 ) ;
16+ }
17+ if ( identity . lastBackendSync === null ) {
18+ throw new HttpException ( 'Identity has never been synced' , 400 ) ;
1619 }
1720 if ( identity . dataStatus !== DataStatusEnum . DELETED ) {
1821 if ( status ) {
@@ -36,7 +39,7 @@ export class IdentitiesActivationService extends AbstractIdentitiesService {
3639 if ( result . state === JobState . COMPLETED ) {
3740 await super . update ( identity . _id , identity ) ;
3841 } else {
39- throw new BadRequestException ( 'Backend failed' ) ;
42+ throw new HttpException ( 'Backend failed' , 400 ) ;
4043 }
4144 }
4245 }
You can’t perform that action at this time.
0 commit comments