Skip to content

Commit

Permalink
Merge pull request #121 from polarsquad/allow-filtering-when-retrievi…
Browse files Browse the repository at this point in the history
…ng-projects

Allow filtering of projects in getAllProjects
  • Loading branch information
joonvena committed Nov 17, 2023
2 parents d013e7b + 25c0375 commit 870bf5f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polarsquad/cinode-api",
"version": "0.12.5",
"version": "0.12.6",
"description": "Cinode API for the Cinode platform",
"homepage": "https://github.com/polarsquad/cinode-api#readme",
"bugs": {
Expand Down
3 changes: 2 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ProjectBase,
ProjectPipeline,
ProjectState,
SearchProjectQuery,
SearchResult,
SearchSkillResult,
TeamBase,
Expand Down Expand Up @@ -66,7 +67,7 @@ export class Api {
.json<CompanyCustomer>();
}

async listAllProjects(query = {}) {
async listAllProjects(query: SearchProjectQuery = {}) {
const {
pagedAndSortedBy: { itemsPerPage },
totalItems,
Expand Down
5 changes: 3 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
ProjectBase,
ProjectState,
ProjectTeam,
SearchProjectQuery,
UserFilter,
WithProfile,
} from './types.js';
Expand Down Expand Up @@ -69,8 +70,8 @@ export class CinodeService {
this.backofficeTeams = backofficeTeams;
}

async getAllProjects() {
const projects = await this.api.listAllProjects();
async getAllProjects(query: SearchProjectQuery = {}) {
const projects = await this.api.listAllProjects(query);
return Promise.all(
projects.flatMap((p) => (p?.id ? [this.getProject(p.id)] : []))
);
Expand Down
36 changes: 36 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ export enum ProjectState {
Suspended = 60,
}

export enum SortByProject {
CreatedDateTime = 0,
Title = 1,
Identifier = 2,
CustomerIdentifier = 3,
SeoId = 4,
UpdatedDateTime = 5,
LastTouchDateTime = 6,
}

export enum SortOrder {
Ascending = 0,
Descending = 1,
}

export enum Status {
Inactive = 0,
Active = 1,
Expand Down Expand Up @@ -1267,6 +1282,27 @@ export interface Role {
level?: AccessLevel | null;
}

interface PageAndSortByProject {
sortBy?: SortByProject;
sortOrder?: SortOrder;
page?: number;
itemsPerPage?: number;
}

export interface SearchProjectQuery {
title?: string;
identification?: string;
customerIdentifier?: string;
corporateIdentityNumber?: string;
customerId?: number;
pageAndSortBy?: PageAndSortByProject;
pipelines?: number[];
salesManagers?: number[];
customers?: number[];
intermediators?: number[];
projectStates?: ProjectState[];
}

export interface SearchSkill {
keywordId?: number | null;
min?: number | null;
Expand Down

0 comments on commit 870bf5f

Please sign in to comment.