fix(core): update

This commit is contained in:
Philipp Kunz 2020-06-22 13:40:05 +00:00
parent 15889699b4
commit ea16521ca3
5 changed files with 80 additions and 0 deletions

View File

@ -65,4 +65,26 @@ tap.test('should get all tasks for a project', async () => {
tasks.forEach(taskArg => console.log(taskArg.title));
});
tap.test('should get a milestone', async () => {
const organizations = await oraInstance.getOrganizations();
const losslessOrganization = organizations.find(orgArg => {
return orgArg.name.startsWith('Lossless');
});
const projectsInLosslessOrg = await losslessOrganization.getProjects();
const featureProjects = projectsInLosslessOrg.filter(oraProjectArg => {
return oraProjectArg.title.includes('Feature');
});
const layerIoProject = featureProjects.find(oraProjectArg =>
oraProjectArg.title.includes('layer.io')
);
const lists = await layerIoProject.getLists();
let tasks: ora.OraTask[] = [];
for (const list of lists) {
tasks = tasks.concat(await list.getTasks());
}
console.log('the following tasks are available:');
const milestone = await tasks[0].getMilestone();
expect(milestone).to.be.instanceOf(ora.OraMilestone);
});
tap.start();

View File

@ -3,3 +3,4 @@ export * from './ora.classes.organization';
export * from './ora.classes.project';
export * from './ora.classes.list';
export * from './ora.classes.task';
export * from './ora.classes.milestone';

View File

@ -0,0 +1,47 @@
import * as plugins from './ora.plugins';
import { OraProject } from './ora.classes.project';
export interface IOraMilestone {
id: number;
title: string;
created_at: string;
updated_at: string;
archived: boolean;
complete: boolean;
deadline: string;
color: string;
position: number;
}
export class OraMilestone implements IOraMilestone {
// ======
// STATIC
// ======
public static async getAllMilestonesForProject(oraProjectArg: OraProject) {
const response = await oraProjectArg.oraOrganizationRef.oraRef.request(`/projects/${oraProjectArg.id}/milestones`, 'GET');
const milestones: OraMilestone[] = [];
for (const dataObject of response.data) {
milestones.push(new OraMilestone(oraProjectArg, dataObject));
}
return milestones;
}
// ========
// INSTANCE
// ========
public id: number;
public title: string;
public created_at: string;
public updated_at: string;
public archived: boolean;
public complete: boolean;
public deadline: string;
public color: string;
public position: number;
public oraProjectRef: OraProject;
constructor(oraProjectRef: OraProject, creationObjectArg: IOraMilestone) {
this.oraProjectRef = oraProjectRef;
Object.assign(this, creationObjectArg);
}
}

View File

@ -2,6 +2,7 @@ import * as plugins from './ora.plugins';
import { Ora } from './ora.classes.ora';
import { OraOrganization } from './ora.classes.organization';
import { OraList } from './ora.classes.list';
import { OraMilestone } from './ora.classes.milestone';
export interface IOraProject {
archived: boolean;
@ -81,4 +82,8 @@ export class OraProject implements IOraProject {
public async getLists(): Promise<OraList[]> {
return OraList.getAllLists(this);
}
public async getMileStones(): Promise<OraMilestone[]> {
return OraMilestone.getAllMilestonesForProject(this);
}
}

View File

@ -1,5 +1,6 @@
import * as plugins from './ora.plugins';
import { OraList } from './ora.classes.list';
import { OraMilestone } from './ora.classes.milestone';
export interface IOraTask {
milestone_id: number;
@ -92,4 +93,8 @@ export class OraTask implements IOraTask {
this.oraListRef = oraListRefArg;
Object.assign(this, creationObjectArg);
}
public async getMilestone (): Promise<OraMilestone> {
return (await this.oraListRef.oraProjectObjectRef.getMileStones()).find(milestoneArg => milestoneArg.id === this.milestone_id);
}
}