Skip to content
Snippets Groups Projects
Commit 440ffef5 authored by Antonin COQUET's avatar Antonin COQUET
Browse files

fix: new endpoint for admin pannel, sorting and better algo

parent 49ab8644
No related branches found
No related tags found
3 merge requests!96release V1.10.0,!83Dev,!79feat: add endpoint for unclaimed structure
import { Body, Delete, Param } from '@nestjs/common'; import { Body, Delete, Param, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { Controller, Get, Post, UseGuards } from '@nestjs/common';
import { ApiOperation, ApiParam } from '@nestjs/swagger'; import { ApiOperation, ApiParam } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { NewsletterSubscription } from '../newsletter/newsletter-subscription.schema';
import { NewsletterService } from '../newsletter/newsletter.service'; import { NewsletterService } from '../newsletter/newsletter.service';
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';
...@@ -24,7 +24,7 @@ export class AdminController { ...@@ -24,7 +24,7 @@ export class AdminController {
@ApiOperation({ description: 'Get pending structre for validation' }) @ApiOperation({ description: 'Get pending structre for validation' })
public async getPendingAttachments(): Promise<PendingStructureDto[]> { public async getPendingAttachments(): Promise<PendingStructureDto[]> {
const pendingStructure = await this.usersService.getPendingStructures(); const pendingStructure = await this.usersService.getPendingStructures();
return await Promise.all( return Promise.all(
pendingStructure.map(async (structure) => { pendingStructure.map(async (structure) => {
structure.structureName = (await this.structuresService.findOne(structure.structureId)).structureName; structure.structureName = (await this.structuresService.findOne(structure.structureId)).structureName;
return structure; return structure;
...@@ -32,14 +32,6 @@ export class AdminController { ...@@ -32,14 +32,6 @@ export class AdminController {
); );
} }
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
@Get('unclaimedStructures')
@ApiOperation({ description: 'Get pending structre for validation' })
public async getUnclaimedStructures(): Promise<UnclaimedStructureDto[]> {
return await this.structuresService.findAllUnclaimed();
}
@UseGuards(JwtAuthGuard, RolesGuard) @UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin') @Roles('admin')
@Get('adminStructuresList') @Get('adminStructuresList')
...@@ -50,11 +42,18 @@ export class AdminController { ...@@ -50,11 +42,18 @@ export class AdminController {
structuresList.toClaim = (await this.structuresService.findAllUnclaimed()).filter( structuresList.toClaim = (await this.structuresService.findAllUnclaimed()).filter(
(demand) => !structuresList.inClaim.find((elem) => elem.structureId == demand.structureId) (demand) => !structuresList.inClaim.find((elem) => elem.structureId == demand.structureId)
); );
structuresList.claimed = (await this.structuresService.findAll()).filter( structuresList.claimed = (await this.structuresService.findAll())
(demand) => .filter(
!structuresList.inClaim.find((elem) => elem.structureId == demand.id) && (demand) =>
!structuresList.toClaim.find((elem) => elem.structureId == demand.id) !structuresList.inClaim.find((elem) => elem.structureId == demand.id) &&
); !structuresList.toClaim.find((elem) => elem.structureId == demand.id)
)
.map((structure) => {
return { structureId: structure.id, structureName: structure.structureName };
});
structuresList.claimed.sort((a, b) => a.structureName.localeCompare(b.structureName));
structuresList.inClaim.sort((a, b) => a.structureName.localeCompare(b.structureName));
structuresList.toClaim.sort((a, b) => a.structureName.localeCompare(b.structureName));
return structuresList; return structuresList;
} }
...@@ -71,7 +70,7 @@ export class AdminController { ...@@ -71,7 +70,7 @@ export class AdminController {
true true
); );
const pendingStructure = await this.usersService.getPendingStructures(); const pendingStructure = await this.usersService.getPendingStructures();
return await Promise.all( return Promise.all(
pendingStructure.map(async (pendingStructureData) => { pendingStructure.map(async (pendingStructureData) => {
pendingStructureData.structureName = ( pendingStructureData.structureName = (
await this.structuresService.findOne(pendingStructureData.structureId) await this.structuresService.findOne(pendingStructureData.structureId)
...@@ -94,7 +93,7 @@ export class AdminController { ...@@ -94,7 +93,7 @@ export class AdminController {
false false
); );
const pendingStructure = await this.usersService.getPendingStructures(); const pendingStructure = await this.usersService.getPendingStructures();
return await Promise.all( return Promise.all(
pendingStructure.map(async (pendingStructureData) => { pendingStructure.map(async (pendingStructureData) => {
pendingStructureData.structureName = ( pendingStructureData.structureName = (
await this.structuresService.findOne(pendingStructureData.structureId) await this.structuresService.findOne(pendingStructureData.structureId)
...@@ -149,7 +148,7 @@ export class AdminController { ...@@ -149,7 +148,7 @@ export class AdminController {
@Roles('admin') @Roles('admin')
@Delete('newsletterSubscription/:email') @Delete('newsletterSubscription/:email')
@ApiParam({ name: 'email', type: String, required: true }) @ApiParam({ name: 'email', type: String, required: true })
public async unsubscribeUserFromNewsletter(@Param() params) { public async unsubscribeUserFromNewsletter(@Param() params): Promise<NewsletterSubscription> {
return await this.newsletterService.deleteOneEmail(params.email); return this.newsletterService.deleteOneEmail(params.email);
} }
} }
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