Skip to content

Commit

Permalink
Merge branch 'main' into 458-feat-add-infitie-scroll-to-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Fjortis authored Sep 23, 2024
2 parents d56b0b1 + 8760d76 commit 332d300
Show file tree
Hide file tree
Showing 52 changed files with 717 additions and 58 deletions.
8 changes: 4 additions & 4 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
".": "1.50.0",
"apps/backend": "1.31.0",
"apps/frontend": "1.46.0",
"packages/shared": "1.29.0",
".": "1.51.0",
"apps/backend": "1.32.0",
"apps/frontend": "1.47.0",
"packages/shared": "1.30.0",
"scripts/analytics": "1.7.0"
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.51.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/v1.50.0...v1.51.0) (2024-09-23)


### Features

* Add an ability to split contributors gf-462 ([#477](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/477)) ([adbf2af](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/adbf2afd81ac81518c50b158ab11cd89768e7c8a))

## [1.50.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/v1.49.0...v1.50.0) (2024-09-23)


Expand Down
7 changes: 7 additions & 0 deletions apps/backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.32.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/backend-v1.31.0...backend-v1.32.0) (2024-09-23)


### Features

* Add an ability to split contributors gf-462 ([#477](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/477)) ([adbf2af](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/adbf2afd81ac81518c50b158ab11cd89768e7c8a))

## [1.31.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/backend-v1.30.1...backend-v1.31.0) (2024-09-23)


Expand Down
2 changes: 1 addition & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@git-fit/backend",
"type": "module",
"version": "1.31.0",
"version": "1.32.0",
"engines": {
"node": "20.x.x",
"npm": "10.x.x"
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/libs/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { PAGE_INDEX_OFFSET } from "./page-index-offset.constant.js";
export { EMPTY_LENGTH } from "@git-fit/shared";
export { EMPTY_LENGTH, MIN_GIT_EMAILS_LENGTH_FOR_SPLIT } from "@git-fit/shared";
73 changes: 73 additions & 0 deletions apps/backend/src/modules/contributors/contributor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import { ContributorsApiPath } from "./libs/enums/enums.js";
import {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorSplitRequestDto,
} from "./libs/types/types.js";
import {
contributorMergeValidationSchema,
contributorPatchValidationSchema,
contributorSplitValidationSchema,
} from "./libs/validation-schemas/validation-schemas.js";

/**
Expand Down Expand Up @@ -109,6 +111,22 @@ class ContributorController extends BaseController {
body: contributorPatchValidationSchema,
},
});

this.addRoute({
handler: (options) =>
this.split(
options as APIHandlerOptions<{
body: ContributorSplitRequestDto;
params: { id: string };
}>,
),
method: "PATCH",
path: ContributorsApiPath.SPLIT_$ID,
preHandlers: [checkUserPermissions([PermissionKey.MANAGE_ALL_PROJECTS])],
validation: {
body: contributorSplitValidationSchema,
},
});
}

/**
Expand Down Expand Up @@ -267,6 +285,61 @@ class ContributorController extends BaseController {
status: HTTPCode.OK,
};
}

/**
* @swagger
* /contributors/split/{contributorId}:
* patch:
* description: Split contributors
* parameters:
* - name: contributorId
* in: path
* description: Id of the current contributor
* required: true
* schema:
* type: number
* minimum: 1
* requestBody:
* description: Payload for splitting contributors
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* gitEmailId:
* type: number
* newContributorName:
* type: number
* responses:
* 200:
* description: Successful operation
* content:
* application/json:
* schema:
* type: object
* properties:
* items:
* type: object
* $ref: "#/components/schemas/Contributor"
* 404:
* description: Contributor not found
* 409:
* description: Attempt to split single email or merging failed
*/
private async split(
options: APIHandlerOptions<{
body: ContributorSplitRequestDto;
params: { id: string };
}>,
): Promise<APIHandlerResponse> {
const contributorId = Number(options.params.id);

return {
payload: await this.contributorService.split(contributorId, options.body),
status: HTTPCode.OK,
};
}
}

export { ContributorController };
40 changes: 40 additions & 0 deletions apps/backend/src/modules/contributors/contributor.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,46 @@ class ContributorRepository implements Repository {
return ContributorEntity.initialize(contributor);
}

public async split(
gitEmailId: number,
newContributorName: string,
): Promise<ContributorEntity> {
const result = await this.contributorModel.transaction(async (trx) => {
const newContributor = await this.contributorModel
.query(trx)
.insert({ name: newContributorName })
.execute();

await this.gitEmailModel
.query(trx)
.patchAndFetchById(gitEmailId, { contributorId: newContributor.id });

return await this.contributorModel
.query(trx)
.select("contributors.*")
.select(
raw(
"COALESCE(ARRAY_AGG(DISTINCT jsonb_build_object('id', projects.id, 'name', projects.name)) FILTER (WHERE projects.id IS NOT NULL), '{}') AS projects",
),
)
.leftJoin("git_emails", "contributors.id", "git_emails.contributor_id")
.leftJoin(
"activity_logs",
"git_emails.id",
"activity_logs.git_email_id",
)
.leftJoin("projects", "activity_logs.project_id", "projects.id")
.groupBy("contributors.id")
.withGraphFetched("gitEmails")
.modifyGraph("gitEmails", (builder) => {
builder.select("id", "email");
})
.findById(newContributor.id);
});

return ContributorEntity.initialize(result as ContributorModel);
}

public update(): ReturnType<Repository["update"]> {
return Promise.resolve(null);
}
Expand Down
59 changes: 58 additions & 1 deletion apps/backend/src/modules/contributors/contributor.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { PAGE_INDEX_OFFSET } from "~/libs/constants/constants.js";
import {
MIN_GIT_EMAILS_LENGTH_FOR_SPLIT,
PAGE_INDEX_OFFSET,
} from "~/libs/constants/constants.js";
import { ExceptionMessage } from "~/libs/enums/enums.js";
import { HTTPCode } from "~/libs/modules/http/http.js";
import {
Expand All @@ -16,6 +19,7 @@ import {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorPatchResponseDto,
type ContributorSplitRequestDto,
} from "./libs/types/types.js";

class ContributorService implements Service {
Expand Down Expand Up @@ -195,6 +199,59 @@ class ContributorService implements Service {
return item.toObject();
}

public async split(
contributorId: number,
payload: ContributorSplitRequestDto,
): Promise<ContributorGetAllItemResponseDto | null> {
const currentContributorEntity =
await this.contributorRepository.find(contributorId);
const hasContributor = currentContributorEntity !== null;

if (!hasContributor) {
throw new ContributorError({
message: ExceptionMessage.CONTRIBUTOR_NOT_FOUND,
status: HTTPCode.NOT_FOUND,
});
}

const currentContributor = currentContributorEntity.toObject();

if (
currentContributor.gitEmails.length <= MIN_GIT_EMAILS_LENGTH_FOR_SPLIT
) {
throw new ContributorError({
message: ExceptionMessage.CONTRIBUTOR_SPLIT_SINGLE_EMAIL,
status: HTTPCode.CONFLICT,
});
}

const splitEmail = currentContributor.gitEmails.find(
({ id }) => id === payload.gitEmailId,
);
const hasSplittedEmail = splitEmail !== undefined;

if (!hasSplittedEmail) {
throw new ContributorError({
message: ExceptionMessage.CONTRIBUTOR_SPLIT_FAILED,
status: HTTPCode.CONFLICT,
});
}

try {
const splitContributor = await this.contributorRepository.split(
payload.gitEmailId,
payload.newContributorName,
);

return splitContributor.toObject();
} catch {
throw new ContributorError({
message: ExceptionMessage.CONTRIBUTOR_SPLIT_FAILED,
status: HTTPCode.CONFLICT,
});
}
}

public update(): ReturnType<Service["update"]> {
return Promise.resolve(null);
}
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/modules/contributors/libs/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorPatchResponseDto,
type ContributorSplitRequestDto,
} from "@git-fit/shared";
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
contributorMergeValidationSchema,
contributorPatchValidationSchema,
contributorSplitValidationSchema,
} from "@git-fit/shared";
7 changes: 7 additions & 0 deletions apps/frontend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [1.47.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/frontend-v1.46.0...frontend-v1.47.0) (2024-09-23)


### Features

* Add an ability to split contributors gf-462 ([#477](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/issues/477)) ([adbf2af](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/commit/adbf2afd81ac81518c50b158ab11cd89768e7c8a))

## [1.46.0](https://github.com/BinaryStudioAcademy/bsa-2024-gitfit/compare/frontend-v1.45.0...frontend-v1.46.0) (2024-09-23)


Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@git-fit/frontend",
"private": true,
"version": "1.46.0",
"version": "1.47.0",
"type": "module",
"engines": {
"node": "20.x.x",
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/assets/images/icons/split.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Project from "~/assets/images/icons/project.svg?react";
import RightArrow from "~/assets/images/icons/right-arrow.svg?react";
import RightDoubleArrow from "~/assets/images/icons/right-double-arrow.svg?react";
import Search from "~/assets/images/icons/search.svg?react";
import Split from "~/assets/images/icons/split.svg?react";
import StrikedEye from "~/assets/images/icons/striked-eye.svg?react";
import TrashBin from "~/assets/images/icons/trash-bin.svg?react";
import Warning from "~/assets/images/icons/warning.svg?react";
Expand All @@ -40,6 +41,7 @@ const iconNameToSvg: Record<IconName, FC<React.SVGProps<SVGSVGElement>>> = {
rightArrow: RightArrow,
rightDoubleArrow: RightDoubleArrow,
search: Search,
split: Split,
strikedEye: StrikedEye,
trashBin: TrashBin,
warning: Warning,
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/libs/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ITEMS_CHANGED_COUNT } from "./items-changed-count.constant.js";
export { SIDEBAR_ITEMS } from "./navigation-items.constant.js";
export { EMPTY_LENGTH } from "@git-fit/shared";
export { EMPTY_LENGTH, MIN_GIT_EMAILS_LENGTH_FOR_SPLIT } from "@git-fit/shared";
3 changes: 2 additions & 1 deletion apps/frontend/src/libs/enums/notification-message.enum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const NotificationMessage = {
CONTRIBUTOR_MERGE_SUCCESS: "Contributor was successfully merged.",
CONTRIBUTOR_MERGE_SUCCESS: "Contributors were successfully merged.",
CONTRIBUTOR_SPLIT_SUCCESS: "Contributors were successfully split.",
CONTRIBUTOR_UPDATE_SUCCESS: "Contributor was successfully updated.",
GROUP_CREATE_SUCCESS: "Group was successfully created.",
GROUP_DELETE_SUCCESS: "Group was successfully deleted.",
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/libs/types/icon-name.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type IconName =
| "rightArrow"
| "rightDoubleArrow"
| "search"
| "split"
| "strikedEye"
| "trashBin"
| "warning";
Expand Down
18 changes: 18 additions & 0 deletions apps/frontend/src/modules/contributors/contributors-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorPatchResponseDto,
type ContributorSplitRequestDto,
} from "./contributors.js";
import { ContributorsApiPath } from "./libs/enums/enums.js";

Expand Down Expand Up @@ -92,6 +93,23 @@ class ContributorApi extends BaseHTTPApi {

return await response.json<ContributorPatchResponseDto>();
}

public async split(
id: number,
payload: ContributorSplitRequestDto,
): Promise<ContributorGetAllItemResponseDto> {
const response = await this.load(
this.getFullEndpoint(ContributorsApiPath.SPLIT_$ID, { id: String(id) }),
{
contentType: ContentType.JSON,
hasAuth: true,
method: "PATCH",
payload: JSON.stringify(payload),
},
);

return await response.json<ContributorGetAllItemResponseDto>();
}
}

export { ContributorApi };
2 changes: 2 additions & 0 deletions apps/frontend/src/modules/contributors/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorPatchResponseDto,
type ContributorSplitRequestDto,
} from "./libs/types/types.js";
export {
contributorMergeValidationSchema,
contributorPatchValidationSchema,
contributorSplitValidationSchema,
} from "./libs/validation-schemas/validation-schemas.js";
export { actions, reducer } from "./slices/contributors.js";
1 change: 1 addition & 0 deletions apps/frontend/src/modules/contributors/libs/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export {
type ContributorMergeRequestDto,
type ContributorPatchRequestDto,
type ContributorPatchResponseDto,
type ContributorSplitRequestDto,
} from "@git-fit/shared";
Loading

0 comments on commit 332d300

Please sign in to comment.