-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/BinaryStudioAcademy/bsa-202…
…4-gitfit into 348-feat-add-projects-select-to-analytics-page
- Loading branch information
Showing
48 changed files
with
507 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
".": "1.47.0", | ||
"apps/backend": "1.29.0", | ||
"apps/frontend": "1.43.0", | ||
"packages/shared": "1.27.0", | ||
"scripts/analytics": "1.6.0" | ||
".": "1.48.0", | ||
"apps/backend": "1.30.0", | ||
"apps/frontend": "1.44.0", | ||
"packages/shared": "1.28.0", | ||
"scripts/analytics": "1.7.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
apps/backend/src/modules/auth-analytics/auth-analytics.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { APIPath } from "~/libs/enums/enums.js"; | ||
import { | ||
type APIHandlerOptions, | ||
type APIHandlerResponse, | ||
BaseController, | ||
} from "~/libs/modules/controller/controller.js"; | ||
import { HTTPCode } from "~/libs/modules/http/http.js"; | ||
import { type Logger } from "~/libs/modules/logger/logger.js"; | ||
|
||
import { type AuthAnalyticsService } from "./auth-analytics.service.js"; | ||
import { AuthAnalyticsApiPath } from "./libs/enums/enums.js"; | ||
import { type AuthAnalyticsValidateCredentialsRequestDto } from "./libs/types/types.js"; | ||
import { authAnalyticsValidateCredentialsValidationSchema } from "./libs/validation-schemas/validation-schemas.js"; | ||
|
||
class AuthAnalyticsController extends BaseController { | ||
private authAnalyticsService: AuthAnalyticsService; | ||
|
||
public constructor( | ||
logger: Logger, | ||
authAnalyticsService: AuthAnalyticsService, | ||
) { | ||
super(logger, APIPath.AUTH_ANALYTICS); | ||
|
||
this.authAnalyticsService = authAnalyticsService; | ||
|
||
this.addRoute({ | ||
handler: (options) => | ||
this.validateCredentials( | ||
options as APIHandlerOptions<{ | ||
body: AuthAnalyticsValidateCredentialsRequestDto; | ||
headers: Record<string, string | undefined>; | ||
}>, | ||
), | ||
method: "POST", | ||
path: AuthAnalyticsApiPath.ROOT, | ||
validation: { | ||
body: authAnalyticsValidateCredentialsValidationSchema, | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* @swagger | ||
* /auth-analytics: | ||
* post: | ||
* description: Validate credentials for collecting statistics script | ||
* requestBody: | ||
* description: Collecting statistics script credentials | ||
* required: true | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* userId: | ||
* type: number | ||
* minimum: 1 | ||
* responses: | ||
* 200: | ||
* description: Successful operation | ||
* content: | ||
* application/json: | ||
* schema: | ||
* type: object | ||
* properties: | ||
* projectId: | ||
* type: number | ||
* projectName: | ||
* type: string | ||
*/ | ||
|
||
private async validateCredentials( | ||
options: APIHandlerOptions<{ | ||
body: AuthAnalyticsValidateCredentialsRequestDto; | ||
headers: Record<string, string | undefined>; | ||
}>, | ||
): Promise<APIHandlerResponse> { | ||
const authorizationHeader = options.headers["authorization"]; | ||
const apiKey = authorizationHeader?.replace("Bearer ", "") ?? ""; | ||
|
||
const payload = { | ||
apiKey, | ||
...options.body, | ||
}; | ||
|
||
return { | ||
payload: await this.authAnalyticsService.validateCredentials(payload), | ||
status: HTTPCode.OK, | ||
}; | ||
} | ||
} | ||
|
||
export { AuthAnalyticsController }; |
44 changes: 44 additions & 0 deletions
44
apps/backend/src/modules/auth-analytics/auth-analytics.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { type UserService } from "~/modules/users/user.service.js"; | ||
|
||
import { type ProjectApiKeyService } from "../project-api-keys/project-api-keys.js"; | ||
import { type ProjectService } from "../projects/projects.js"; | ||
import { | ||
type AuthAnalyticsValidateCredentialsRequestDto, | ||
type AuthAnalyticsValidateCredentialsResponseDto, | ||
} from "./libs/types/types.js"; | ||
|
||
class AuthAnalyticsService { | ||
private projectApiKeyService: ProjectApiKeyService; | ||
|
||
private projectService: ProjectService; | ||
|
||
private userService: UserService; | ||
|
||
public constructor( | ||
projectApiKeyService: ProjectApiKeyService, | ||
projectService: ProjectService, | ||
userService: UserService, | ||
) { | ||
this.projectService = projectService; | ||
this.projectApiKeyService = projectApiKeyService; | ||
this.userService = userService; | ||
} | ||
|
||
public async validateCredentials( | ||
payload: { apiKey: string } & AuthAnalyticsValidateCredentialsRequestDto, | ||
): Promise<AuthAnalyticsValidateCredentialsResponseDto> { | ||
await this.userService.find(payload.userId); | ||
|
||
const projectApiKeyEntity = await this.projectApiKeyService.findByApiKey( | ||
payload.apiKey, | ||
); | ||
|
||
const project = await this.projectService.find( | ||
projectApiKeyEntity.projectId, | ||
); | ||
|
||
return { projectId: project.id, projectName: project.name }; | ||
} | ||
} | ||
|
||
export { AuthAnalyticsService }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { logger } from "~/libs/modules/logger/logger.js"; | ||
import { projectApiKeyService } from "~/modules/project-api-keys/project-api-keys.js"; | ||
import { projectService } from "~/modules/projects/projects.js"; | ||
import { userService } from "~/modules/users/users.js"; | ||
|
||
import { AuthAnalyticsController } from "./auth-analytics.controller.js"; | ||
import { AuthAnalyticsService } from "./auth-analytics.service.js"; | ||
|
||
const authAnalyticsService = new AuthAnalyticsService( | ||
projectApiKeyService, | ||
projectService, | ||
userService, | ||
); | ||
const authAnalyticsController = new AuthAnalyticsController( | ||
logger, | ||
authAnalyticsService, | ||
); | ||
|
||
export { authAnalyticsController }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AuthAnalyticsApiPath } from "@git-fit/shared"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
type AuthAnalyticsValidateCredentialsRequestDto, | ||
type AuthAnalyticsValidateCredentialsResponseDto, | ||
} from "@git-fit/shared"; |
1 change: 1 addition & 0 deletions
1
apps/backend/src/modules/auth-analytics/libs/validation-schemas/validation-schemas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { authAnalyticsValidateCredentialsValidationSchema } from "@git-fit/shared"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.