mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Merge pull request #1145 from Unleash/feat/update-health-report
feat: update health report
This commit is contained in:
commit
7ec9672a5c
@ -11,7 +11,14 @@ import {
|
||||
} from '../types/stores/project-store';
|
||||
import { DEFAULT_ENV } from '../util/constants';
|
||||
|
||||
const COLUMNS = ['id', 'name', 'description', 'created_at', 'health'];
|
||||
const COLUMNS = [
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'created_at',
|
||||
'health',
|
||||
'updated_at',
|
||||
];
|
||||
const TABLE = 'projects';
|
||||
|
||||
class ProjectStore implements IProjectStore {
|
||||
@ -74,7 +81,7 @@ class ProjectStore implements IProjectStore {
|
||||
async updateHealth(healthUpdate: IProjectHealthUpdate): Promise<void> {
|
||||
await this.db(TABLE)
|
||||
.where({ id: healthUpdate.id })
|
||||
.update({ health: healthUpdate.health });
|
||||
.update({ health: healthUpdate.health, updated_at: new Date() });
|
||||
}
|
||||
|
||||
async create(project: IProjectInsert): Promise<IProject> {
|
||||
@ -197,6 +204,7 @@ class ProjectStore implements IProjectStore {
|
||||
description: row.description,
|
||||
createdAt: row.created_at,
|
||||
health: row.health || 100,
|
||||
updatedAt: row.updated_at || new Date(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ export default class ProjectHealthService {
|
||||
name: project.name,
|
||||
description: project.description,
|
||||
health: project.health,
|
||||
updatedAt: project.updatedAt,
|
||||
environments,
|
||||
features,
|
||||
members,
|
||||
|
@ -143,6 +143,7 @@ export interface IProjectOverview {
|
||||
members: number;
|
||||
version: number;
|
||||
health: number;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
export interface IProjectHealthReport extends IProjectOverview {
|
||||
@ -309,6 +310,7 @@ export interface IProject {
|
||||
description: string;
|
||||
health?: number;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
export interface IProjectWithCount extends IProject {
|
||||
|
@ -5,6 +5,7 @@ export interface IProjectInsert {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
export interface IProjectArchived {
|
||||
|
12
src/migrations/20211130142314-add-updated-at-to-projects.js
Normal file
12
src/migrations/20211130142314-add-updated-at-to-projects.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
exports.up = function (db, callback) {
|
||||
db.runSql(
|
||||
'ALTER TABLE projects ADD COLUMN "updated_at" TIMESTAMP WITH TIME ZONE DEFAULT now();',
|
||||
callback,
|
||||
);
|
||||
};
|
||||
|
||||
exports.down = function (db, callback) {
|
||||
db.runSql('ALTER TABLE projects DROP COLUMN "updated_at";', callback);
|
||||
};
|
@ -302,3 +302,16 @@ test('Sorts environments correctly if sort order is equal', async () => {
|
||||
expect(feature.environments[1].name).toBe(envTwo);
|
||||
});
|
||||
});
|
||||
|
||||
test('Update update_at when setHealth runs', async () => {
|
||||
await app.services.projectHealthService.setHealthRating();
|
||||
await app.request
|
||||
.get('/api/admin/projects/default/health-report')
|
||||
.expect(200)
|
||||
.expect('Content-Type', /json/)
|
||||
.expect((res) => {
|
||||
let now = new Date().getTime();
|
||||
let updatedAt = new Date(res.body.updatedAt).getTime();
|
||||
expect(now - updatedAt).toBeLessThan(5000);
|
||||
});
|
||||
});
|
||||
|
@ -39,6 +39,7 @@ test('should create new project', async () => {
|
||||
expect(project.name).toEqual(ret.name);
|
||||
expect(project.description).toEqual(ret.description);
|
||||
expect(ret.createdAt).toBeTruthy();
|
||||
expect(ret.updatedAt).toBeTruthy();
|
||||
expect(exists).toBe(true);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user