@intlayer/backend 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/dist/cjs/controllers/dictionary.controller.cjs +356 -0
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -0
- package/dist/cjs/controllers/oAuth2.controller.cjs +46 -0
- package/dist/cjs/controllers/oAuth2.controller.cjs.map +1 -0
- package/dist/cjs/controllers/organization.controller.cjs +354 -0
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -0
- package/dist/cjs/controllers/project.controller.cjs +298 -0
- package/dist/cjs/controllers/project.controller.cjs.map +1 -0
- package/dist/cjs/controllers/projectAccessKey.controller.cjs +134 -0
- package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -0
- package/dist/cjs/controllers/sessionAuth.controller.cjs +616 -0
- package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +197 -0
- package/dist/cjs/controllers/user.controller.cjs.map +1 -0
- package/dist/cjs/emails/InviteUserEmail.cjs +297 -0
- package/dist/cjs/emails/InviteUserEmail.cjs.map +1 -0
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs +148 -0
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs.map +1 -0
- package/dist/cjs/emails/ResetUserPassword.cjs +209 -0
- package/dist/cjs/emails/ResetUserPassword.cjs.map +1 -0
- package/dist/cjs/emails/ValidateUserEmail.cjs +230 -0
- package/dist/cjs/emails/ValidateUserEmail.cjs.map +1 -0
- package/dist/cjs/emails/Welcome.cjs +185 -0
- package/dist/cjs/emails/Welcome.cjs.map +1 -0
- package/dist/cjs/emails/index.cjs +31 -0
- package/dist/cjs/emails/index.cjs.map +1 -0
- package/dist/cjs/export.cjs +46 -0
- package/dist/cjs/export.cjs.map +1 -0
- package/dist/cjs/index.cjs +122 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/logger/index.cjs +53 -0
- package/dist/cjs/logger/index.cjs.map +1 -0
- package/dist/cjs/middlewares/admin.middleware.cjs +44 -0
- package/dist/cjs/middlewares/admin.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs +89 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/request.middleware.cjs +41 -0
- package/dist/cjs/middlewares/request.middleware.cjs.map +1 -0
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs +130 -0
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -0
- package/dist/cjs/models/dictionary.model.cjs +34 -0
- package/dist/cjs/models/dictionary.model.cjs.map +1 -0
- package/dist/cjs/models/oAuth2.model.cjs +31 -0
- package/dist/cjs/models/oAuth2.model.cjs.map +1 -0
- package/dist/cjs/models/organization.model.cjs +34 -0
- package/dist/cjs/models/organization.model.cjs.map +1 -0
- package/dist/cjs/models/project.model.cjs +31 -0
- package/dist/cjs/models/project.model.cjs.map +1 -0
- package/dist/cjs/models/user.model.cjs +31 -0
- package/dist/cjs/models/user.model.cjs.map +1 -0
- package/dist/cjs/routes/dictionary.routes.cjs +156 -0
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -0
- package/dist/cjs/routes/organization.routes.cjs +132 -0
- package/dist/cjs/routes/organization.routes.cjs.map +1 -0
- package/dist/cjs/routes/project.routes.cjs +175 -0
- package/dist/cjs/routes/project.routes.cjs.map +1 -0
- package/dist/cjs/routes/sessionAuth.routes.cjs +147 -0
- package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -0
- package/dist/cjs/routes/user.routes.cjs +96 -0
- package/dist/cjs/routes/user.routes.cjs.map +1 -0
- package/dist/cjs/schemas/dictionary.schema.cjs +69 -0
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -0
- package/dist/cjs/schemas/oAuth2.schema.cjs +55 -0
- package/dist/cjs/schemas/oAuth2.schema.cjs.map +1 -0
- package/dist/cjs/schemas/organization.schema.cjs +60 -0
- package/dist/cjs/schemas/organization.schema.cjs.map +1 -0
- package/dist/cjs/schemas/project.schema.cjs +79 -0
- package/dist/cjs/schemas/project.schema.cjs.map +1 -0
- package/dist/cjs/schemas/user.schema.cjs +112 -0
- package/dist/cjs/schemas/user.schema.cjs.map +1 -0
- package/dist/cjs/services/dictionary.service.cjs +166 -0
- package/dist/cjs/services/dictionary.service.cjs.map +1 -0
- package/dist/cjs/services/email.service.cjs +118 -0
- package/dist/cjs/services/email.service.cjs.map +1 -0
- package/dist/cjs/services/oAuth2.service.cjs +182 -0
- package/dist/cjs/services/oAuth2.service.cjs.map +1 -0
- package/dist/cjs/services/organization.service.cjs +95 -0
- package/dist/cjs/services/organization.service.cjs.map +1 -0
- package/dist/cjs/services/project.service.cjs +87 -0
- package/dist/cjs/services/project.service.cjs.map +1 -0
- package/dist/cjs/services/projectAccessKey.service.cjs +139 -0
- package/dist/cjs/services/projectAccessKey.service.cjs.map +1 -0
- package/dist/cjs/services/sessionAuth.service.cjs +386 -0
- package/dist/cjs/services/sessionAuth.service.cjs.map +1 -0
- package/dist/cjs/services/user.service.cjs +155 -0
- package/dist/cjs/services/user.service.cjs.map +1 -0
- package/dist/cjs/types/Routes.cjs +17 -0
- package/dist/cjs/types/Routes.cjs.map +1 -0
- package/dist/cjs/types/dictionary.types.cjs +17 -0
- package/dist/cjs/types/dictionary.types.cjs.map +1 -0
- package/dist/cjs/types/organization.types.cjs +17 -0
- package/dist/cjs/types/organization.types.cjs.map +1 -0
- package/dist/cjs/types/project.types.cjs +17 -0
- package/dist/cjs/types/project.types.cjs.map +1 -0
- package/dist/cjs/types/session.types.cjs +17 -0
- package/dist/cjs/types/session.types.cjs.map +1 -0
- package/dist/cjs/types/user.types.cjs +17 -0
- package/dist/cjs/types/user.types.cjs.map +1 -0
- package/dist/cjs/utils/CSRF.cjs +47 -0
- package/dist/cjs/utils/CSRF.cjs.map +1 -0
- package/dist/cjs/utils/accessControl.cjs +121 -0
- package/dist/cjs/utils/accessControl.cjs.map +1 -0
- package/dist/cjs/utils/cookies.cjs +59 -0
- package/dist/cjs/utils/cookies.cjs.map +1 -0
- package/dist/cjs/utils/errors/ErrorHandler.cjs +103 -0
- package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -0
- package/dist/cjs/utils/errors/ErrorsClass.cjs +65 -0
- package/dist/cjs/utils/errors/ErrorsClass.cjs.map +1 -0
- package/dist/cjs/utils/errors/errorCodes.cjs +837 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -0
- package/dist/cjs/utils/errors/index.cjs +37 -0
- package/dist/cjs/utils/errors/index.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +55 -0
- package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs +65 -0
- package/dist/cjs/utils/filtersAndPagination/getFiltersAndPaginationFromBody.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +55 -0
- package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +58 -0
- package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +52 -0
- package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -0
- package/dist/cjs/utils/httpStatusCodes.cjs +93 -0
- package/dist/cjs/utils/httpStatusCodes.cjs.map +1 -0
- package/dist/cjs/utils/mapper/dictionary.cjs +40 -0
- package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -0
- package/dist/cjs/utils/mapper/organization.cjs +39 -0
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -0
- package/dist/cjs/utils/mapper/project.cjs +39 -0
- package/dist/cjs/utils/mapper/project.cjs.map +1 -0
- package/dist/cjs/utils/mapper/user.cjs +39 -0
- package/dist/cjs/utils/mapper/user.cjs.map +1 -0
- package/dist/cjs/utils/mongoDB/connectDB.cjs +53 -0
- package/dist/cjs/utils/mongoDB/connectDB.cjs.map +1 -0
- package/dist/cjs/utils/oAuth2.cjs +50 -0
- package/dist/cjs/utils/oAuth2.cjs.map +1 -0
- package/dist/cjs/utils/responseData.cjs +66 -0
- package/dist/cjs/utils/responseData.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateArray.cjs +57 -0
- package/dist/cjs/utils/validation/validateArray.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateDictionary.cjs +66 -0
- package/dist/cjs/utils/validation/validateDictionary.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateEmail.cjs +37 -0
- package/dist/cjs/utils/validation/validateEmail.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateOrganization.cjs +79 -0
- package/dist/cjs/utils/validation/validateOrganization.cjs.map +1 -0
- package/dist/cjs/utils/validation/validatePhone.cjs +37 -0
- package/dist/cjs/utils/validation/validatePhone.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateProject.cjs +97 -0
- package/dist/cjs/utils/validation/validateProject.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateString.cjs +39 -0
- package/dist/cjs/utils/validation/validateString.cjs.map +1 -0
- package/dist/cjs/utils/validation/validateUser.cjs +73 -0
- package/dist/cjs/utils/validation/validateUser.cjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +321 -0
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -0
- package/dist/esm/controllers/oAuth2.controller.mjs +25 -0
- package/dist/esm/controllers/oAuth2.controller.mjs.map +1 -0
- package/dist/esm/controllers/organization.controller.mjs +317 -0
- package/dist/esm/controllers/organization.controller.mjs.map +1 -0
- package/dist/esm/controllers/project.controller.mjs +263 -0
- package/dist/esm/controllers/project.controller.mjs.map +1 -0
- package/dist/esm/controllers/projectAccessKey.controller.mjs +98 -0
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -0
- package/dist/esm/controllers/sessionAuth.controller.mjs +570 -0
- package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +160 -0
- package/dist/esm/controllers/user.controller.mjs.map +1 -0
- package/dist/esm/emails/InviteUserEmail.mjs +285 -0
- package/dist/esm/emails/InviteUserEmail.mjs.map +1 -0
- package/dist/esm/emails/PasswordChangeConfirmation.mjs +134 -0
- package/dist/esm/emails/PasswordChangeConfirmation.mjs.map +1 -0
- package/dist/esm/emails/ResetUserPassword.mjs +197 -0
- package/dist/esm/emails/ResetUserPassword.mjs.map +1 -0
- package/dist/esm/emails/ValidateUserEmail.mjs +218 -0
- package/dist/esm/emails/ValidateUserEmail.mjs.map +1 -0
- package/dist/esm/emails/Welcome.mjs +173 -0
- package/dist/esm/emails/Welcome.mjs.map +1 -0
- package/dist/esm/emails/index.mjs +6 -0
- package/dist/esm/emails/index.mjs.map +1 -0
- package/dist/esm/export.mjs +15 -0
- package/dist/esm/export.mjs.map +1 -0
- package/dist/esm/index.mjs +102 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/logger/index.mjs +29 -0
- package/dist/esm/logger/index.mjs.map +1 -0
- package/dist/esm/middlewares/admin.middleware.mjs +20 -0
- package/dist/esm/middlewares/admin.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs +57 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/request.middleware.mjs +17 -0
- package/dist/esm/middlewares/request.middleware.mjs.map +1 -0
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +96 -0
- package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -0
- package/dist/esm/models/dictionary.model.mjs +10 -0
- package/dist/esm/models/dictionary.model.mjs.map +1 -0
- package/dist/esm/models/oAuth2.model.mjs +7 -0
- package/dist/esm/models/oAuth2.model.mjs.map +1 -0
- package/dist/esm/models/organization.model.mjs +10 -0
- package/dist/esm/models/organization.model.mjs.map +1 -0
- package/dist/esm/models/project.model.mjs +7 -0
- package/dist/esm/models/project.model.mjs.map +1 -0
- package/dist/esm/models/user.model.mjs +7 -0
- package/dist/esm/models/user.model.mjs.map +1 -0
- package/dist/esm/routes/dictionary.routes.mjs +139 -0
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -0
- package/dist/esm/routes/organization.routes.mjs +116 -0
- package/dist/esm/routes/organization.routes.mjs.map +1 -0
- package/dist/esm/routes/project.routes.mjs +162 -0
- package/dist/esm/routes/project.routes.mjs.map +1 -0
- package/dist/esm/routes/sessionAuth.routes.mjs +134 -0
- package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -0
- package/dist/esm/routes/user.routes.mjs +78 -0
- package/dist/esm/routes/user.routes.mjs.map +1 -0
- package/dist/esm/schemas/dictionary.schema.mjs +45 -0
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -0
- package/dist/esm/schemas/oAuth2.schema.mjs +31 -0
- package/dist/esm/schemas/oAuth2.schema.mjs.map +1 -0
- package/dist/esm/schemas/organization.schema.mjs +40 -0
- package/dist/esm/schemas/organization.schema.mjs.map +1 -0
- package/dist/esm/schemas/project.schema.mjs +59 -0
- package/dist/esm/schemas/project.schema.mjs.map +1 -0
- package/dist/esm/schemas/user.schema.mjs +81 -0
- package/dist/esm/schemas/user.schema.mjs.map +1 -0
- package/dist/esm/services/dictionary.service.mjs +134 -0
- package/dist/esm/services/dictionary.service.mjs.map +1 -0
- package/dist/esm/services/email.service.mjs +114 -0
- package/dist/esm/services/email.service.mjs.map +1 -0
- package/dist/esm/services/oAuth2.service.mjs +150 -0
- package/dist/esm/services/oAuth2.service.mjs.map +1 -0
- package/dist/esm/services/organization.service.mjs +68 -0
- package/dist/esm/services/organization.service.mjs.map +1 -0
- package/dist/esm/services/project.service.mjs +60 -0
- package/dist/esm/services/project.service.mjs.map +1 -0
- package/dist/esm/services/projectAccessKey.service.mjs +113 -0
- package/dist/esm/services/projectAccessKey.service.mjs.map +1 -0
- package/dist/esm/services/sessionAuth.service.mjs +337 -0
- package/dist/esm/services/sessionAuth.service.mjs.map +1 -0
- package/dist/esm/services/user.service.mjs +122 -0
- package/dist/esm/services/user.service.mjs.map +1 -0
- package/dist/esm/types/Routes.mjs +1 -0
- package/dist/esm/types/Routes.mjs.map +1 -0
- package/dist/esm/types/dictionary.types.mjs +1 -0
- package/dist/esm/types/dictionary.types.mjs.map +1 -0
- package/dist/esm/types/organization.types.mjs +1 -0
- package/dist/esm/types/organization.types.mjs.map +1 -0
- package/dist/esm/types/project.types.mjs +1 -0
- package/dist/esm/types/project.types.mjs.map +1 -0
- package/dist/esm/types/session.types.mjs +1 -0
- package/dist/esm/types/session.types.mjs.map +1 -0
- package/dist/esm/types/user.types.mjs +1 -0
- package/dist/esm/types/user.types.mjs.map +1 -0
- package/dist/esm/utils/CSRF.mjs +21 -0
- package/dist/esm/utils/CSRF.mjs.map +1 -0
- package/dist/esm/utils/accessControl.mjs +95 -0
- package/dist/esm/utils/accessControl.mjs.map +1 -0
- package/dist/esm/utils/cookies.mjs +32 -0
- package/dist/esm/utils/cookies.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs +79 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorsClass.mjs +40 -0
- package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -0
- package/dist/esm/utils/errors/errorCodes.mjs +813 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -0
- package/dist/esm/utils/errors/index.mjs +10 -0
- package/dist/esm/utils/errors/index.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +33 -0
- package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs +41 -0
- package/dist/esm/utils/filtersAndPagination/getFiltersAndPaginationFromBody.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +33 -0
- package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +36 -0
- package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +30 -0
- package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -0
- package/dist/esm/utils/httpStatusCodes.mjs +69 -0
- package/dist/esm/utils/httpStatusCodes.mjs.map +1 -0
- package/dist/esm/utils/mapper/dictionary.mjs +16 -0
- package/dist/esm/utils/mapper/dictionary.mjs.map +1 -0
- package/dist/esm/utils/mapper/organization.mjs +15 -0
- package/dist/esm/utils/mapper/organization.mjs.map +1 -0
- package/dist/esm/utils/mapper/project.mjs +15 -0
- package/dist/esm/utils/mapper/project.mjs.map +1 -0
- package/dist/esm/utils/mapper/user.mjs +14 -0
- package/dist/esm/utils/mapper/user.mjs.map +1 -0
- package/dist/esm/utils/mongoDB/connectDB.mjs +19 -0
- package/dist/esm/utils/mongoDB/connectDB.mjs.map +1 -0
- package/dist/esm/utils/oAuth2.mjs +29 -0
- package/dist/esm/utils/oAuth2.mjs.map +1 -0
- package/dist/esm/utils/responseData.mjs +41 -0
- package/dist/esm/utils/responseData.mjs.map +1 -0
- package/dist/esm/utils/validation/validateArray.mjs +33 -0
- package/dist/esm/utils/validation/validateArray.mjs.map +1 -0
- package/dist/esm/utils/validation/validateDictionary.mjs +42 -0
- package/dist/esm/utils/validation/validateDictionary.mjs.map +1 -0
- package/dist/esm/utils/validation/validateEmail.mjs +13 -0
- package/dist/esm/utils/validation/validateEmail.mjs.map +1 -0
- package/dist/esm/utils/validation/validateOrganization.mjs +52 -0
- package/dist/esm/utils/validation/validateOrganization.mjs.map +1 -0
- package/dist/esm/utils/validation/validatePhone.mjs +13 -0
- package/dist/esm/utils/validation/validatePhone.mjs.map +1 -0
- package/dist/esm/utils/validation/validateProject.mjs +70 -0
- package/dist/esm/utils/validation/validateProject.mjs.map +1 -0
- package/dist/esm/utils/validation/validateString.mjs +15 -0
- package/dist/esm/utils/validation/validateString.mjs.map +1 -0
- package/dist/esm/utils/validation/validateUser.mjs +47 -0
- package/dist/esm/utils/validation/validateUser.mjs.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts +70 -0
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -0
- package/dist/types/controllers/oAuth2.controller.d.ts +14 -0
- package/dist/types/controllers/oAuth2.controller.d.ts.map +1 -0
- package/dist/types/controllers/organization.controller.d.ts +72 -0
- package/dist/types/controllers/organization.controller.d.ts.map +1 -0
- package/dist/types/controllers/project.controller.d.ts +59 -0
- package/dist/types/controllers/project.controller.d.ts.map +1 -0
- package/dist/types/controllers/projectAccessKey.controller.d.ts +27 -0
- package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -0
- package/dist/types/controllers/sessionAuth.controller.d.ts +120 -0
- package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts +56 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -0
- package/dist/types/emails/InviteUserEmail.d.ts +22 -0
- package/dist/types/emails/InviteUserEmail.d.ts.map +1 -0
- package/dist/types/emails/PasswordChangeConfirmation.d.ts +16 -0
- package/dist/types/emails/PasswordChangeConfirmation.d.ts.map +1 -0
- package/dist/types/emails/ResetUserPassword.d.ts +17 -0
- package/dist/types/emails/ResetUserPassword.d.ts.map +1 -0
- package/dist/types/emails/ValidateUserEmail.d.ts +17 -0
- package/dist/types/emails/ValidateUserEmail.d.ts.map +1 -0
- package/dist/types/emails/Welcome.d.ts +17 -0
- package/dist/types/emails/Welcome.d.ts.map +1 -0
- package/dist/types/emails/index.d.ts +6 -0
- package/dist/types/emails/index.d.ts.map +1 -0
- package/dist/types/export.d.ts +19 -0
- package/dist/types/export.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger/index.d.ts +2 -0
- package/dist/types/logger/index.d.ts.map +1 -0
- package/dist/types/middlewares/admin.middleware.d.ts +10 -0
- package/dist/types/middlewares/admin.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/oAuth2.middleware.d.ts +9 -0
- package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/request.middleware.d.ts +4 -0
- package/dist/types/middlewares/request.middleware.d.ts.map +1 -0
- package/dist/types/middlewares/sessionAuth.middleware.d.ts +20 -0
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -0
- package/dist/types/models/dictionary.model.d.ts +11 -0
- package/dist/types/models/dictionary.model.d.ts.map +1 -0
- package/dist/types/models/oAuth2.model.d.ts +10 -0
- package/dist/types/models/oAuth2.model.d.ts.map +1 -0
- package/dist/types/models/organization.model.d.ts +12 -0
- package/dist/types/models/organization.model.d.ts.map +1 -0
- package/dist/types/models/project.model.d.ts +12 -0
- package/dist/types/models/project.model.d.ts.map +1 -0
- package/dist/types/models/user.model.d.ts +3 -0
- package/dist/types/models/user.model.d.ts.map +1 -0
- package/dist/types/routes/dictionary.routes.d.ts +42 -0
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -0
- package/dist/types/routes/organization.routes.d.ts +47 -0
- package/dist/types/routes/organization.routes.d.ts.map +1 -0
- package/dist/types/routes/project.routes.d.ts +57 -0
- package/dist/types/routes/project.routes.d.ts.map +1 -0
- package/dist/types/routes/sessionAuth.routes.d.ts +66 -0
- package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -0
- package/dist/types/routes/user.routes.d.ts +42 -0
- package/dist/types/routes/user.routes.d.ts.map +1 -0
- package/dist/types/schemas/dictionary.schema.d.ts +16 -0
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -0
- package/dist/types/schemas/oAuth2.schema.d.ts +19 -0
- package/dist/types/schemas/oAuth2.schema.d.ts.map +1 -0
- package/dist/types/schemas/organization.schema.d.ts +17 -0
- package/dist/types/schemas/organization.schema.d.ts.map +1 -0
- package/dist/types/schemas/project.schema.d.ts +17 -0
- package/dist/types/schemas/project.schema.d.ts.map +1 -0
- package/dist/types/schemas/user.schema.d.ts +12 -0
- package/dist/types/schemas/user.schema.d.ts.map +1 -0
- package/dist/types/services/dictionary.service.d.ts +70 -0
- package/dist/types/services/dictionary.service.d.ts.map +1 -0
- package/dist/types/services/email.service.d.ts +18 -0
- package/dist/types/services/email.service.d.ts.map +1 -0
- package/dist/types/services/oAuth2.service.d.ts +85 -0
- package/dist/types/services/oAuth2.service.d.ts.map +1 -0
- package/dist/types/services/organization.service.d.ts +43 -0
- package/dist/types/services/organization.service.d.ts.map +1 -0
- package/dist/types/services/project.service.d.ts +43 -0
- package/dist/types/services/project.service.d.ts.map +1 -0
- package/dist/types/services/projectAccessKey.service.d.ts +16 -0
- package/dist/types/services/projectAccessKey.service.d.ts.map +1 -0
- package/dist/types/services/sessionAuth.service.d.ts +148 -0
- package/dist/types/services/sessionAuth.service.d.ts.map +1 -0
- package/dist/types/services/user.service.d.ts +89 -0
- package/dist/types/services/user.service.d.ts.map +1 -0
- package/dist/types/types/Routes.d.ts +7 -0
- package/dist/types/types/Routes.d.ts.map +1 -0
- package/dist/types/types/dictionary.types.d.ts +35 -0
- package/dist/types/types/dictionary.types.d.ts.map +1 -0
- package/dist/types/types/organization.types.d.ts +21 -0
- package/dist/types/types/organization.types.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +40 -0
- package/dist/types/types/project.types.d.ts.map +1 -0
- package/dist/types/types/session.types.d.ts +22 -0
- package/dist/types/types/session.types.d.ts.map +1 -0
- package/dist/types/types/user.types.d.ts +28 -0
- package/dist/types/types/user.types.d.ts.map +1 -0
- package/dist/types/utils/CSRF.d.ts +3 -0
- package/dist/types/utils/CSRF.d.ts.map +1 -0
- package/dist/types/utils/accessControl.d.ts +58 -0
- package/dist/types/utils/accessControl.d.ts.map +1 -0
- package/dist/types/utils/cookies.d.ts +12 -0
- package/dist/types/utils/cookies.d.ts.map +1 -0
- package/dist/types/utils/errors/ErrorHandler.d.ts +32 -0
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -0
- package/dist/types/utils/errors/ErrorsClass.d.ts +26 -0
- package/dist/types/utils/errors/ErrorsClass.d.ts.map +1 -0
- package/dist/types/utils/errors/errorCodes.d.ts +811 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -0
- package/dist/types/utils/errors/index.d.ts +4 -0
- package/dist/types/utils/errors/index.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +23 -0
- package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts +22 -0
- package/dist/types/utils/filtersAndPagination/getFiltersAndPaginationFromBody.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts +31 -0
- package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts +24 -0
- package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts +22 -0
- package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -0
- package/dist/types/utils/httpStatusCodes.d.ts +395 -0
- package/dist/types/utils/httpStatusCodes.d.ts.map +1 -0
- package/dist/types/utils/mapper/dictionary.d.ts +12 -0
- package/dist/types/utils/mapper/dictionary.d.ts.map +1 -0
- package/dist/types/utils/mapper/organization.d.ts +9 -0
- package/dist/types/utils/mapper/organization.d.ts.map +1 -0
- package/dist/types/utils/mapper/project.d.ts +9 -0
- package/dist/types/utils/mapper/project.d.ts.map +1 -0
- package/dist/types/utils/mapper/user.d.ts +14 -0
- package/dist/types/utils/mapper/user.d.ts.map +1 -0
- package/dist/types/utils/mongoDB/connectDB.d.ts +3 -0
- package/dist/types/utils/mongoDB/connectDB.d.ts.map +1 -0
- package/dist/types/utils/oAuth2.d.ts +6 -0
- package/dist/types/utils/oAuth2.d.ts.map +1 -0
- package/dist/types/utils/responseData.d.ts +53 -0
- package/dist/types/utils/responseData.d.ts.map +1 -0
- package/dist/types/utils/validation/validateArray.d.ts +13 -0
- package/dist/types/utils/validation/validateArray.d.ts.map +1 -0
- package/dist/types/utils/validation/validateDictionary.d.ts +12 -0
- package/dist/types/utils/validation/validateDictionary.d.ts.map +1 -0
- package/dist/types/utils/validation/validateEmail.d.ts +10 -0
- package/dist/types/utils/validation/validateEmail.d.ts.map +1 -0
- package/dist/types/utils/validation/validateOrganization.d.ts +15 -0
- package/dist/types/utils/validation/validateOrganization.d.ts.map +1 -0
- package/dist/types/utils/validation/validatePhone.d.ts +10 -0
- package/dist/types/utils/validation/validatePhone.d.ts.map +1 -0
- package/dist/types/utils/validation/validateProject.d.ts +15 -0
- package/dist/types/utils/validation/validateProject.d.ts.map +1 -0
- package/dist/types/utils/validation/validateString.d.ts +10 -0
- package/dist/types/utils/validation/validateString.d.ts.map +1 -0
- package/dist/types/utils/validation/validateUser.d.ts +15 -0
- package/dist/types/utils/validation/validateUser.d.ts.map +1 -0
- package/package.json +115 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validatePhone_exports = {};
|
|
20
|
+
__export(validatePhone_exports, {
|
|
21
|
+
validatePhone: () => validatePhone
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(validatePhone_exports);
|
|
24
|
+
var import_validateString = require('./validateString.cjs');
|
|
25
|
+
const validatePhone = (value, entityName = "Phone", minLength = 6, maxLength = 20) => {
|
|
26
|
+
const errors = (0, import_validateString.validateString)(value, entityName, minLength, maxLength);
|
|
27
|
+
const phoneRegex = /^\+?\(?\d{3}\)?[-\s.]?\d{3}[-\s.]?\d{4,6}$/;
|
|
28
|
+
if (typeof value === "string" && !phoneRegex.test(value)) {
|
|
29
|
+
errors.push(`${entityName} must be a valid phone number.`);
|
|
30
|
+
}
|
|
31
|
+
return errors;
|
|
32
|
+
};
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
validatePhone
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=validatePhone.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/validation/validatePhone.ts"],"sourcesContent":["import { validateString } from './validateString';\n\n/**\n * Validates a email field.\n * @param value The value to validate.\n * @param entityName The name of the entity being validated.\n * @param minLength The minimum length of the string.\n * @param maxLength The maximum length of the string.\n * @returns An array of validation errors.\n */\nexport const validatePhone = (\n value: unknown,\n entityName = 'Phone',\n minLength = 6,\n maxLength = 20\n): string[] => {\n const errors = validateString(value, entityName, minLength, maxLength);\n\n const phoneRegex = /^\\+?\\(?\\d{3}\\)?[-\\s.]?\\d{3}[-\\s.]?\\d{4,6}$/;\n\n if (typeof value === 'string' && !phoneRegex.test(value)) {\n errors.push(`${entityName} must be a valid phone number.`);\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAUxB,MAAM,gBAAgB,CAC3B,OACA,aAAa,SACb,YAAY,GACZ,YAAY,OACC;AACb,QAAM,aAAS,sCAAe,OAAO,YAAY,WAAW,SAAS;AAErE,QAAM,aAAa;AAEnB,MAAI,OAAO,UAAU,YAAY,CAAC,WAAW,KAAK,KAAK,GAAG;AACxD,WAAO,KAAK,GAAG,UAAU,gCAAgC;AAAA,EAC3D;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validateProject_exports = {};
|
|
20
|
+
__export(validateProject_exports, {
|
|
21
|
+
MEMBERS_MIN_LENGTH: () => MEMBERS_MIN_LENGTH,
|
|
22
|
+
NAME_MAX_LENGTH: () => NAME_MAX_LENGTH,
|
|
23
|
+
NAME_MIN_LENGTH: () => NAME_MIN_LENGTH,
|
|
24
|
+
validateProject: () => validateProject
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(validateProject_exports);
|
|
27
|
+
var import_organization = require('./../../services/organization.service.cjs');
|
|
28
|
+
var import_validateArray = require('./validateArray.cjs');
|
|
29
|
+
var import_validateString = require('./validateString.cjs');
|
|
30
|
+
const defaultFieldsToCheck = [
|
|
31
|
+
"name",
|
|
32
|
+
"membersIds",
|
|
33
|
+
"adminsIds",
|
|
34
|
+
"organizationId"
|
|
35
|
+
];
|
|
36
|
+
const NAME_MIN_LENGTH = 4;
|
|
37
|
+
const NAME_MAX_LENGTH = 100;
|
|
38
|
+
const MEMBERS_MIN_LENGTH = 1;
|
|
39
|
+
const validateProject = async (project, fieldsToCheck = defaultFieldsToCheck) => {
|
|
40
|
+
const errors = {};
|
|
41
|
+
const fieldsToValidate = new Set(fieldsToCheck);
|
|
42
|
+
const organization = await (0, import_organization.getOrganizationById)(project.organizationId ?? "");
|
|
43
|
+
for (const field of fieldsToValidate) {
|
|
44
|
+
const value = project[field];
|
|
45
|
+
errors[field] = [];
|
|
46
|
+
if (field === "name") {
|
|
47
|
+
const nameErrors = (0, import_validateString.validateString)(
|
|
48
|
+
value,
|
|
49
|
+
"Name",
|
|
50
|
+
NAME_MIN_LENGTH,
|
|
51
|
+
NAME_MAX_LENGTH
|
|
52
|
+
);
|
|
53
|
+
if (nameErrors.length > 0) {
|
|
54
|
+
errors[field] = nameErrors;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (field === "organizationId") {
|
|
58
|
+
const organizationErrors = [];
|
|
59
|
+
if (typeof value !== "string") {
|
|
60
|
+
organizationErrors.push("Organization id must be a string");
|
|
61
|
+
}
|
|
62
|
+
if (!value) {
|
|
63
|
+
organizationErrors.push("Organization id is required");
|
|
64
|
+
}
|
|
65
|
+
if (!organization) {
|
|
66
|
+
organizationErrors.push("Organization not found");
|
|
67
|
+
}
|
|
68
|
+
if (organizationErrors.length > 0) {
|
|
69
|
+
errors[field] = organizationErrors;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (field === "membersIds" || field === "adminsIds") {
|
|
73
|
+
const membersErrors = (0, import_validateArray.validateArray)(
|
|
74
|
+
value,
|
|
75
|
+
"Members",
|
|
76
|
+
"string",
|
|
77
|
+
(item) => (organization?.membersIds).includes(item),
|
|
78
|
+
MEMBERS_MIN_LENGTH
|
|
79
|
+
);
|
|
80
|
+
if (membersErrors.length > 0) {
|
|
81
|
+
errors[field] = membersErrors;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (errors[field].length === 0) {
|
|
85
|
+
delete errors[field];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return errors;
|
|
89
|
+
};
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
MEMBERS_MIN_LENGTH,
|
|
93
|
+
NAME_MAX_LENGTH,
|
|
94
|
+
NAME_MIN_LENGTH,
|
|
95
|
+
validateProject
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=validateProject.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/validation/validateProject.ts"],"sourcesContent":["/* eslint-disable sonarjs/cognitive-complexity */\nimport { getOrganizationById } from '@services/organization.service';\nimport { validateArray } from './validateArray';\nimport { validateString } from './validateString';\nimport type { Project } from '@/types/project.types';\n\nexport type ProjectFields = (keyof Project)[];\n\nconst defaultFieldsToCheck: ProjectFields = [\n 'name',\n 'membersIds',\n 'adminsIds',\n 'organizationId',\n];\n\ntype FieldsToCheck = (typeof defaultFieldsToCheck)[number];\ntype ValidationErrors = Partial<\n Record<(typeof defaultFieldsToCheck)[number], string[]>\n>;\n\nexport const NAME_MIN_LENGTH = 4;\nexport const NAME_MAX_LENGTH = 100;\n\nexport const MEMBERS_MIN_LENGTH = 1;\n\n/**\n * Validates an project object.\n * @param project The project object to validate.\n * @returns An object containing the validation errors for each field.\n */\nexport const validateProject = async (\n project: Partial<Project>,\n fieldsToCheck = defaultFieldsToCheck\n): Promise<ValidationErrors> => {\n const errors: ValidationErrors = {};\n\n // Define the fields to validate\n const fieldsToValidate = new Set<FieldsToCheck>(fieldsToCheck);\n\n const organization = await getOrganizationById(project.organizationId ?? '');\n\n // Validate each field\n for (const field of fieldsToValidate) {\n const value = project[field];\n\n // Initialize error array for the field\n errors[field] = [];\n\n // Check for name validity\n if (field === 'name') {\n const nameErrors = validateString(\n value,\n 'Name',\n NAME_MIN_LENGTH,\n NAME_MAX_LENGTH\n );\n\n if (nameErrors.length > 0) {\n errors[field] = nameErrors;\n }\n }\n\n if (field === 'organizationId') {\n const organizationErrors: string[] = [];\n\n if (typeof value !== 'string') {\n organizationErrors.push('Organization id must be a string');\n }\n\n if (!value) {\n organizationErrors.push('Organization id is required');\n }\n\n if (!organization) {\n organizationErrors.push('Organization not found');\n }\n\n if (organizationErrors.length > 0) {\n errors[field] = organizationErrors;\n }\n }\n\n if (field === 'membersIds' || field === 'adminsIds') {\n const membersErrors = validateArray<string>(\n value as unknown as string[],\n 'Members',\n 'string',\n (item) =>\n (organization?.membersIds as unknown as string[]).includes(item),\n MEMBERS_MIN_LENGTH\n );\n\n if (membersErrors.length > 0) {\n errors[field] = membersErrors;\n }\n }\n\n // Remove the error field if there are no errors\n if (errors[field].length === 0) {\n delete errors[field];\n }\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAoC;AACpC,2BAA8B;AAC9B,4BAA+B;AAK/B,MAAM,uBAAsC;AAAA,EAC1C;AAA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
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validateString_exports = {};
|
|
20
|
+
__export(validateString_exports, {
|
|
21
|
+
validateString: () => validateString
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(validateString_exports);
|
|
24
|
+
const validateString = (value, entityName, minLength, maxLength) => {
|
|
25
|
+
const errors = [];
|
|
26
|
+
if (typeof value !== "string") {
|
|
27
|
+
errors.push(`${entityName} must be a string.`);
|
|
28
|
+
} else if (minLength && value.length < minLength) {
|
|
29
|
+
errors.push(`${entityName} must be at least ${minLength} characters long.`);
|
|
30
|
+
} else if (maxLength && value.length > maxLength) {
|
|
31
|
+
errors.push(`${entityName} must be at most ${maxLength} characters long.`);
|
|
32
|
+
}
|
|
33
|
+
return errors;
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
validateString
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=validateString.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/validation/validateString.ts"],"sourcesContent":["/**\n * Validates a string field.\n * @param value The value to validate.\n * @param entityName The name of the entity being validated.\n * @param minLength The minimum length of the string.\n * @param maxLength The maximum length of the string.\n * @returns An array of validation errors.\n */\nexport const validateString = (\n value: unknown,\n entityName: string,\n minLength?: number,\n maxLength?: number\n): string[] => {\n const errors: string[] = [];\n\n if (typeof value !== 'string') {\n errors.push(`${entityName} must be a string.`);\n } else if (minLength && value.length < minLength) {\n errors.push(`${entityName} must be at least ${minLength} characters long.`);\n } else if (maxLength && value.length > maxLength) {\n errors.push(`${entityName} must be at most ${maxLength} characters long.`);\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,MAAM,iBAAiB,CAC5B,OACA,YACA,WACA,cACa;AACb,QAAM,SAAmB,CAAC;AAE1B,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,KAAK,GAAG,UAAU,oBAAoB;AAAA,EAC/C,WAAW,aAAa,MAAM,SAAS,WAAW;AAChD,WAAO,KAAK,GAAG,UAAU,qBAAqB,SAAS,mBAAmB;AAAA,EAC5E,WAAW,aAAa,MAAM,SAAS,WAAW;AAChD,WAAO,KAAK,GAAG,UAAU,oBAAoB,SAAS,mBAAmB;AAAA,EAC3E;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var validateUser_exports = {};
|
|
20
|
+
__export(validateUser_exports, {
|
|
21
|
+
NAMES_MAX_LENGTH: () => NAMES_MAX_LENGTH,
|
|
22
|
+
NAMES_MIN_LENGTH: () => NAMES_MIN_LENGTH,
|
|
23
|
+
validateUser: () => validateUser
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(validateUser_exports);
|
|
26
|
+
var import_validateEmail = require('./validateEmail.cjs');
|
|
27
|
+
var import_validatePhone = require('./validatePhone.cjs');
|
|
28
|
+
var import_validateString = require('./validateString.cjs');
|
|
29
|
+
const defaultFieldsToCheck = ["name", "phone", "email", "phone"];
|
|
30
|
+
const NAMES_MIN_LENGTH = 4;
|
|
31
|
+
const NAMES_MAX_LENGTH = 100;
|
|
32
|
+
const validateUser = (project, fieldsToCheck = defaultFieldsToCheck) => {
|
|
33
|
+
const errors = {};
|
|
34
|
+
const fieldsToValidate = new Set(fieldsToCheck);
|
|
35
|
+
for (const field of fieldsToValidate) {
|
|
36
|
+
const value = project[field];
|
|
37
|
+
errors[field] = [];
|
|
38
|
+
if (field === "name") {
|
|
39
|
+
const nameErrors = (0, import_validateString.validateString)(
|
|
40
|
+
value,
|
|
41
|
+
`User ${field}`,
|
|
42
|
+
NAMES_MIN_LENGTH,
|
|
43
|
+
NAMES_MAX_LENGTH
|
|
44
|
+
);
|
|
45
|
+
if (nameErrors.length > 0) {
|
|
46
|
+
errors[field] = nameErrors;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (field === "email") {
|
|
50
|
+
const emailErrors = (0, import_validateEmail.validateEmail)(value, "User Email");
|
|
51
|
+
if (emailErrors.length > 0) {
|
|
52
|
+
errors[field] = emailErrors;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (field === "phone") {
|
|
56
|
+
const phoneErrors = (0, import_validatePhone.validatePhone)(value, "User Phone", 8, 20);
|
|
57
|
+
if (phoneErrors.length > 0) {
|
|
58
|
+
errors[field] = phoneErrors;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (errors[field].length === 0) {
|
|
62
|
+
delete errors[field];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return errors;
|
|
66
|
+
};
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
NAMES_MAX_LENGTH,
|
|
70
|
+
NAMES_MIN_LENGTH,
|
|
71
|
+
validateUser
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=validateUser.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/validation/validateUser.ts"],"sourcesContent":["/* eslint-disable sonarjs/cognitive-complexity */\nimport { validateEmail } from './validateEmail';\nimport { validatePhone } from './validatePhone';\nimport { validateString } from './validateString';\nimport type { User } from '@/types/user.types';\n\nexport type UserFields = (keyof User)[];\n\nconst defaultFieldsToCheck: UserFields = ['name', 'phone', 'email', 'phone'];\n\nexport type FieldsToCheck = (typeof defaultFieldsToCheck)[number];\ntype ValidationErrors = Partial<\n Record<(typeof defaultFieldsToCheck)[number], string[]>\n>;\nexport const NAMES_MIN_LENGTH = 4;\nexport const NAMES_MAX_LENGTH = 100;\n\n/**\n * Validates an user object.\n * @param user The user object to validate.\n * @returns An object containing the validation errors for each field.\n */\nexport const validateUser = (\n project: Partial<User>,\n fieldsToCheck = defaultFieldsToCheck\n): ValidationErrors => {\n const errors: ValidationErrors = {};\n\n // Define the fields to validate\n const fieldsToValidate = new Set<FieldsToCheck>(fieldsToCheck);\n\n // Validate each field\n for (const field of fieldsToValidate) {\n const value = project[field];\n\n // Initialize error array for the field\n errors[field] = [];\n\n // Check for name validity\n if (field === 'name') {\n const nameErrors = validateString(\n value,\n `User ${field}`,\n NAMES_MIN_LENGTH,\n NAMES_MAX_LENGTH\n );\n\n if (nameErrors.length > 0) {\n errors[field] = nameErrors;\n }\n }\n\n // Check for email validity\n if (field === 'email') {\n const emailErrors = validateEmail(value, 'User Email');\n\n if (emailErrors.length > 0) {\n errors[field] = emailErrors;\n }\n }\n\n if (field === 'phone') {\n const phoneErrors = validatePhone(value, 'User Phone', 8, 20);\n\n if (phoneErrors.length > 0) {\n errors[field] = phoneErrors;\n }\n }\n\n // Remove the error field if there are no errors\n if (errors[field].length === 0) {\n delete errors[field];\n }\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,2BAA8B;AAC9B,2BAA8B;AAC9B,4BAA+B;AAK/B,MAAM,uBAAmC,CAAC,QAAQ,SAAS,SAAS,OAAO;AAMpE,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;AAOzB,MAAM,eAAe,CAC1B,SACA,gBAAgB,yBACK;AACrB,QAAM,SAA2B,CAAC;AAGlC,QAAM,mBAAmB,IAAI,IAAmB,aAAa;AAG7D,aAAW,SAAS,kBAAkB;AACpC,UAAM,QAAQ,QAAQ,KAAK;AAG3B,WAAO,KAAK,IAAI,CAAC;AAGjB,QAAI,UAAU,QAAQ;AACpB,YAAM,iBAAa;AAAA,QACjB;AAAA,QACA,QAAQ,KAAK;AAAA,QACb;AAAA,QACA;AAAA,MACF;AAEA,UAAI,WAAW,SAAS,GAAG;AACzB,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,IACF;AAGA,QAAI,UAAU,SAAS;AACrB,YAAM,kBAAc,oCAAc,OAAO,YAAY;AAErD,UAAI,YAAY,SAAS,GAAG;AAC1B,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,IACF;AAEA,QAAI,UAAU,SAAS;AACrB,YAAM,kBAAc,oCAAc,OAAO,cAAc,GAAG,EAAE;AAE5D,UAAI,YAAY,SAAS,GAAG;AAC1B,eAAO,KAAK,IAAI;AAAA,MAClB;AAAA,IACF;AAGA,QAAI,OAAO,KAAK,EAAE,WAAW,GAAG;AAC9B,aAAO,OAAO,KAAK;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { logger } from './../logger/index.mjs';
|
|
2
|
+
import * as dictionaryService from './../services/dictionary.service.mjs';
|
|
3
|
+
import { ErrorHandler } from './../utils/errors/index.mjs';
|
|
4
|
+
import {
|
|
5
|
+
getDictionaryFiltersAndPagination
|
|
6
|
+
} from './../utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs';
|
|
7
|
+
import { mapDictionaryToAPI } from './../utils/mapper/dictionary.mjs';
|
|
8
|
+
import {
|
|
9
|
+
formatPaginatedResponse,
|
|
10
|
+
formatResponse
|
|
11
|
+
} from './../utils/responseData.mjs';
|
|
12
|
+
const getDictionaries = async (req, res, _next) => {
|
|
13
|
+
const { user, project } = res.locals;
|
|
14
|
+
const { filters, pageSize, skip, page, getNumberOfPages } = getDictionaryFiltersAndPagination(req);
|
|
15
|
+
if (!project) {
|
|
16
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!user) {
|
|
20
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const dictionaries = await dictionaryService.findDictionaries(
|
|
25
|
+
filters,
|
|
26
|
+
skip,
|
|
27
|
+
pageSize
|
|
28
|
+
);
|
|
29
|
+
const totalItems = await dictionaryService.countDictionaries(filters);
|
|
30
|
+
const dictionariesAPI = dictionaries.map(
|
|
31
|
+
(el) => mapDictionaryToAPI(el, project._id)
|
|
32
|
+
);
|
|
33
|
+
const responseData = formatPaginatedResponse({
|
|
34
|
+
data: dictionariesAPI,
|
|
35
|
+
page,
|
|
36
|
+
pageSize,
|
|
37
|
+
totalPages: getNumberOfPages(totalItems),
|
|
38
|
+
totalItems
|
|
39
|
+
});
|
|
40
|
+
res.json(responseData);
|
|
41
|
+
return;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const getDictionariesKeys = async (_req, res, _next) => {
|
|
48
|
+
const { project } = res.locals;
|
|
49
|
+
if (!project) {
|
|
50
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const dictionariesKeys = await dictionaryService.getDictionariesKeys(
|
|
55
|
+
project._id
|
|
56
|
+
);
|
|
57
|
+
const responseData = formatResponse({
|
|
58
|
+
data: dictionariesKeys
|
|
59
|
+
});
|
|
60
|
+
res.json(responseData);
|
|
61
|
+
return;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const getDictionaryByKey = async (req, res, _next) => {
|
|
68
|
+
const { project, user } = res.locals;
|
|
69
|
+
const { dictionaryKey } = req.params;
|
|
70
|
+
const { version } = req.query;
|
|
71
|
+
if (!project) {
|
|
72
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!user) {
|
|
76
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const dictionaries = await dictionaryService.getDictionaryByKey(
|
|
81
|
+
dictionaryKey,
|
|
82
|
+
project._id
|
|
83
|
+
);
|
|
84
|
+
if (!dictionaries.projectIds.includes(String(project._id))) {
|
|
85
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
86
|
+
res,
|
|
87
|
+
"DICTIONARY_PROJECT_MISMATCH"
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const apiResult = mapDictionaryToAPI(dictionaries, project._id, version);
|
|
92
|
+
const responseData = formatResponse({
|
|
93
|
+
data: apiResult
|
|
94
|
+
});
|
|
95
|
+
res.json(responseData);
|
|
96
|
+
return;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const addDictionary = async (req, res, _next) => {
|
|
103
|
+
const { project, user } = res.locals;
|
|
104
|
+
const dictionaryData = req.body;
|
|
105
|
+
if (!dictionaryData) {
|
|
106
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!project) {
|
|
110
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!user) {
|
|
114
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!dictionaryData.projectIds.includes(String(project._id))) {
|
|
118
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const dictionary = {
|
|
122
|
+
key: dictionaryData.key,
|
|
123
|
+
title: dictionaryData.title,
|
|
124
|
+
description: dictionaryData.description,
|
|
125
|
+
content: [dictionaryData.content],
|
|
126
|
+
creatorId: user._id,
|
|
127
|
+
filePath: { [String(project._id)]: dictionaryData.filePath ?? "" },
|
|
128
|
+
projectIds: dictionaryData.projectIds ?? [String(project._id)]
|
|
129
|
+
};
|
|
130
|
+
try {
|
|
131
|
+
const newDictionary = await dictionaryService.createDictionary(dictionary);
|
|
132
|
+
const apiResult = mapDictionaryToAPI(newDictionary, project._id);
|
|
133
|
+
const responseData = formatResponse({
|
|
134
|
+
data: apiResult
|
|
135
|
+
});
|
|
136
|
+
res.json(responseData);
|
|
137
|
+
return;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const pushDictionaries = async (req, res, _next) => {
|
|
144
|
+
const { project, user } = res.locals;
|
|
145
|
+
const dictionaryData = req.body.dictionaries;
|
|
146
|
+
const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);
|
|
147
|
+
if (typeof dictionaryData === "object" && Array.isArray(dictionaryData) && dictionaryData.length === 0) {
|
|
148
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARIES_NOT_PROVIDED");
|
|
149
|
+
return;
|
|
150
|
+
} else if (!dictionaryData) {
|
|
151
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (!project) {
|
|
155
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (!user) {
|
|
159
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const { existingDictionariesKey, newDictionariesKey } = await dictionaryService.getExistingDictionaryKey(
|
|
164
|
+
dictionariesKeys,
|
|
165
|
+
project._id
|
|
166
|
+
);
|
|
167
|
+
const existingDictionaries = dictionaryData.filter(
|
|
168
|
+
(dictionary) => existingDictionariesKey.includes(dictionary.key)
|
|
169
|
+
);
|
|
170
|
+
const newDictionaries = dictionaryData.filter(
|
|
171
|
+
(dictionary) => newDictionariesKey.includes(dictionary.key)
|
|
172
|
+
);
|
|
173
|
+
const result = {
|
|
174
|
+
newDictionaries: [],
|
|
175
|
+
updatedDictionaries: [],
|
|
176
|
+
error: []
|
|
177
|
+
};
|
|
178
|
+
for (const dictionaryDataEl of newDictionaries) {
|
|
179
|
+
const dictionary = {
|
|
180
|
+
title: dictionaryDataEl.title,
|
|
181
|
+
description: dictionaryDataEl.description,
|
|
182
|
+
content: [dictionaryDataEl.content],
|
|
183
|
+
projectIds: [String(project._id)],
|
|
184
|
+
creatorId: user._id,
|
|
185
|
+
filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? "" },
|
|
186
|
+
key: dictionaryDataEl.key
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
const newDictionary = await dictionaryService.createDictionary(dictionary);
|
|
190
|
+
result.newDictionaries.push(newDictionary.key);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (existingDictionariesKey.length >= 0) {
|
|
196
|
+
const existingDictionariesDB = await dictionaryService.getDictionariesByKeys(
|
|
197
|
+
existingDictionariesKey,
|
|
198
|
+
project._id
|
|
199
|
+
);
|
|
200
|
+
for (const dictionaryDataEl of existingDictionaries) {
|
|
201
|
+
const existingDictionaryDB = existingDictionariesDB.find(
|
|
202
|
+
(dictionaryDB) => dictionaryDB.key === dictionaryDataEl.key
|
|
203
|
+
);
|
|
204
|
+
const dictionary = {
|
|
205
|
+
...existingDictionaryDB,
|
|
206
|
+
...dictionaryDataEl,
|
|
207
|
+
content: [
|
|
208
|
+
...existingDictionaryDB.content ?? [],
|
|
209
|
+
dictionaryDataEl.content
|
|
210
|
+
],
|
|
211
|
+
projectIds: [String(project._id)],
|
|
212
|
+
creatorId: user._id,
|
|
213
|
+
filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? "" },
|
|
214
|
+
key: dictionaryDataEl.key
|
|
215
|
+
};
|
|
216
|
+
try {
|
|
217
|
+
const newDictionary = await dictionaryService.updateDictionaryByKey(
|
|
218
|
+
dictionaryDataEl.key,
|
|
219
|
+
dictionary,
|
|
220
|
+
project._id
|
|
221
|
+
);
|
|
222
|
+
result.updatedDictionaries.push(newDictionary.key);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const responseData = formatResponse({
|
|
229
|
+
data: result
|
|
230
|
+
});
|
|
231
|
+
res.json(responseData);
|
|
232
|
+
return;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const updateDictionary = async (req, res, _next) => {
|
|
239
|
+
const { project } = res.locals;
|
|
240
|
+
const dictionaryData = req.body;
|
|
241
|
+
if (!dictionaryData) {
|
|
242
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!project) {
|
|
246
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (!dictionaryData.projectIds?.includes(String(project._id))) {
|
|
250
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (typeof dictionaryData._id === "undefined") {
|
|
254
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const updatedDictionary = await dictionaryService.updateDictionaryById(
|
|
259
|
+
dictionaryData._id,
|
|
260
|
+
dictionaryData
|
|
261
|
+
);
|
|
262
|
+
const apiResult = mapDictionaryToAPI(updatedDictionary, project._id);
|
|
263
|
+
const responseData = formatResponse({
|
|
264
|
+
data: apiResult
|
|
265
|
+
});
|
|
266
|
+
res.json(responseData);
|
|
267
|
+
return;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const deleteDictionary = async (req, res, _next) => {
|
|
274
|
+
const { project } = res.locals;
|
|
275
|
+
const { dictionaryId } = req.params;
|
|
276
|
+
if (!dictionaryId) {
|
|
277
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!project) {
|
|
281
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const dictionaryToDelete = await dictionaryService.getDictionaryById(dictionaryId);
|
|
286
|
+
if (!dictionaryToDelete.projectIds.includes(project._id)) {
|
|
287
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
288
|
+
res,
|
|
289
|
+
"DICTIONARY_PROJECT_MISMATCH"
|
|
290
|
+
);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const deletedDictionary = await dictionaryService.deleteDictionaryById(dictionaryId);
|
|
294
|
+
if (!deletedDictionary) {
|
|
295
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_NOT_FOUND", {
|
|
296
|
+
dictionaryId
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);
|
|
301
|
+
const apiResult = mapDictionaryToAPI(deletedDictionary, project._id);
|
|
302
|
+
const responseData = formatResponse({
|
|
303
|
+
data: apiResult
|
|
304
|
+
});
|
|
305
|
+
res.json(responseData);
|
|
306
|
+
return;
|
|
307
|
+
} catch (error) {
|
|
308
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
export {
|
|
313
|
+
addDictionary,
|
|
314
|
+
deleteDictionary,
|
|
315
|
+
getDictionaries,
|
|
316
|
+
getDictionariesKeys,
|
|
317
|
+
getDictionaryByKey,
|
|
318
|
+
pushDictionaries,
|
|
319
|
+
updateDictionary
|
|
320
|
+
};
|
|
321
|
+
//# sourceMappingURL=dictionary.controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/controllers/dictionary.controller.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { type Dictionary as LocalDictionary } from '@intlayer/core';\nimport { logger } from '@logger';\nimport type { ResponseWithInformation } from '@middlewares/sessionAuth.middleware';\nimport * as dictionaryService from '@services/dictionary.service';\nimport { AppError, ErrorHandler } from '@utils/errors';\nimport {\n type DictionaryFiltersParams,\n getDictionaryFiltersAndPagination,\n} from '@utils/filtersAndPagination/getDictionaryFiltersAndPagination';\nimport type { FiltersAndPagination } from '@utils/filtersAndPagination/getFiltersAndPaginationFromBody';\nimport { mapDictionaryToAPI } from '@utils/mapper/dictionary';\nimport {\n formatPaginatedResponse,\n type ResponseData,\n type PaginatedResponse,\n formatResponse,\n} from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport type {\n Dictionary,\n DictionaryAPI,\n DictionaryCreationData,\n DictionaryData,\n} from '@/types/dictionary.types';\n\nexport type GetDictionariesParams =\n FiltersAndPagination<DictionaryFiltersParams>;\nexport type GetDictionariesResult = PaginatedResponse<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaries = async (\n req: Request<GetDictionariesParams>,\n res: ResponseWithInformation<GetDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project } = res.locals;\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(req);\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n try {\n const dictionaries = await dictionaryService.findDictionaries(\n filters,\n skip,\n pageSize\n );\n const totalItems = await dictionaryService.countDictionaries(filters);\n\n const dictionariesAPI = dictionaries.map((el) =>\n mapDictionaryToAPI(el, project._id)\n );\n\n const responseData = formatPaginatedResponse<DictionaryAPI>({\n data: dictionariesAPI,\n page,\n pageSize,\n totalPages: getNumberOfPages(totalItems),\n totalItems,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionariesKeysResult = ResponseData<string[]>;\n\n/**\n * Retrieves a list of dictionaries keys based on filters and pagination.\n */\nexport const getDictionariesKeys = async (\n _req: Request,\n res: ResponseWithInformation<GetDictionariesKeysResult>,\n _next: NextFunction\n) => {\n const { project } = res.locals;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n\n try {\n const dictionariesKeys = await dictionaryService.getDictionariesKeys(\n project._id\n );\n\n const responseData = formatResponse<string[]>({\n data: dictionariesKeys,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type GetDictionaryParams = { dictionaryKey: string };\nexport type GetDictionaryQuery = { version?: number };\nexport type GetDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const getDictionaryByKey = async (\n req: Request<GetDictionaryParams>,\n res: ResponseWithInformation<GetDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user } = res.locals;\n const { dictionaryKey } = req.params;\n const { version } = req.query as GetDictionaryQuery;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n try {\n const dictionaries = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project._id\n );\n\n if (!dictionaries.projectIds.includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const apiResult = mapDictionaryToAPI(dictionaries, project._id, version);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type AddDictionaryBody = DictionaryCreationData;\nexport type AddDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Adds a new dictionary to the database.\n */\nexport const addDictionary = async (\n req: Request<any, any, AddDictionaryBody>,\n res: ResponseWithInformation<AddDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user } = res.locals;\n const dictionaryData = req.body;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n if (!dictionaryData.projectIds.includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n const dictionary: DictionaryData = {\n key: dictionaryData.key,\n title: dictionaryData.title,\n description: dictionaryData.description,\n content: [dictionaryData.content],\n creatorId: user._id,\n filePath: { [String(project._id)]: dictionaryData.filePath ?? '' },\n projectIds: dictionaryData.projectIds ?? [String(project._id)],\n };\n\n try {\n const newDictionary = await dictionaryService.createDictionary(dictionary);\n\n const apiResult = mapDictionaryToAPI(newDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type PushDictionariesBody = { dictionaries: LocalDictionary[] };\ntype PushDictionariesResultData = {\n newDictionaries: string[];\n updatedDictionaries: string[];\n error: { dictionaryId: string; message: string }[];\n};\nexport type PushDictionariesResult = ResponseData<PushDictionariesResultData>;\n\n/**\n * Check each dictionaries, add the new ones and update the existing ones.\n * @param req - Express request object.\n * @param res - Express response object.\n * @returns Response containing the created dictionary.\n */\nexport const pushDictionaries = async (\n req: Request<any, any, PushDictionariesBody>,\n res: ResponseWithInformation<PushDictionariesResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project, user } = res.locals;\n const dictionaryData = req.body.dictionaries;\n const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);\n\n if (\n typeof dictionaryData === 'object' &&\n Array.isArray(dictionaryData) &&\n dictionaryData.length === 0\n ) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARIES_NOT_PROVIDED');\n return;\n } else if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_FOUND');\n return;\n }\n\n try {\n const { existingDictionariesKey, newDictionariesKey } =\n await dictionaryService.getExistingDictionaryKey(\n dictionariesKeys,\n project._id\n );\n\n const existingDictionaries = dictionaryData.filter((dictionary) =>\n existingDictionariesKey.includes(dictionary.key)\n );\n const newDictionaries = dictionaryData.filter((dictionary) =>\n newDictionariesKey.includes(dictionary.key)\n );\n\n const result: PushDictionariesResultData = {\n newDictionaries: [],\n updatedDictionaries: [],\n error: [],\n };\n\n for (const dictionaryDataEl of newDictionaries) {\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n content: [dictionaryDataEl.content],\n projectIds: [String(project._id)],\n creatorId: user._id,\n filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? '' },\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary =\n await dictionaryService.createDictionary(dictionary);\n result.newDictionaries.push(newDictionary.key);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n }\n }\n\n if (existingDictionariesKey.length >= 0) {\n const existingDictionariesDB =\n await dictionaryService.getDictionariesByKeys(\n existingDictionariesKey,\n project._id\n );\n\n for (const dictionaryDataEl of existingDictionaries) {\n const existingDictionaryDB = existingDictionariesDB.find(\n (dictionaryDB) => dictionaryDB.key === dictionaryDataEl.key\n )!;\n\n const dictionary: DictionaryData = {\n ...existingDictionaryDB,\n ...dictionaryDataEl,\n content: [\n ...(existingDictionaryDB.content ?? []),\n dictionaryDataEl.content,\n ],\n projectIds: [String(project._id)],\n creatorId: user._id,\n filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? '' },\n key: dictionaryDataEl.key,\n };\n\n try {\n const newDictionary = await dictionaryService.updateDictionaryByKey(\n dictionaryDataEl.key,\n dictionary,\n project._id\n );\n result.updatedDictionaries.push(newDictionary.key);\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n }\n }\n }\n\n const responseData = formatResponse<PushDictionariesResultData>({\n data: result,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type UpdateDictionaryBody = Partial<Dictionary>;\nexport type UpdateDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Updates an existing dictionary in the database.\n */\nexport const updateDictionary = async (\n req: Request<any, any, UpdateDictionaryBody>,\n res: ResponseWithInformation<UpdateDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const dictionaryData = req.body;\n\n if (!dictionaryData) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_DATA_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n\n if (!dictionaryData.projectIds?.includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_PROJECT_MISMATCH');\n return;\n }\n\n if (typeof dictionaryData._id === 'undefined') {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n try {\n const updatedDictionary = await dictionaryService.updateDictionaryById(\n dictionaryData._id,\n dictionaryData\n );\n\n const apiResult = mapDictionaryToAPI(updatedDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n\nexport type DeleteDictionaryParam = { dictionaryId: string };\nexport type DeleteDictionaryResult = ResponseData<DictionaryAPI>;\n\n/**\n * Deletes a dictionary from the database by its ID.\n */\nexport const deleteDictionary = async (\n req: Request<DeleteDictionaryParam>,\n res: ResponseWithInformation<DeleteDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { project } = res.locals;\n const { dictionaryId } = req.params as Partial<DeleteDictionaryParam>;\n\n if (!dictionaryId) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_ID_NOT_FOUND');\n return;\n }\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_FOUND');\n return;\n }\n\n try {\n const dictionaryToDelete =\n await dictionaryService.getDictionaryById(dictionaryId);\n\n if (!dictionaryToDelete.projectIds.includes(project._id)) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const deletedDictionary =\n await dictionaryService.deleteDictionaryById(dictionaryId);\n\n if (!deletedDictionary) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_NOT_FOUND', {\n dictionaryId,\n });\n return;\n }\n\n logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);\n\n const apiResult = mapDictionaryToAPI(deletedDictionary, project._id);\n\n const responseData = formatResponse<DictionaryAPI>({\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as AppError);\n return;\n }\n};\n"],"mappings":"AAEA,SAAS,cAAc;AAEvB,YAAY,uBAAuB;AACnC,SAAmB,oBAAoB;AACvC;AAAA,EAEE;AAAA,OACK;AAEP,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AAgBA,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,QAAQ,IAAI,IAAI;AAC9B,QAAM,EAAE,SAAS,UAAU,MAAM,MAAM,iBAAiB,IACtD,kCAAkC,GAAG;AAEvC,MAAI,CAAC,SAAS;AACZ,iBAAa,2BAA2B,KAAK,mBAAmB;AAChE;AAAA,EACF;AACA,MAAI,CAAC,MAAM;AACT,iBAAa,2BAA2B,KAAK,gBAAgB;AAC7D;AAAA,EACF;AAEA,MAAI;AACF,UAAM,eAAe,MAAM,kBAAkB;AAAA,MAC3C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,UAAM,aAAa,MAAM,kBAAkB,kBAAkB,OAAO;AAEpE,UAAM,kBAAkB,aAAa;AAAA,MAAI,CAAC,OACxC,mBAAmB,IAAI,QAAQ,GAAG;AAAA,IACpC;AAEA,UAAM,eAAe,wBAAuC;AAAA,MAC1D,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA,YAAY,iBAAiB,UAAU;AAAA,MACvC;AAAA,IACF,CAAC;AAED,QAAI,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AAE;AAElE,UAAM,YAAY,mBAAmB,mBAAmB,QAAQ,GAAG;AAEnE,UAAM,eAAe,eAA8B;AAAA,MACjD,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,iBAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ErrorHandler } from './../utils/errors/index.mjs';
|
|
2
|
+
import { formatResponse } from './../utils/responseData.mjs';
|
|
3
|
+
import {
|
|
4
|
+
Request as OAuthRequest,
|
|
5
|
+
Response as OAuthResponse
|
|
6
|
+
} from "oauth2-server";
|
|
7
|
+
const getOAuth2Token = async (req, res, _next) => {
|
|
8
|
+
const oauthRequest = new OAuthRequest(req);
|
|
9
|
+
const oauthResponse = new OAuthResponse(res);
|
|
10
|
+
try {
|
|
11
|
+
const token = await req.oauth.token(oauthRequest, oauthResponse);
|
|
12
|
+
const responseData = formatResponse({
|
|
13
|
+
data: token
|
|
14
|
+
});
|
|
15
|
+
res.json(responseData);
|
|
16
|
+
return;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
ErrorHandler.handleAppErrorResponse(res, error);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
getOAuth2Token
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=oAuth2.controller.mjs.map
|