diff --git a/test/test.ts b/test/test.ts index 29b44ba..52f0d76 100644 --- a/test/test.ts +++ b/test/test.ts @@ -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(); diff --git a/ts/index.ts b/ts/index.ts index d66f3be..949e22e 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -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'; diff --git a/ts/ora.classes.milestone.ts b/ts/ora.classes.milestone.ts new file mode 100644 index 0000000..0d690b0 --- /dev/null +++ b/ts/ora.classes.milestone.ts @@ -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); + } +} diff --git a/ts/ora.classes.project.ts b/ts/ora.classes.project.ts index 1b8f363..58fcc12 100644 --- a/ts/ora.classes.project.ts +++ b/ts/ora.classes.project.ts @@ -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 { return OraList.getAllLists(this); } + + public async getMileStones(): Promise { + return OraMilestone.getAllMilestonesForProject(this); + } } diff --git a/ts/ora.classes.task.ts b/ts/ora.classes.task.ts index 2d9f007..a701064 100644 --- a/ts/ora.classes.task.ts +++ b/ts/ora.classes.task.ts @@ -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 { + return (await this.oraListRef.oraProjectObjectRef.getMileStones()).find(milestoneArg => milestoneArg.id === this.milestone_id); + } }