Skip to content
Snippets Groups Projects
Commit ceace060 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

Merge branch '272-restore-deleted-structure' into 'dev'

feat(admin): restore deleted structure

See merge request !281
parents 41bd3352 02ae043a
No related branches found
No related tags found
2 merge requests!294V2.3.0,!281feat(admin): restore deleted structure
...@@ -16,7 +16,7 @@ import { validate } from 'class-validator'; ...@@ -16,7 +16,7 @@ import { validate } from 'class-validator';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { NewsletterSubscription } from '../newsletter/newsletter-subscription.schema'; import { NewsletterSubscription } from '../newsletter/newsletter-subscription.schema';
import { NewsletterService } from '../newsletter/newsletter.service'; import { NewsletterService } from '../newsletter/newsletter.service';
import { Structure } from '../structures/schemas/structure.schema'; import { Structure, StructureDocument } from '../structures/schemas/structure.schema';
import { StructuresService } from '../structures/services/structures.service'; import { StructuresService } from '../structures/services/structures.service';
import { Roles } from '../users/decorators/roles.decorator'; import { Roles } from '../users/decorators/roles.decorator';
import { RolesGuard } from '../users/guards/roles.guard'; import { RolesGuard } from '../users/guards/roles.guard';
...@@ -315,10 +315,21 @@ export class AdminController { ...@@ -315,10 +315,21 @@ export class AdminController {
@ApiBearerAuth('JWT') @ApiBearerAuth('JWT')
@ApiOperation({ description: 'Get deleted structures' }) @ApiOperation({ description: 'Get deleted structures' })
@Get('getDeletedStructures') @Get('getDeletedStructures')
public async getDeletedStructures() { public async getDeletedStructures(): Promise<StructureDocument[]> {
this.logger.debug('getDeletedStructures'); this.logger.debug('getDeletedStructures');
const deletedStructures = await this.structuresService.findAll(true); const deletedStructures = await this.structuresService.findAll(true);
this.logger.debug(`Found ${deletedStructures.length} deleted structures`); this.logger.debug(`Found ${deletedStructures.length} deleted structures`);
return deletedStructures; return deletedStructures;
} }
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@ApiBearerAuth('JWT')
@ApiOperation({ description: 'Get deleted structures' })
@Post('restoreDeletedStructure/:structureId')
public async restoreDeletedStructures(@Param('structureId') structureId: string): Promise<void> {
this.logger.debug(`restoreDeletedStructures: ${structureId}`);
await this.structuresService.restoreStructure(structureId);
await this.structuresService.initiateStructureIndex();
}
} }
...@@ -619,4 +619,13 @@ describe('StructuresService', () => { ...@@ -619,4 +619,13 @@ describe('StructuresService', () => {
expect(mockSetCNFSid).toHaveBeenCalledTimes(2); expect(mockSetCNFSid).toHaveBeenCalledTimes(2);
}); });
}); });
describe('restoreStructure', () => {
it('should restore a structure', async () => {
mockStructureModel.findByIdAndUpdate.mockReturnThis();
mockStructureModel.exec.mockImplementation(() => null);
await service.restoreStructure('someId');
expect(mockStructureModel.findByIdAndUpdate).toBeCalled();
});
});
}); });
...@@ -1158,4 +1158,9 @@ export class StructuresService { ...@@ -1158,4 +1158,9 @@ export class StructuresService {
} }
return null; return null;
} }
public async restoreStructure(structureId: string) {
this.logger.debug(`restoreDeletedStructures: ${structureId}`);
this.structureModel.findByIdAndUpdate(structureId, { $unset: { deletedAt: 1 } }).exec();
}
} }
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