Commit 01d56659 authored by Rémi PAILHAREY's avatar Rémi PAILHAREY
Browse files

feat(admin): now display last update date next to structure names

parent 9f2cb1b9
......@@ -71,7 +71,7 @@ describe('AdminController', () => {
it('should get pending attachments', async () => {
expect((await controller.getPendingAttachments()).length).toBe(2);
expect(Object.keys((await controller.getPendingAttachments())[0]).length).toBe(3);
expect(Object.keys((await controller.getPendingAttachments())[0]).length).toBe(4);
});
describe('Pending structures validation', () => {
......@@ -80,9 +80,10 @@ describe('AdminController', () => {
structureId: '6093ba0e2ab5775cfc01ed3e',
structureName: 'test',
userEmail: 'jean.paul@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
};
expect((await controller.validatePendingStructure(pendingStructureTest)).length).toBe(2);
expect(Object.keys((await controller.validatePendingStructure(pendingStructureTest))[0]).length).toBe(3);
expect(Object.keys((await controller.validatePendingStructure(pendingStructureTest))[0]).length).toBe(4);
});
it('should get structure does not exist', async () => {
......@@ -90,6 +91,7 @@ describe('AdminController', () => {
structureId: '1093ba0e2ab5775cfc01z2ki',
structureName: 'test',
userEmail: 'jean.paul@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
};
try {
await controller.validatePendingStructure(pendingStructureTest);
......@@ -106,9 +108,10 @@ describe('AdminController', () => {
structureId: '6093ba0e2ab5775cfc01ed3e',
structureName: 'test',
userEmail: 'jean.paul@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
};
expect((await controller.refusePendingStructure(pendingStructureTest)).length).toBe(2);
expect(Object.keys((await controller.refusePendingStructure(pendingStructureTest))[0]).length).toBe(3);
expect(Object.keys((await controller.refusePendingStructure(pendingStructureTest))[0]).length).toBe(4);
});
it('should get structure does not exist', async () => {
......@@ -116,6 +119,7 @@ describe('AdminController', () => {
structureId: '1093ba0e2ab5775cfc01z2ki',
structureName: 'test',
userEmail: 'jean.paul@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
};
try {
await controller.refusePendingStructure(pendingStructureTest);
......
......@@ -22,6 +22,7 @@ import { PendingStructureDto } from './dto/pending-structure.dto';
import { validate } from 'class-validator';
import { Structure } from '../structures/schemas/structure.schema';
import { IUser } from '../users/interfaces/user.interface';
import { DateTime, Interval } from 'luxon';
@Controller('admin')
export class AdminController {
......@@ -40,7 +41,9 @@ export class AdminController {
const pendingStructure = await this.usersService.getPendingStructures();
return Promise.all(
pendingStructure.map(async (structure) => {
structure.structureName = (await this.structuresService.findOne(structure.structureId)).structureName;
const structureDocument = await this.structuresService.findOne(structure.structureId);
structure.structureName = structureDocument.structureName;
structure.updatedAt = structureDocument.updatedAt;
return structure;
})
);
......@@ -52,10 +55,27 @@ export class AdminController {
@ApiOperation({ description: 'Get pending structre for validation' })
public async getAdminStructuresList(): Promise<any> {
const structuresList = { claimed: [], inClaim: [], toClaim: [], incomplete: [] };
structuresList.inClaim = await this.getPendingAttachments();
structuresList.toClaim = (await this.structuresService.findAllUnclaimed()).filter(
(demand) => !structuresList.inClaim.find((elem) => elem.structureId == demand.structureId)
);
const today = DateTime.local().setZone('utc', { keepLocalTime: true });
const inClaimStructures = await this.getPendingAttachments();
structuresList.inClaim = inClaimStructures.map((structure) => {
return {
structureId: structure.structureId,
structureName: structure.structureName,
updatedAt: structure.updatedAt,
isOutdated: Interval.fromDateTimes(DateTime.fromISO(structure.updatedAt), today).length('months') > 6,
};
});
const toClaimStructures = await this.structuresService.findAllUnclaimed();
structuresList.toClaim = toClaimStructures
.filter((demand) => !structuresList.inClaim.find((elem) => elem.structureId == demand.structureId))
.map((structure) => {
return {
structureId: structure.structureId,
structureName: structure.structureName,
updatedAt: structure.updatedAt,
isOutdated: Interval.fromDateTimes(DateTime.fromISO(structure.updatedAt), today).length('months') > 6,
};
});
const allStructures = await this.structuresService.findAll();
structuresList.claimed = allStructures
.filter(
......@@ -64,14 +84,25 @@ export class AdminController {
!structuresList.toClaim.find((elem) => elem.structureId == demand.id)
)
.map((structure) => {
return { structureId: structure.id, structureName: structure.structureName };
return {
structureId: structure.id,
structureName: structure.structureName,
updatedAt: structure.updatedAt,
isOutdated: Interval.fromDateTimes(DateTime.fromISO(structure.updatedAt), today).length('months') > 6,
};
});
structuresList.incomplete = await Promise.all(
allStructures.map(async (struct) => {
const validity = await validate(new Structure(struct));
if (validity.length > 0) {
this.logger.debug(`getAdminStructuresList - validation failed. errors: ${validity.toString()}`);
return { structureId: struct.id, structureName: struct.structureName };
return {
structureId: struct.id,
structureName: struct.structureName,
updatedAt: struct.updatedAt,
isOutdated: Interval.fromDateTimes(DateTime.fromISO(struct.updatedAt), today).length('months') > 6,
};
} else {
this.logger.debug('getAdminStructuresList - validation succeed');
return null;
......
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsMongoId, IsNotEmpty, IsString } from 'class-validator';
import { IsDate, IsEmail, IsMongoId, IsNotEmpty, IsString } from 'class-validator';
export class PendingStructureDto {
@IsNotEmpty()
......@@ -16,4 +16,9 @@ export class PendingStructureDto {
@IsString()
@ApiProperty({ type: String })
structureName: string;
@IsNotEmpty()
@IsDate()
@ApiProperty({ type: String })
updatedAt: string;
}
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { IsDate, IsNotEmpty, IsString } from 'class-validator';
export class UnclaimedStructureDto {
@IsNotEmpty()
......@@ -11,4 +11,9 @@ export class UnclaimedStructureDto {
@IsString()
@ApiProperty({ type: String })
structureName: string;
@IsNotEmpty()
@IsDate()
@ApiProperty({ type: String })
updatedAt: string;
}
......@@ -198,7 +198,11 @@ export class StructuresService {
await Promise.all(
structures.map(async (structure: StructureDocument) => {
if (!(await this.userService.isStructureClaimed(structure.id))) {
unclaimedStructures.push({ structureId: structure.id, structureName: structure.structureName });
unclaimedStructures.push({
structureId: structure.id,
structureName: structure.structureName,
updatedAt: structure.updatedAt,
});
}
})
);
......
......@@ -67,11 +67,13 @@ export class UsersServiceMock {
structureId: '6093ba0e2ab5775cfc01ed3e',
structureName: 'a',
userEmail: 'paula.dubois@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
},
{
structureId: '6903ba0e2ab5775cfc01ed4d',
structureName: "L'Atelier Numérique",
userEmail: 'jacques.dupont@mii.com',
updatedAt: '2021-03-02T10:07:48.000Z',
},
];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment