Skip to content

Commit

Permalink
feat(projects): added ecosystem support for projects
Browse files Browse the repository at this point in the history
CLOSES JOB-542
  • Loading branch information
AndySakov committed Mar 7, 2024
1 parent 9ff7c48 commit 7d6b925
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 84 deletions.
1 change: 1 addition & 0 deletions src/audits/audits.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe("AuditsService", () => {

const projectDetails = await projectsService.getProjectDetailsById(
project.id,
undefined,
);
expect(projectDetails.audits).toEqual(
expect.arrayContaining<Audit>([
Expand Down
1 change: 1 addition & 0 deletions src/hacks/hacks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe("HacksService", () => {

const projectDetails = await projectsService.getProjectDetailsById(
project.id,
undefined,
);
expect(projectDetails.hacks).toEqual(
expect.arrayContaining<Hack>([
Expand Down
25 changes: 16 additions & 9 deletions src/projects/projects.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe("ProjectsController", () => {
page: 1,
limit: Number(Integer.MAX_VALUE),
};
const res = await controller.getProjectsListWithSearch(params);
const res = await controller.getProjectsListWithSearch(params, undefined);

const uuids = res.data.map(project => project.id + project.orgId);
const setOfUuids = new Set([...uuids]);
Expand All @@ -313,7 +313,7 @@ describe("ProjectsController", () => {
it(
"should get correctly formatted filter configs",
async () => {
const configs = await controller.getFilterConfigs();
const configs = await controller.getFilterConfigs(undefined);

expect(configs).toBeDefined();

Expand Down Expand Up @@ -342,14 +342,16 @@ describe("ProjectsController", () => {
limit: 1,
};

const project = (await controller.getProjectsListWithSearch(params))
.data[0];
const project = (
await controller.getProjectsListWithSearch(params, undefined)
).data[0];

const res: Partial<Response> = {};

const details = await controller.getProjectDetailsById(
project.id,
res as Response,
undefined,
);

expect(projectHasArrayPropsDuplication(details)).toBe(false);
Expand Down Expand Up @@ -382,10 +384,14 @@ describe("ProjectsController", () => {
limit: 1,
};

const project = (await controller.getProjectsListWithSearch(params))
.data[0];
const project = (
await controller.getProjectsListWithSearch(params, undefined)
).data[0];

const competitors = await controller.getProjectCompetitors(project.id);
const competitors = await controller.getProjectCompetitors(
project.id,
undefined,
);

expect(competitors).toEqual({
success: true,
Expand Down Expand Up @@ -445,8 +451,9 @@ describe("ProjectsController", () => {
limit: 1,
};

const project = (await controller.getProjectsListWithSearch(params))
.data[0];
const project = (
await controller.getProjectsListWithSearch(params, undefined)
).data[0];

const res: Partial<Response> = {};

Expand Down
31 changes: 23 additions & 8 deletions src/projects/projects.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Delete,
Get,
Header,
Headers,
HttpStatus,
Param,
ParseFilePipeBuilder,
Expand Down Expand Up @@ -34,14 +35,14 @@ import { Response as ExpressResponse } from "express";
import { File, NFTStorage } from "nft.storage";
import { RBACGuard } from "src/auth/rbac.guard";
import { OrganizationsService } from "src/organizations/organizations.service";
import { CheckWalletRoles } from "src/shared/constants";
import { CheckWalletRoles, ECOSYSTEM_HEADER } from "src/shared/constants";
import {
CACHE_CONTROL_HEADER,
CACHE_DURATION,
CACHE_EXPIRY,
} from "src/shared/constants/cache-control";
import { Roles } from "src/shared/decorators";
import { responseSchemaWrapper } from "src/shared/helpers";
import { normalizeString, responseSchemaWrapper } from "src/shared/helpers";
import { ProjectProps } from "src/shared/models";
import {
DefiLlamaProject,
Expand Down Expand Up @@ -167,9 +168,16 @@ export class ProjectsController {
async getProjectsListWithSearch(
@Query(new ValidationPipe({ transform: true }))
params: ProjectListParams,
@Headers(ECOSYSTEM_HEADER) ecosystem: string | undefined,
): Promise<PaginatedData<ProjectListResult>> {
this.logger.log(`/projects/list ${JSON.stringify(params)}`);
return this.projectsService.getProjectsListWithSearch(params);
const enrichedParams = {
...params,
communities: ecosystem
? [...(params.communities ?? []), normalizeString(ecosystem)]
: params.communities,
};
this.logger.log(`/projects/list ${JSON.stringify(enrichedParams)}`);
return this.projectsService.getProjectsListWithSearch(enrichedParams);
}

@Get("/filters")
Expand All @@ -190,9 +198,11 @@ export class ProjectsController {
"Returns an error message with a list of values that failed validation",
type: ValidationError,
})
async getFilterConfigs(): Promise<ProjectFilterConfigs> {
async getFilterConfigs(
@Headers(ECOSYSTEM_HEADER) ecosystem: string | undefined,
): Promise<ProjectFilterConfigs> {
this.logger.log(`/projects/filters`);
return this.projectsService.getFilterConfigs();
return this.projectsService.getFilterConfigs(ecosystem);
}

@Get("details/:id")
Expand All @@ -219,9 +229,13 @@ export class ProjectsController {
async getProjectDetailsById(
@Param("id") id: string,
@Res({ passthrough: true }) res: ExpressResponse,
@Headers(ECOSYSTEM_HEADER) ecosystem: string | undefined,
): Promise<ProjectDetails | undefined> {
this.logger.log(`/projects/details/${id}`);
const result = await this.projectsService.getProjectDetailsById(id);
const result = await this.projectsService.getProjectDetailsById(
id,
ecosystem,
);
if (result === undefined) {
res.status(HttpStatus.NOT_FOUND);
}
Expand Down Expand Up @@ -274,10 +288,11 @@ export class ProjectsController {
})
async getProjectCompetitors(
@Param("id") id: string,
@Headers(ECOSYSTEM_HEADER) ecosystem: string | undefined,
): Promise<Response<ProjectProps[]> | ResponseWithNoData> {
this.logger.log(`/projects/competitors/${id}`);
return this.projectsService
.getProjectCompetitors(id)
.getProjectCompetitors(id, ecosystem)
.then(res => ({
success: true,
message: "Retrieved all competing projects successfully",
Expand Down
Loading

0 comments on commit 7d6b925

Please sign in to comment.