Skip to content

Instantly share code, notes, and snippets.

@adadgio
Created July 12, 2021 07:23
Show Gist options
  • Save adadgio/c60bb3d98ca7f866110c6ddba14fd503 to your computer and use it in GitHub Desktop.
Save adadgio/c60bb3d98ca7f866110c6ddba14fd503 to your computer and use it in GitHub Desktop.
//ProjectListFilter
interface Range {
from: number;
to: number;
}
type UiFilterObject = {
id: string
label: string
name: string // value
}
export class ProjectListFilter {
limit?: number = 25;
skip?: number = 0;
orderBy?: string = "id";
order?: string = "DESC";
keyAccount?: string;
term?: string = null;
projectStatus?: Array<string> = [];
targetStatus?: Array<string> = [];
status?: Array<string> = ['active'];
type?: Array<string> = [];
professions?: Array<string> = [];
specialties?: Array<string> = [];
actionCodes?: Array<string> = [];
startDate?: Range = null;
endDate?: Range = null;
checkDate?: Range = null;
populationSample?: Array<string> = [];
populationSize: Range = null;
revenue: number = 0.00
name: string;
clientName: string;
constructor(data?: any) {
if (data) {
this.limit = data.limit || 25
this.skip = data.skip || 0
this.orderBy = data.orderBy || "id"
this.order = data.order || "DESC"
this.keyAccount = data.keyAccount || []
this.term = data.term || null
this.projectStatus = data.projectStatus || []
this.targetStatus = data.targetStatus || []
this.status = data.status || []
this.type = data.type || []
this.professions = data.professions || []
this.specialties = data.specialties || []
this.actionCodes = data.actionCodes || []
this.startDate = data.startDate || null
this.checkDate = data.checkDate || null
this.endDate = data.endDate || null
this.populationSample = data.populationSample || []
this.populationSize = data.populationSize || null
this.revenue = data.revenue || 0.00
}
}
fromUiListFilters(uiFilters: Array<UiFilterObject>) {
this.keyAccount = uiFilters['keyAccount'].map(({ id }) => id) || this.keyAccount
this.projectStatus = uiFilters['projectStatus'].map(({ name }) => name) || this.projectStatus
this.targetStatus = uiFilters['targetStatus'].map(({ name }) => name) || this.targetStatus
this.status = uiFilters['status'].map(({ name }) => name) || this.status
this.type = uiFilters['type'].map(({ id }) => id) || this.type
this.professions = uiFilters['professions'].map(({ id }) => id) || this.professions
this.specialties = uiFilters['specialties'].map(({ id }) => id) || this.specialties
this.actionCodes = uiFilters['actionCodes'].map(({ name }) => name) || this.actionCodes
this.startDate = uiFilters['startDate'].name || this.startDate
this.checkDate = uiFilters['checkDate'].name || this.checkDate
this.endDate = uiFilters['endDate'].name || this.endDate
this.populationSample = uiFilters['populationSample'].map(({ id }) => id) || this.populationSample
this.populationSize = uiFilters['populationSize'].populationSize || this.populationSize
this.revenue = uiFilters['revenue'].revenue || this.revenue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment