Skip to content

Commit

Permalink
Temp wip
Browse files Browse the repository at this point in the history
  • Loading branch information
manelcecs committed Nov 6, 2023
1 parent e86d58a commit 1a011a5
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "yarn lint-prettier && yarn lint-eslint"
},
"dependencies": {
"@unocha/hpc-api-core": "^6.0.0",
"@unocha/hpc-api-core": "https://github.com/UN-OCHA/hpc-api-core.git#7443efb9039a0eab7833ee9fa8393038e1c286a6",
"apollo-server-hapi": "^3.12.0",
"bunyan": "^1.8.15",
"class-validator": "^0.14.0",
Expand Down
56 changes: 54 additions & 2 deletions src/domain-services/flows/flow-search-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Service } from 'typedi';
import { FlowSearchResult, FlowSortField } from './graphql/types';
import {
FlowParkedParentSource,
FlowSearchResult,
FlowSortField,
} from './graphql/types';
import { Database } from '@unocha/hpc-api-core/src/db/type';
import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types';
import { OrganizationService } from '../organizations/organization-service';
Expand Down Expand Up @@ -131,6 +135,7 @@ export class FlowSearchService {
]);

const items = flows.map((flow) => {
const flowLink = flowLinksMap.get(flow.id) || [];
const categories = categoriesMap.get(flow.id) || [];
const organizations = organizationsMap.get(flow.id) || [];
const locations = locationsMap.get(flow.id) || [];
Expand All @@ -139,6 +144,11 @@ export class FlowSearchService {
const externalReferences = externalReferencesMap.get(flow.id) || [];
const reportDetails = reportDetailsMap.get(flow.id) || [];

const parkedParentSource: FlowParkedParentSource[] = [];
if (flow.activeStatus && flowLink.length > 0) {
this.getParketParents(flow, flowLink, models, parkedParentSource);
}

const childIDs: number[] = (flowLinksMap.get(flow.id) || []).map(
(flowLink) => flowLink.childID.valueOf()
) as number[];
Expand Down Expand Up @@ -167,7 +177,7 @@ export class FlowSearchService {
origCurrency: flow.origCurrency ? flow.origCurrency.toString() : '',
externalReferences,
reportDetails,
parkedParentSource: 'placeholder',
parkedParentSource,
// Paged item field
cursor: flow.id.valueOf(),
};
Expand Down Expand Up @@ -214,4 +224,46 @@ export class FlowSearchService {
}
});
}

private async getParketParents(
flow: any,
flowLink: any[],
models: Database,
parkedParentSource: FlowParkedParentSource[]

Check failure on line 232 in src/domain-services/flows/flow-search-service.ts

View workflow job for this annotation

GitHub Actions / Code Checks

'parkedParentSource' is defined but never used. Allowed unused args must match /^_/u
): Promise<any> {
const flowLinksDepth0 = flowLink.filter((flowLink) => flowLink.depth === 0);

const flowLinksParent = flowLinksDepth0.filter(
(flowLink) => flowLink.parentID === flow.id
);

const parentFlowIds = flowLinksParent.map((flowLink) =>

Check failure on line 240 in src/domain-services/flows/flow-search-service.ts

View workflow job for this annotation

GitHub Actions / Code Checks

'parentFlowIds' is assigned a value but never used. Allowed unused vars must match /^_/u
flowLink.parentID.valueOf()
);

const categories = await models.category.find({
where: {
group: 'flowType',
name: 'parked',
},
});

const categoriesIDs = categories.map((category) => category.id);

const categoryRef = await models.categoryRef.find({
where: {
categoryID: {
[Op.IN]: categoriesIDs,
},
versionID: flow.versionID,
},
});

const parentFlows = flowLinksParent.filter((flowLink) => {

Check failure on line 262 in src/domain-services/flows/flow-search-service.ts

View workflow job for this annotation

GitHub Actions / Code Checks

'parentFlows' is assigned a value but never used. Allowed unused vars must match /^_/u
return categoryRef.some(
(categoryRef) =>
categoryRef.objectID.valueOf() === flowLink.parentID.valueOf()
);
});
}
}
31 changes: 18 additions & 13 deletions src/domain-services/flows/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export class FlowOrganization {
@Field({ nullable: false })
id: number;

@Field({ nullable: false })
@Field({ nullable: true })
refDirection: string;

@Field({ nullable: false })
@Field({ nullable: true })
name: string;
}

Expand Down Expand Up @@ -123,13 +123,13 @@ export class FlowReportDetail {
@Field({ nullable: false })
id: number;

@Field({ nullable: false })
@Field({ nullable: true })
flowID: number;

@Field({ nullable: false })
versionID: number;

@Field({ nullable: false })
@Field({ nullable: true })
contactInfo: string;

@Field({ nullable: false })
Expand All @@ -138,10 +138,10 @@ export class FlowReportDetail {
@Field({ nullable: false })
date: string;

@Field({ nullable: false })
@Field({ nullable: true })
sourceID: string;

@Field({ nullable: false })
@Field({ nullable: true })
refCode: string;

@Field({ nullable: false })
Expand All @@ -153,13 +153,21 @@ export class FlowReportDetail {
@Field({ nullable: false })
updatedAt: string;

@Field({ nullable: false })
@Field({ nullable: true })
organizationID: number;
}

@ObjectType()
export class FlowParkedParentSource {
@Field(() => [Number], { nullable: false })
organization: number[];

@Field(() => [String], { nullable: false })
orgName: string[];
}

@ObjectType()
export default class Flow extends ItemPaged {
// Mandatory fields
@Field({ nullable: false })
id: number;

Expand All @@ -178,7 +186,6 @@ export default class Flow extends ItemPaged {
@Field({ nullable: false })
restricted: boolean;

// Optional fields
@Field(() => [FlowCategory], { nullable: true })
categories: FlowCategory[];

Expand Down Expand Up @@ -212,9 +219,8 @@ export default class Flow extends ItemPaged {
@Field(() => [FlowReportDetail], { nullable: true })
reportDetails: FlowReportDetail[];

// Missing fields & new Types
@Field({ nullable: true })
parkedParentSource: string;
@Field(() => [FlowParkedParentSource], { nullable: true })
parkedParentSource: FlowParkedParentSource[];
}

@ObjectType()
Expand All @@ -230,7 +236,6 @@ export type FlowSortField =
| 'updatedAt'
| 'activeStatus'
| 'restricted'
//
| 'newMoney'
| 'flowDate'
| 'decisionDate'
Expand Down
82 changes: 66 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,9 @@
"@types/istanbul-lib-report" "*"

"@types/jest@^29.5.5":
version "29.5.5"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.5.tgz#727204e06228fe24373df9bae76b90f3e8236a2a"
integrity sha512-ebylz2hnsWR9mYvmBFbXJXr+33UPc4+ZdxyDXh5w0FlPBTfCVN3wPL+kuOiQt3xvrK419v7XWeAs+AeOksafXg==
version "29.5.7"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.7.tgz#2c0dafe2715dd958a455bc10e2ec3e1ec47b5036"
integrity sha512-HLyetab6KVPSiF+7pFcUyMeLsx25LDNDemw9mGsJBkai/oouwrjTycocSDYopMEwFhN2Y4s9oPyOCZNofgSt2g==
dependencies:
expect "^29.0.0"
pretty-format "^29.0.0"
Expand All @@ -1428,6 +1428,13 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==

"@types/knex@^0.16.1":
version "0.16.1"
resolved "https://registry.yarnpkg.com/@types/knex/-/knex-0.16.1.tgz#619678407265c675463c563ed38323461a49515d"
integrity sha512-54gWD1HWwdVx5iLHaJ1qxH3I6KyBsj5fFqzRpXFn7REWiEB2jwspeVCombNsocSrqPd7IRPqKrsIME7/cD+TFQ==
dependencies:
knex "*"

"@types/lodash@^4.14.194":
version "4.14.194"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
Expand Down Expand Up @@ -1611,11 +1618,11 @@
"@typescript-eslint/types" "5.61.0"
eslint-visitor-keys "^3.3.0"

"@unocha/hpc-api-core@^6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@unocha/hpc-api-core/-/hpc-api-core-6.0.0.tgz#2abf57f103255966de808eb31637543c985ad41c"
integrity sha512-n7CqIdsgWeTu4chX7NTU3SnZxFglZ0HG6awXu7lBCqz+KuVaGb9Er3DjKyKgRNa1qgt3GWNTAzACOehNd5vNNw==
"@unocha/hpc-api-core@https://github.com/UN-OCHA/hpc-api-core.git#7443efb9039a0eab7833ee9fa8393038e1c286a6":
version "6.2.0"
resolved "https://github.com/UN-OCHA/hpc-api-core.git#7443efb9039a0eab7833ee9fa8393038e1c286a6"
dependencies:
"@types/knex" "^0.16.1"
"@types/lodash" "^4.14.194"
"@types/node-fetch" "2.6.3"
fp-ts "^2.14.0"
Expand All @@ -1624,6 +1631,7 @@
lodash "^4.17.21"
node-fetch "2.6.9"
pg "^8.10.0"
ts-node "^10.9.1"

"@unocha/hpc-repo-tools@^3.0.1":
version "3.0.1"
Expand Down Expand Up @@ -2347,7 +2355,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.1.0.tgz#1f943e5a357fac10b4e0f5aaef3b14cdc1af6ec7"
integrity sha512-6S062WDQUXi6hOfkO/sBPVwE5ASXY4G2+b4atvhJfSsuUUhIaUKlkjLe9692Ipyt5/a+IPF5aVTu3V5gvXq5cg==

colorette@^2.0.19:
colorette@2.0.19, colorette@^2.0.19:
version "2.0.19"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798"
integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==
Expand Down Expand Up @@ -2488,6 +2496,13 @@ [email protected]:
dependencies:
ms "^2.1.1"

[email protected], debug@^4.1.0, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

debug@^2.2.0, debug@^2.3.3:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
Expand All @@ -2502,13 +2517,6 @@ debug@^3.2.6:
dependencies:
ms "^2.1.1"

debug@^4.1.0, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

debug@^4.1.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
Expand Down Expand Up @@ -3194,6 +3202,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.2.5.tgz#67a0fe471cacb9c687d817cab6450b96dde8313b"
integrity sha512-9jb7AW5p3in+IiJWhQiZmmwkpLaR/ccTWdWQCtZM66HJcHHLegowh4q4tSD7gouUyeNvFWRavfK9GXosQHDpFA==

[email protected]:
version "2.3.0"
resolved "https://registry.yarnpkg.com/getopts/-/getopts-2.3.0.tgz#71e5593284807e03e2427449d4f6712a268666f4"
integrity sha512-5eDf9fuSXwxBL6q5HX+dhDj+dslFGWzU5thZ9kNKUkcPtaPdatmUFKwHFrLb/uf/WpA4BHET+AX3Scl56cAjpA==

git-node-fs@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/git-node-fs/-/git-node-fs-1.0.0.tgz#49b215e242ebe43aa4c7561bbba499521752080f"
Expand Down Expand Up @@ -3509,7 +3522,7 @@ ini@^1.3.4, ini@^1.3.5:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

interpret@^2.0.0:
interpret@^2.0.0, interpret@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9"
integrity sha512-Ju0Bz/cEia55xDwUWEa8+olFpCiQoypjnQySseKtmjNrnps3P+xfpUmGr90T7yjlVJmOtybRvPXhKMbHr+fWnw==
Expand Down Expand Up @@ -4258,6 +4271,26 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==

knex@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/knex/-/knex-3.0.1.tgz#b12f3173c30d8c7b6d69dc257cc9c84db00ad60e"
integrity sha512-ruASxC6xPyDklRdrcDy6a9iqK+R9cGK214aiQa+D9gX2ZnHZKv6o6JC9ZfgxILxVAul4bZ13c3tgOAHSuQ7/9g==
dependencies:
colorette "2.0.19"
commander "^10.0.0"
debug "4.3.4"
escalade "^3.1.1"
esm "^3.2.25"
get-package-type "^0.1.0"
getopts "2.3.0"
interpret "^2.2.0"
lodash "^4.17.21"
pg-connection-string "2.6.1"
rechoir "^0.8.0"
resolve-from "^5.0.0"
tarn "^3.0.2"
tildify "2.0.0"

[email protected]:
version "0.21.1"
resolved "https://registry.yarnpkg.com/knex/-/knex-0.21.1.tgz#4fba7e6c58c9f459846c3090be157a732fc75e41"
Expand Down Expand Up @@ -4983,6 +5016,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.2.0.tgz#caab4d38a9de4fdc29c9317acceed752897de41c"
integrity sha512-xB/+wxcpFipUZOQcSzcgkjcNOosGhEoPSjz06jC89lv1dj7mc9bZv6wLVy8M2fVjP0a/xN0N988YDq1L0FhK3A==

[email protected]:
version "2.6.1"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.6.1.tgz#78c23c21a35dd116f48e12e23c0965e8d9e2cbfb"
integrity sha512-w6ZzNu6oMmIzEAYVw+RLK0+nqHPt8K3ZnknKi+g48Ak2pr3dtljJW3o+D/n2zzCG07Zoe9VOX3aiKpj+BN0pjg==

pg-connection-string@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.5.0.tgz#538cadd0f7e603fc09a12590f3b8a452c2c0cf34"
Expand Down Expand Up @@ -5367,6 +5405,13 @@ rechoir@^0.6.2:
dependencies:
resolve "^1.1.6"

rechoir@^0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.8.0.tgz#49f866e0d32146142da3ad8f0eff352b3215ff22"
integrity sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==
dependencies:
resolve "^1.20.0"

reflect-metadata@^0.1.13:
version "0.1.13"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
Expand Down Expand Up @@ -5942,6 +5987,11 @@ tarn@^3.0.0:
resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.1.tgz#ebac2c6dbc6977d34d4526e0a7814200386a8aec"
integrity sha512-6usSlV9KyHsspvwu2duKH+FMUhqJnAh6J5J/4MITl8s94iSUQTLkJggdiewKv4RyARQccnigV48Z+khiuVZDJw==

tarn@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/tarn/-/tarn-3.0.2.tgz#73b6140fbb881b71559c4f8bfde3d9a4b3d27693"
integrity sha512-51LAVKUSZSVfI05vjPESNc5vwqqZpbXCsU+/+wxlOrUjk2SnFTt97v9ZgQrD4YmxYW1Px6w2KjaDitCfkvgxMQ==

test-exclude@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e"
Expand Down

0 comments on commit 1a011a5

Please sign in to comment.