diff --git a/backend/src/bundles/auth/auth.controller.ts b/backend/src/bundles/auth/auth.controller.ts index 7a64ed90f..eaf4bb7a3 100644 --- a/backend/src/bundles/auth/auth.controller.ts +++ b/backend/src/bundles/auth/auth.controller.ts @@ -1,4 +1,8 @@ -import { type UserSignUpRequestDto } from '~/bundles/users/users.js'; +import { + type UserSignInRequestDto, + type UserSignUpRequestDto, + userSignInValidationSchema, +} from '~/bundles/users/users.js'; import { userSignUpValidationSchema } from '~/bundles/users/users.js'; import { type ApiHandlerOptions, @@ -20,6 +24,20 @@ class AuthController extends BaseController { this.authService = authService; + this.addRoute({ + path: AuthApiPath.SIGN_IN, + method: 'POST', + validation: { + body: userSignInValidationSchema, + }, + handler: (options) => + this.signIn( + options as ApiHandlerOptions<{ + body: UserSignInRequestDto; + }>, + ), + }); + this.addRoute({ path: AuthApiPath.SIGN_UP, method: 'POST', @@ -35,6 +53,55 @@ class AuthController extends BaseController { }); } + /** + * @swagger + * /auth/sign-in: + * post: + * description: Sign in user into the application + * requestBody: + * description: User auth data + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * email: + * type: string + * format: email + * password: + * type: string + * responses: + * 200: + * description: Successful operation + * content: + * application/json: + * schema: + * type: object + * properties: + * message: + * type: object + * $ref: '#/components/schemas/User' + * 400: + * description: Failed operation + * content: + * application/json: + * schema: + * type: object + * $ref: '#/components/schemas/Error' + */ + + private async signIn( + options: ApiHandlerOptions<{ + body: UserSignInRequestDto; + }>, + ): Promise { + return { + payload: await this.authService.signIn(options.body), + status: HttpCode.OK, + }; + } + /** * @swagger * /auth/sign-up: @@ -65,6 +132,7 @@ class AuthController extends BaseController { * type: object * $ref: '#/components/schemas/User' */ + private async signUp( options: ApiHandlerOptions<{ body: UserSignUpRequestDto; diff --git a/backend/src/bundles/auth/auth.service.ts b/backend/src/bundles/auth/auth.service.ts index 5ae168e63..fabf0d934 100644 --- a/backend/src/bundles/auth/auth.service.ts +++ b/backend/src/bundles/auth/auth.service.ts @@ -3,6 +3,14 @@ import { type UserSignUpResponseDto, } from '~/bundles/users/types/types.js'; import { type UserService } from '~/bundles/users/user.service.js'; +import { + type UserSignInRequestDto, + type UserSignInResponseDto, +} from '~/bundles/users/users.js'; +import { HttpCode, HttpError } from '~/common/http/http.js'; +import { cryptService } from '~/common/services/services.js'; + +import { UserValidationMessage } from './enums/enums.js'; class AuthService { private userService: UserService; @@ -11,6 +19,36 @@ class AuthService { this.userService = userService; } + public async signIn( + userRequestDto: UserSignInRequestDto, + ): Promise { + const { email, password } = userRequestDto; + const user = await this.userService.findByEmail(email); + + if (!user) { + throw new HttpError({ + message: UserValidationMessage.WRONG_CREDENTIALS, + status: HttpCode.BAD_REQUEST, + }); + } + + const { passwordHash } = user.toNewObject(); + + const isPwdCorrect = cryptService.compareSyncPassword( + password, + passwordHash, + ); + + if (!isPwdCorrect) { + throw new HttpError({ + message: UserValidationMessage.WRONG_CREDENTIALS, + status: HttpCode.BAD_REQUEST, + }); + } + + return user.toObject(); + } + public signUp( userRequestDto: UserSignUpRequestDto, ): Promise { diff --git a/backend/src/bundles/auth/enums/enums.ts b/backend/src/bundles/auth/enums/enums.ts index 7cbd1669d..e208cd7f4 100644 --- a/backend/src/bundles/auth/enums/enums.ts +++ b/backend/src/bundles/auth/enums/enums.ts @@ -1 +1 @@ -export { AuthApiPath } from 'shared'; +export { AuthApiPath, UserValidationMessage } from 'shared'; diff --git a/backend/src/bundles/users/types/types.ts b/backend/src/bundles/users/types/types.ts index f44313789..6a3620c41 100644 --- a/backend/src/bundles/users/types/types.ts +++ b/backend/src/bundles/users/types/types.ts @@ -1,5 +1,7 @@ export { type UserGetAllResponseDto, + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from 'shared'; diff --git a/backend/src/bundles/users/user.repository.ts b/backend/src/bundles/users/user.repository.ts index be08919a1..b4d6110d8 100644 --- a/backend/src/bundles/users/user.repository.ts +++ b/backend/src/bundles/users/user.repository.ts @@ -13,6 +13,12 @@ class UserRepository implements Repository { return Promise.resolve(null); } + public async findByEmail(email: string): Promise { + const user = await this.userModel.query().findOne({ email }).execute(); + + return user ? UserEntity.initialize(user) : null; + } + public async findAll(): Promise { const users = await this.userModel.query().execute(); diff --git a/backend/src/bundles/users/user.service.ts b/backend/src/bundles/users/user.service.ts index 1616231f0..778c8f95f 100644 --- a/backend/src/bundles/users/user.service.ts +++ b/backend/src/bundles/users/user.service.ts @@ -20,6 +20,10 @@ class UserService implements Service { return Promise.resolve(null); } + public async findByEmail(email: string): Promise { + return await this.userRepository.findByEmail(email); + } + public async findAll(): Promise { const items = await this.userRepository.findAll(); diff --git a/backend/src/bundles/users/users.ts b/backend/src/bundles/users/users.ts index 1ad8ad701..73f640e85 100644 --- a/backend/src/bundles/users/users.ts +++ b/backend/src/bundles/users/users.ts @@ -11,8 +11,13 @@ const userController = new UserController(logger, userService); export { userController, userService }; export { + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from './types/types.js'; export { UserModel } from './user.model.js'; -export { userSignUpValidationSchema } from './validation-schemas/validation-schemas.js'; +export { + userSignInValidationSchema, + userSignUpValidationSchema, +} from './validation-schemas/validation-schemas.js'; diff --git a/backend/src/bundles/users/validation-schemas/validation-schemas.ts b/backend/src/bundles/users/validation-schemas/validation-schemas.ts index 7bc9a09c5..5952fe0cf 100644 --- a/backend/src/bundles/users/validation-schemas/validation-schemas.ts +++ b/backend/src/bundles/users/validation-schemas/validation-schemas.ts @@ -1 +1 @@ -export { userSignUpValidationSchema } from 'shared'; +export { userSignInValidationSchema, userSignUpValidationSchema } from 'shared'; diff --git a/backend/src/common/server-application/base-server-app-api.ts b/backend/src/common/server-application/base-server-app-api.ts index 6630eaebc..e86461e11 100644 --- a/backend/src/common/server-application/base-server-app-api.ts +++ b/backend/src/common/server-application/base-server-app-api.ts @@ -38,11 +38,27 @@ class BaseServerAppApi implements ServerAppApi { definition: { openapi: '3.0.0', info: { - title: 'Hello World', + title: 'OutreachVids API documentation', version: `${this.version}.0.0`, }, + components: { + schemas: { + Error: { + type: 'object', + properties: { + errorType: { + type: 'string', + enum: ['COMMON', 'VALIDATION'], + }, + message: { + type: 'string', + }, + }, + }, + }, + }, }, - apis: [`src/packages/**/*.controller.${controllerExtension}`], + apis: [`src/bundles/**/*.controller.${controllerExtension}`], }); } } diff --git a/frontend/package.json b/frontend/package.json index 8a6fbed5e..159e25561 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,6 +33,8 @@ "@chakra-ui/react": "2.8.2", "@emotion/react": "11.13.0", "@emotion/styled": "11.13.0", + "@fortawesome/free-solid-svg-icons": "6.6.0", + "@fortawesome/react-fontawesome": "0.2.2", "@reduxjs/toolkit": "2.2.7", "formik": "2.4.6", "framer-motion": "11.3.24", diff --git a/frontend/src/app/app.tsx b/frontend/src/app/app.tsx index 671be91a9..54a2eff7f 100644 --- a/frontend/src/app/app.tsx +++ b/frontend/src/app/app.tsx @@ -1,17 +1,8 @@ import { RouterOutlet } from '~/bundles/common/components/components.js'; -import { AppRoute } from '~/bundles/common/enums/enums.js'; -import { useLocation } from '~/bundles/common/hooks/hooks.js'; const App: React.FC = () => { - const { pathname } = useLocation(); - - const isAuth = - pathname === AppRoute.SIGN_IN || pathname === AppRoute.SIGN_UP; - return ( <> - {/* TODO Header */} - {!isAuth && 'Header'} ); diff --git a/frontend/src/bundles/auth/auth-api.ts b/frontend/src/bundles/auth/auth-api.ts index a81074fa4..53c946f10 100644 --- a/frontend/src/bundles/auth/auth-api.ts +++ b/frontend/src/bundles/auth/auth-api.ts @@ -1,5 +1,7 @@ import { ApiPath, ContentType } from '~/bundles/common/enums/enums.js'; import { + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from '~/bundles/users/users.js'; @@ -20,6 +22,22 @@ class AuthApi extends BaseHttpApi { super({ path: ApiPath.AUTH, baseUrl, http, storage }); } + public async signIn( + payload: UserSignInRequestDto, + ): Promise { + const response = await this.load( + this.getFullEndpoint(AuthApiPath.SIGN_IN, {}), + { + method: 'POST', + contentType: ContentType.JSON, + payload: JSON.stringify(payload), + hasAuth: false, + }, + ); + + return await response.json(); + } + public async signUp( payload: UserSignUpRequestDto, ): Promise { diff --git a/frontend/src/bundles/auth/components/sign-in-form/constants/constants.ts b/frontend/src/bundles/auth/components/sign-in-form/constants/constants.ts new file mode 100644 index 000000000..3e3264e83 --- /dev/null +++ b/frontend/src/bundles/auth/components/sign-in-form/constants/constants.ts @@ -0,0 +1,8 @@ +import { type UserSignInRequestDto } from '~/bundles/users/users.js'; + +const DEFAULT_SIGN_IN_PAYLOAD: UserSignInRequestDto = { + email: '', + password: '', +}; + +export { DEFAULT_SIGN_IN_PAYLOAD }; diff --git a/frontend/src/bundles/auth/components/sign-in-form/sign-in-form.tsx b/frontend/src/bundles/auth/components/sign-in-form/sign-in-form.tsx index bbcad3139..f3a73d1f5 100644 --- a/frontend/src/bundles/auth/components/sign-in-form/sign-in-form.tsx +++ b/frontend/src/bundles/auth/components/sign-in-form/sign-in-form.tsx @@ -1,17 +1,97 @@ -import { Button, Heading } from '~/bundles/common/components/components.js'; +import { + FormError, + FormHeader, + PasswordInput, +} from '~/bundles/auth/components/common/components.js'; +import { + Box, + Button, + FormProvider, + Input, + Link, + VStack, +} from '~/bundles/common/components/components.js'; +import { + AppRoute, + DataStatus, + UserValidationMessage, +} from '~/bundles/common/enums/enums.js'; +import { + useAppForm, + useAppSelector, + useMemo, +} from '~/bundles/common/hooks/hooks.js'; +import { + type UserSignInRequestDto, + userSignInValidationSchema, +} from '~/bundles/users/users.js'; + +import { DEFAULT_SIGN_IN_PAYLOAD } from './constants/constants.js'; type Properties = { - onSubmit: () => void; + onSubmit: (payload: UserSignInRequestDto) => void; }; -const SignInForm: React.FC = () => ( - <> - Sign In +const SignInForm: React.FC = ({ onSubmit }) => { + const { dataStatus } = useAppSelector(({ auth }) => ({ + dataStatus: auth.dataStatus, + })); + const form = useAppForm({ + initialValues: DEFAULT_SIGN_IN_PAYLOAD, + validationSchema: userSignInValidationSchema, + onSubmit, + }); + + const { handleSubmit, errors, values } = form; -
-
+ + + + ); +}; + +export { VideoPreview }; diff --git a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/video-modal-content.tsx b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/video-modal-content.tsx new file mode 100644 index 000000000..737d6bb2e --- /dev/null +++ b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/video-modal-content.tsx @@ -0,0 +1,29 @@ +import { TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react'; +import { faPlay } from '@fortawesome/free-solid-svg-icons/faPlay'; + +import { Tab, VideoPreview } from './components/components.js'; + +const VideoModalContent = (): JSX.Element => { + return ( + + + + + + + + + + + ); +}; + +export { VideoModalContent }; diff --git a/frontend/src/bundles/common/components/video-modal/video-modal.tsx b/frontend/src/bundles/common/components/video-modal/video-modal.tsx new file mode 100644 index 000000000..dfcd36a13 --- /dev/null +++ b/frontend/src/bundles/common/components/video-modal/video-modal.tsx @@ -0,0 +1,44 @@ +import { + Modal, + ModalBody, + ModalCloseButton, + ModalContent, + ModalHeader, + ModalOverlay, +} from '@chakra-ui/react'; + +import { VideoModalContent } from './components/components.js'; + +type Properties = { + isOpen: boolean; + onModalClose: () => void; +}; + +const VideoModal = ({ isOpen, onModalClose }: Properties): JSX.Element => { + return ( + + + + + Create video + + + + + + + + ); +}; + +export { VideoModal }; diff --git a/frontend/src/bundles/common/enums/enums.ts b/frontend/src/bundles/common/enums/enums.ts index 0e65d3c5b..ef77ebca3 100644 --- a/frontend/src/bundles/common/enums/enums.ts +++ b/frontend/src/bundles/common/enums/enums.ts @@ -1,3 +1,9 @@ export { AppRoute } from './app-route.enum.js'; export { DataStatus } from './data-status.enum.js'; -export { ApiPath, AppEnvironment, ContentType, ServerErrorType } from 'shared'; +export { + ApiPath, + AppEnvironment, + ContentType, + ServerErrorType, + UserValidationMessage, +} from 'shared'; diff --git a/frontend/src/bundles/users/types/types.ts b/frontend/src/bundles/users/types/types.ts index fb8e20c76..66268a76e 100644 --- a/frontend/src/bundles/users/types/types.ts +++ b/frontend/src/bundles/users/types/types.ts @@ -1,6 +1,8 @@ export { type UserGetAllItemResponseDto, type UserGetAllResponseDto, + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from 'shared'; diff --git a/frontend/src/bundles/users/users.ts b/frontend/src/bundles/users/users.ts index 443083e1c..1c0f3bf9d 100644 --- a/frontend/src/bundles/users/users.ts +++ b/frontend/src/bundles/users/users.ts @@ -14,7 +14,12 @@ export { userApi }; export { type UserGetAllItemResponseDto, type UserGetAllResponseDto, + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from './types/types.js'; -export { userSignUpValidationSchema } from './validation-schemas/validation-schemas.js'; +export { + userSignInValidationSchema, + userSignUpValidationSchema, +} from './validation-schemas/validation-schemas.js'; diff --git a/frontend/src/bundles/users/validation-schemas/validation-schemas.ts b/frontend/src/bundles/users/validation-schemas/validation-schemas.ts index 7bc9a09c5..5952fe0cf 100644 --- a/frontend/src/bundles/users/validation-schemas/validation-schemas.ts +++ b/frontend/src/bundles/users/validation-schemas/validation-schemas.ts @@ -1 +1 @@ -export { userSignUpValidationSchema } from 'shared'; +export { userSignInValidationSchema, userSignUpValidationSchema } from 'shared'; diff --git a/frontend/src/framework/theme/styles/colors.styles.ts b/frontend/src/framework/theme/styles/colors.styles.ts index 10ec09c65..8ae8d0cce 100644 --- a/frontend/src/framework/theme/styles/colors.styles.ts +++ b/frontend/src/framework/theme/styles/colors.styles.ts @@ -7,9 +7,8 @@ const colors = { 50: '#e2e1ec', }, brand: { - 900: '#1a365d', - 200: '#b3e0ff', secondary: { + 50: '#3BAF28', 300: '#ff6e1c', 600: '#eb5500', 900: '#e13b00', diff --git a/frontend/src/framework/theme/styles/components.styles.ts b/frontend/src/framework/theme/styles/components.styles.ts index 417d40ef9..ff9a15c66 100644 --- a/frontend/src/framework/theme/styles/components.styles.ts +++ b/frontend/src/framework/theme/styles/components.styles.ts @@ -3,7 +3,55 @@ import { colors } from './colors.styles.js'; const components = { Heading: { baseStyle: { - color: colors.text.accent, + color: colors.white, + fontFamily: 'Poppins, sans-serif', + textAlign: 'left', + }, + variants: { + H1: { + fontSize: '54px', + fontWeight: '600', + lineHeight: '64px', + }, + H2: { + fontSize: '30px', + fontWeight: '600', + lineHeight: '32px', + }, + H3: { + fontSize: '18px', + fontWeight: '700', + lineHeight: '27px', + }, + }, + }, + Text: { + baseStyle: { + color: colors.white, + fontFamily: 'Poppins, sans-serif', + textAlign: 'left', + }, + variants: { + body1: { + fontSize: '16px', + fontWeight: '500', + lineHeight: '22px', + }, + bodySmall: { + fontSize: '14px', + fontWeight: '400', + lineHeight: '20px', + }, + caption: { + fontSize: '12px', + fontWeight: '400', + lineHeight: '16px', + }, + button: { + fontSize: '14px', + fontWeight: '600', + lineHeight: '16px', + }, }, }, Button: { diff --git a/package-lock.json b/package-lock.json index c679dfd41..7f75e979e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -75,6 +75,8 @@ "@chakra-ui/react": "2.8.2", "@emotion/react": "11.13.0", "@emotion/styled": "11.13.0", + "@fortawesome/free-solid-svg-icons": "6.6.0", + "@fortawesome/react-fontawesome": "0.2.2", "@reduxjs/toolkit": "2.2.7", "formik": "2.4.6", "framer-motion": "11.3.24", @@ -2799,6 +2801,49 @@ "yaml": "^2.2.2" } }, + "node_modules/@fortawesome/fontawesome-common-types": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.6.0.tgz", + "integrity": "sha512-xyX0X9mc0kyz9plIyryrRbl7ngsA9jz77mCZJsUkLl+ZKs0KWObgaEBoSgQiYWAsSmjz/yjl0F++Got0Mdp4Rw==", + "engines": { + "node": ">=6" + } + }, + "node_modules/@fortawesome/fontawesome-svg-core": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.6.0.tgz", + "integrity": "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg==", + "peer": true, + "dependencies": { + "@fortawesome/fontawesome-common-types": "6.6.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@fortawesome/free-solid-svg-icons": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.6.0.tgz", + "integrity": "sha512-IYv/2skhEDFc2WGUcqvFJkeK39Q+HyPf5GHUrT/l2pKbtgEIv1al1TKd6qStR5OIwQdN1GZP54ci3y4mroJWjA==", + "dependencies": { + "@fortawesome/fontawesome-common-types": "6.6.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@fortawesome/react-fontawesome": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.2.tgz", + "integrity": "sha512-EnkrprPNqI6SXJl//m29hpaNzOp1bruISWaOiRtkMi/xSvHJlzc2j2JAYS7egxt/EbjSNV/k6Xy0AQI6vB2+1g==", + "dependencies": { + "prop-types": "^15.8.1" + }, + "peerDependencies": { + "@fortawesome/fontawesome-svg-core": "~1 || ~6", + "react": ">=16.3" + } + }, "node_modules/@gitbeaker/core": { "version": "38.12.1", "resolved": "https://registry.npmjs.org/@gitbeaker/core/-/core-38.12.1.tgz", diff --git a/shared/src/bundles/auth/enums/auth-api-path.enum.ts b/shared/src/bundles/auth/enums/auth-api-path.enum.ts index 5833c6684..79d9340e1 100644 --- a/shared/src/bundles/auth/enums/auth-api-path.enum.ts +++ b/shared/src/bundles/auth/enums/auth-api-path.enum.ts @@ -1,5 +1,6 @@ const AuthApiPath = { ROOT: '/', + SIGN_IN: '/sign-in', SIGN_UP: '/sign-up', } as const; diff --git a/shared/src/bundles/users/enums/user-validation-message.enum.ts b/shared/src/bundles/users/enums/user-validation-message.enum.ts index 34bc45223..ad735094d 100644 --- a/shared/src/bundles/users/enums/user-validation-message.enum.ts +++ b/shared/src/bundles/users/enums/user-validation-message.enum.ts @@ -1,8 +1,12 @@ const UserValidationMessage = { - FIELD_IS_REQUIRE: 'Please fill out this field', + EMAIL_REQUIRE: 'Email is required', + EMAIL_WRONG: 'Email is wrong', + FIELD_REQUIRE: 'Please fill out this field', EMAIL_INVALID: 'Please enter a valid email', PASSWORD_LENGTH: 'Password must have from 6 to 12 characters', PASS_DONT_MATCH: 'Passwords must be identical', + INVALID_DATA: 'Incorrect email or password. Please try again.', + WRONG_CREDENTIALS: 'Email or password are incorrect', USER_IS_NOT_AVAILABLE: 'User with this email already exists. Log in if it is you', } as const; diff --git a/shared/src/bundles/users/types/types.ts b/shared/src/bundles/users/types/types.ts index 7564f70b2..36cfa4fdb 100644 --- a/shared/src/bundles/users/types/types.ts +++ b/shared/src/bundles/users/types/types.ts @@ -1,4 +1,6 @@ export { type UserGetAllItemResponseDto } from './user-get-all-item-response-dto.type.js'; export { type UserGetAllResponseDto } from './user-get-all-response-dto.type.js'; +export { type UserSignInRequestDto } from './user-sign-in-request-dto.type.js'; +export { type UserSignInResponseDto } from './user-sign-in-response-dto.type.js'; export { type UserSignUpRequestDto } from './user-sign-up-request-dto.type.js'; export { type UserSignUpResponseDto } from './user-sign-up-response-dto.type.js'; diff --git a/shared/src/bundles/users/types/user-sign-in-request-dto.type.ts b/shared/src/bundles/users/types/user-sign-in-request-dto.type.ts new file mode 100644 index 000000000..8098c64cf --- /dev/null +++ b/shared/src/bundles/users/types/user-sign-in-request-dto.type.ts @@ -0,0 +1,6 @@ +type UserSignInRequestDto = { + email: string; + password: string; +}; + +export { type UserSignInRequestDto }; diff --git a/shared/src/bundles/users/types/user-sign-in-response-dto.type.ts b/shared/src/bundles/users/types/user-sign-in-response-dto.type.ts new file mode 100644 index 000000000..afb72b351 --- /dev/null +++ b/shared/src/bundles/users/types/user-sign-in-response-dto.type.ts @@ -0,0 +1,6 @@ +type UserSignInResponseDto = { + id: number; + email: string; +}; + +export { type UserSignInResponseDto }; diff --git a/shared/src/bundles/users/users.ts b/shared/src/bundles/users/users.ts index e65858985..5a2147adc 100644 --- a/shared/src/bundles/users/users.ts +++ b/shared/src/bundles/users/users.ts @@ -2,7 +2,12 @@ export { UsersApiPath, UserValidationMessage } from './enums/enums.js'; export { type UserGetAllItemResponseDto, type UserGetAllResponseDto, + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, } from './types/types.js'; -export { userSignUp as userSignUpValidationSchema } from './validation-schemas/validation-schemas.js'; +export { + userSignIn as userSignInValidationSchema, + userSignUp as userSignUpValidationSchema, +} from './validation-schemas/validation-schemas.js'; diff --git a/shared/src/bundles/users/validation-schemas/user-sign-in.validation-schema.ts b/shared/src/bundles/users/validation-schemas/user-sign-in.validation-schema.ts new file mode 100644 index 000000000..100cb3dad --- /dev/null +++ b/shared/src/bundles/users/validation-schemas/user-sign-in.validation-schema.ts @@ -0,0 +1,36 @@ +import { z } from 'zod'; + +import { UserValidationMessage, UserValidationRule } from '../enums/enums.js'; + +type UserSignInRequestValidationDto = { + email: z.ZodString; + password: z.ZodString; +}; + +const userSignIn = z + .object({ + email: z + .string({ required_error: UserValidationMessage.FIELD_REQUIRE }) + .trim() + .min(UserValidationRule.EMAIL_MINIMUM_LENGTH, { + message: UserValidationMessage.EMAIL_INVALID, + }) + .max(UserValidationRule.EMAIL_MAXIMUM_LENGTH, { + message: UserValidationMessage.EMAIL_INVALID, + }) + .email({ + message: UserValidationMessage.EMAIL_INVALID, + }), + password: z + .string({ required_error: UserValidationMessage.FIELD_REQUIRE }) + .trim() + .min(UserValidationRule.PASSWORD_MINIMUM_LENGTH, { + message: UserValidationMessage.PASSWORD_LENGTH, + }) + .max(UserValidationRule.PASSWORD_MAXIMUM_LENGTH, { + message: UserValidationMessage.PASSWORD_LENGTH, + }), + }) + .required(); + +export { userSignIn }; diff --git a/shared/src/bundles/users/validation-schemas/validation-schemas.ts b/shared/src/bundles/users/validation-schemas/validation-schemas.ts index cb1c2ad60..f6c85f13c 100644 --- a/shared/src/bundles/users/validation-schemas/validation-schemas.ts +++ b/shared/src/bundles/users/validation-schemas/validation-schemas.ts @@ -1 +1,2 @@ +export { userSignIn } from './user-sign-in.validation-schema.js'; export { userSignUp } from './user-sign-up.validation-schema.js'; diff --git a/shared/src/framework/http/enums/http-code.enum.ts b/shared/src/framework/http/enums/http-code.enum.ts index 59a238f46..6d2ad89ba 100644 --- a/shared/src/framework/http/enums/http-code.enum.ts +++ b/shared/src/framework/http/enums/http-code.enum.ts @@ -1,6 +1,7 @@ const HttpCode = { OK: 200, CREATED: 201, + BAD_REQUEST: 400, UNPROCESSED_ENTITY: 422, INTERNAL_SERVER_ERROR: 500, } as const; diff --git a/shared/src/index.ts b/shared/src/index.ts index df887038b..d4b77ee0e 100644 --- a/shared/src/index.ts +++ b/shared/src/index.ts @@ -2,10 +2,14 @@ export { AuthApiPath } from './bundles/auth/auth.js'; export { type UserGetAllItemResponseDto, type UserGetAllResponseDto, + type UserSignInRequestDto, + type UserSignInResponseDto, type UserSignUpRequestDto, type UserSignUpResponseDto, UsersApiPath, + userSignInValidationSchema, userSignUpValidationSchema, + UserValidationMessage, } from './bundles/users/users.js'; export { ApiPath,