@intlayer/backend 3.0.3 → 3.2.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/dist/cjs/controllers/dictionary.controller.cjs +91 -18
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/organization.controller.cjs +140 -12
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +181 -31
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/projectAccessKey.controller.cjs +61 -10
- package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -1
- package/dist/cjs/controllers/sessionAuth.controller.cjs +291 -62
- package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -1
- package/dist/cjs/controllers/stripe.controller.cjs +84 -0
- package/dist/cjs/controllers/stripe.controller.cjs.map +1 -0
- package/dist/cjs/controllers/user.controller.cjs +49 -20
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs +182 -0
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs.map +1 -0
- package/dist/cjs/emails/SubscriptionPaymentError.cjs +182 -0
- package/dist/cjs/emails/SubscriptionPaymentError.cjs.map +1 -0
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs +188 -0
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs.map +1 -0
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/index.cjs +16 -5
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/oAuth2.middleware.cjs +10 -0
- package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -1
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs +50 -10
- package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -1
- package/dist/cjs/routes/dictionary.routes.cjs +2 -62
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/organization.routes.cjs +1 -25
- package/dist/cjs/routes/organization.routes.cjs.map +1 -1
- package/dist/cjs/routes/project.routes.cjs +10 -85
- package/dist/cjs/routes/project.routes.cjs.map +1 -1
- package/dist/cjs/routes/sessionAuth.routes.cjs +26 -25
- package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -1
- package/dist/cjs/routes/stripe.routes.cjs +42 -0
- package/dist/cjs/routes/stripe.routes.cjs.map +1 -0
- package/dist/cjs/routes/user.routes.cjs +6 -27
- package/dist/cjs/routes/user.routes.cjs.map +1 -1
- package/dist/cjs/schemas/organization.schema.cjs +5 -0
- package/dist/cjs/schemas/organization.schema.cjs.map +1 -1
- package/dist/cjs/{middlewares/admin.middleware.cjs → schemas/plans.schema.cjs} +32 -20
- package/dist/cjs/schemas/plans.schema.cjs.map +1 -0
- package/dist/cjs/schemas/project.schema.cjs +14 -1
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/schemas/user.schema.cjs +5 -1
- package/dist/cjs/schemas/user.schema.cjs.map +1 -1
- package/dist/cjs/services/dictionary.service.cjs.map +1 -1
- package/dist/cjs/services/email.service.cjs +113 -43
- package/dist/cjs/services/email.service.cjs.map +1 -1
- package/dist/cjs/services/oAuth2.service.cjs +16 -8
- package/dist/cjs/services/oAuth2.service.cjs.map +1 -1
- package/dist/cjs/services/organization.service.cjs +63 -8
- package/dist/cjs/services/organization.service.cjs.map +1 -1
- package/dist/cjs/services/project.service.cjs +9 -5
- package/dist/cjs/services/project.service.cjs.map +1 -1
- package/dist/cjs/services/projectAccessKey.service.cjs +42 -10
- package/dist/cjs/services/projectAccessKey.service.cjs.map +1 -1
- package/dist/cjs/services/sessionAuth.service.cjs +9 -11
- package/dist/cjs/services/sessionAuth.service.cjs.map +1 -1
- package/dist/cjs/services/subscription.service.cjs +201 -0
- package/dist/cjs/services/subscription.service.cjs.map +1 -0
- package/dist/cjs/services/user.service.cjs +1 -3
- package/dist/cjs/services/user.service.cjs.map +1 -1
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/types/organization.types.cjs.map +1 -1
- package/dist/cjs/types/plan.types.cjs +17 -0
- package/dist/cjs/types/plan.types.cjs.map +1 -0
- package/dist/cjs/types/project.types.cjs.map +1 -1
- package/dist/cjs/types/session.types.cjs.map +1 -1
- package/dist/cjs/types/user.types.cjs.map +1 -1
- package/dist/cjs/utils/errors/ErrorHandler.cjs +29 -9
- package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
- package/dist/cjs/utils/errors/ErrorsClass.cjs +17 -3
- package/dist/cjs/utils/errors/ErrorsClass.cjs.map +1 -1
- package/dist/cjs/utils/errors/errorCodes.cjs +321 -9
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
- package/dist/cjs/utils/mapper/project.cjs +19 -3
- package/dist/cjs/utils/mapper/project.cjs.map +1 -1
- package/dist/cjs/utils/mapper/user.cjs.map +1 -1
- package/dist/cjs/utils/plan.cjs +75 -0
- package/dist/cjs/utils/plan.cjs.map +1 -0
- package/dist/cjs/utils/responseData.cjs +8 -0
- package/dist/cjs/utils/responseData.cjs.map +1 -1
- package/dist/cjs/webhooks/stripe.webhook.cjs +133 -0
- package/dist/cjs/webhooks/stripe.webhook.cjs.map +1 -0
- package/dist/esm/controllers/dictionary.controller.mjs +91 -18
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/organization.controller.mjs +140 -12
- package/dist/esm/controllers/organization.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +181 -31
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/projectAccessKey.controller.mjs +61 -10
- package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
- package/dist/esm/controllers/sessionAuth.controller.mjs +287 -61
- package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -1
- package/dist/esm/controllers/stripe.controller.mjs +60 -0
- package/dist/esm/controllers/stripe.controller.mjs.map +1 -0
- package/dist/esm/controllers/user.controller.mjs +49 -20
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs +168 -0
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs.map +1 -0
- package/dist/esm/emails/SubscriptionPaymentError.mjs +168 -0
- package/dist/esm/emails/SubscriptionPaymentError.mjs.map +1 -0
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs +174 -0
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs.map +1 -0
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/index.mjs +19 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middlewares/oAuth2.middleware.mjs +10 -0
- package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
- package/dist/esm/middlewares/sessionAuth.middleware.mjs +49 -9
- package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +2 -62
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/organization.routes.mjs +1 -25
- package/dist/esm/routes/organization.routes.mjs.map +1 -1
- package/dist/esm/routes/project.routes.mjs +10 -85
- package/dist/esm/routes/project.routes.mjs.map +1 -1
- package/dist/esm/routes/sessionAuth.routes.mjs +29 -26
- package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -1
- package/dist/esm/routes/stripe.routes.mjs +17 -0
- package/dist/esm/routes/stripe.routes.mjs.map +1 -0
- package/dist/esm/routes/user.routes.mjs +6 -27
- package/dist/esm/routes/user.routes.mjs.map +1 -1
- package/dist/esm/schemas/organization.schema.mjs +5 -0
- package/dist/esm/schemas/organization.schema.mjs.map +1 -1
- package/dist/esm/schemas/plans.schema.mjs +32 -0
- package/dist/esm/schemas/plans.schema.mjs.map +1 -0
- package/dist/esm/schemas/project.schema.mjs +13 -1
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/schemas/user.schema.mjs +5 -1
- package/dist/esm/schemas/user.schema.mjs.map +1 -1
- package/dist/esm/services/dictionary.service.mjs.map +1 -1
- package/dist/esm/services/email.service.mjs +125 -43
- package/dist/esm/services/email.service.mjs.map +1 -1
- package/dist/esm/services/oAuth2.service.mjs +16 -8
- package/dist/esm/services/oAuth2.service.mjs.map +1 -1
- package/dist/esm/services/organization.service.mjs +58 -7
- package/dist/esm/services/organization.service.mjs.map +1 -1
- package/dist/esm/services/project.service.mjs +9 -5
- package/dist/esm/services/project.service.mjs.map +1 -1
- package/dist/esm/services/projectAccessKey.service.mjs +42 -10
- package/dist/esm/services/projectAccessKey.service.mjs.map +1 -1
- package/dist/esm/services/sessionAuth.service.mjs +9 -10
- package/dist/esm/services/sessionAuth.service.mjs.map +1 -1
- package/dist/esm/services/subscription.service.mjs +178 -0
- package/dist/esm/services/subscription.service.mjs.map +1 -0
- package/dist/esm/services/user.service.mjs +1 -3
- package/dist/esm/services/user.service.mjs.map +1 -1
- package/dist/esm/types/plan.types.mjs +1 -0
- package/dist/esm/types/plan.types.mjs.map +1 -0
- package/dist/esm/utils/errors/ErrorHandler.mjs +29 -9
- package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
- package/dist/esm/utils/errors/ErrorsClass.mjs +17 -3
- package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +321 -9
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/mapper/organization.mjs.map +1 -1
- package/dist/esm/utils/mapper/project.mjs +17 -2
- package/dist/esm/utils/mapper/project.mjs.map +1 -1
- package/dist/esm/utils/mapper/user.mjs.map +1 -1
- package/dist/esm/utils/plan.mjs +50 -0
- package/dist/esm/utils/plan.mjs.map +1 -0
- package/dist/esm/utils/responseData.mjs +8 -0
- package/dist/esm/utils/responseData.mjs.map +1 -1
- package/dist/esm/webhooks/stripe.webhook.mjs +113 -0
- package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -0
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/organization.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts +9 -7
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
- package/dist/types/controllers/sessionAuth.controller.d.ts +28 -9
- package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -1
- package/dist/types/controllers/stripe.controller.d.ts +17 -0
- package/dist/types/controllers/stripe.controller.d.ts.map +1 -0
- package/dist/types/controllers/user.controller.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -0
- package/dist/types/emails/SubscriptionPaymentError.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentError.d.ts.map +1 -0
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +20 -0
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts.map +1 -0
- package/dist/types/export.d.ts +2 -0
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
- package/dist/types/middlewares/sessionAuth.middleware.d.ts +13 -7
- package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
- package/dist/types/models/dictionary.model.d.ts +1 -1
- package/dist/types/models/oAuth2.model.d.ts +1 -1
- package/dist/types/models/organization.model.d.ts +2 -1
- package/dist/types/models/organization.model.d.ts.map +1 -1
- package/dist/types/models/plan.moddel.d.ts +11 -0
- package/dist/types/models/plan.moddel.d.ts.map +1 -0
- package/dist/types/models/project.model.d.ts +1 -1
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/organization.routes.d.ts.map +1 -1
- package/dist/types/routes/project.routes.d.ts.map +1 -1
- package/dist/types/routes/sessionAuth.routes.d.ts +15 -2
- package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -1
- package/dist/types/routes/stripe.routes.d.ts +10 -0
- package/dist/types/routes/stripe.routes.d.ts.map +1 -0
- package/dist/types/routes/user.routes.d.ts.map +1 -1
- package/dist/types/schemas/dictionary.schema.d.ts +2 -2
- package/dist/types/schemas/oAuth2.schema.d.ts +2 -2
- package/dist/types/schemas/organization.schema.d.ts +3 -2
- package/dist/types/schemas/organization.schema.d.ts.map +1 -1
- package/dist/types/schemas/plans.schema.d.ts +16 -0
- package/dist/types/schemas/plans.schema.d.ts.map +1 -0
- package/dist/types/schemas/project.schema.d.ts +12 -3
- package/dist/types/schemas/project.schema.d.ts.map +1 -1
- package/dist/types/schemas/user.schema.d.ts +2 -2
- package/dist/types/schemas/user.schema.d.ts.map +1 -1
- package/dist/types/services/dictionary.service.d.ts +9 -9
- package/dist/types/services/dictionary.service.d.ts.map +1 -1
- package/dist/types/services/email.service.d.ts +33 -4
- package/dist/types/services/email.service.d.ts.map +1 -1
- package/dist/types/services/oAuth2.service.d.ts +7 -5
- package/dist/types/services/oAuth2.service.d.ts.map +1 -1
- package/dist/types/services/organization.service.d.ts +27 -6
- package/dist/types/services/organization.service.d.ts.map +1 -1
- package/dist/types/services/plans.service.d.ts +35 -0
- package/dist/types/services/plans.service.d.ts.map +1 -0
- package/dist/types/services/project.service.d.ts +6 -6
- package/dist/types/services/project.service.d.ts.map +1 -1
- package/dist/types/services/projectAccessKey.service.d.ts +4 -4
- package/dist/types/services/projectAccessKey.service.d.ts.map +1 -1
- package/dist/types/services/sessionAuth.service.d.ts +9 -16
- package/dist/types/services/sessionAuth.service.d.ts.map +1 -1
- package/dist/types/services/subscription.service.d.ts +22 -0
- package/dist/types/services/subscription.service.d.ts.map +1 -0
- package/dist/types/services/user.service.d.ts +11 -19
- package/dist/types/services/user.service.d.ts.map +1 -1
- package/dist/types/types/dictionary.types.d.ts +2 -2
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/types/organization.types.d.ts +4 -2
- package/dist/types/types/organization.types.d.ts.map +1 -1
- package/dist/types/types/plan.types.d.ts +18 -0
- package/dist/types/types/plan.types.d.ts.map +1 -0
- package/dist/types/types/project.types.d.ts +13 -2
- package/dist/types/types/project.types.d.ts.map +1 -1
- package/dist/types/types/session.types.d.ts +6 -6
- package/dist/types/types/session.types.d.ts.map +1 -1
- package/dist/types/types/user.types.d.ts +2 -1
- package/dist/types/types/user.types.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorHandler.d.ts +5 -3
- package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
- package/dist/types/utils/errors/ErrorsClass.d.ts +4 -1
- package/dist/types/utils/errors/ErrorsClass.d.ts.map +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +313 -1
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/mapper/organization.d.ts +1 -1
- package/dist/types/utils/mapper/organization.d.ts.map +1 -1
- package/dist/types/utils/mapper/project.d.ts +10 -1
- package/dist/types/utils/mapper/project.d.ts.map +1 -1
- package/dist/types/utils/mapper/user.d.ts +1 -1
- package/dist/types/utils/mapper/user.d.ts.map +1 -1
- package/dist/types/utils/plan.d.ts +17 -0
- package/dist/types/utils/plan.d.ts.map +1 -0
- package/dist/types/utils/responseData.d.ts +13 -2
- package/dist/types/utils/responseData.d.ts.map +1 -1
- package/dist/types/webhooks/stripe.d.ts +3 -0
- package/dist/types/webhooks/stripe.d.ts.map +1 -0
- package/dist/types/webhooks/stripe.webhook.d.ts +3 -0
- package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -0
- package/package.json +27 -24
- package/dist/cjs/middlewares/admin.middleware.cjs.map +0 -1
- package/dist/esm/middlewares/admin.middleware.mjs +0 -20
- package/dist/esm/middlewares/admin.middleware.mjs.map +0 -1
|
@@ -9,15 +9,20 @@ import {
|
|
|
9
9
|
formatPaginatedResponse,
|
|
10
10
|
formatResponse
|
|
11
11
|
} from './../utils/responseData.mjs';
|
|
12
|
+
import { t } from "express-intlayer";
|
|
12
13
|
const getDictionaries = async (req, res, _next) => {
|
|
13
|
-
const { user, project } = res.locals;
|
|
14
|
+
const { user, project, dictionaryRights } = res.locals;
|
|
14
15
|
const { filters, pageSize, skip, page, getNumberOfPages } = getDictionaryFiltersAndPagination(req);
|
|
15
16
|
if (!project) {
|
|
16
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
17
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
if (!user) {
|
|
20
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
21
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!dictionaryRights?.read) {
|
|
25
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
|
|
21
26
|
return;
|
|
22
27
|
}
|
|
23
28
|
try {
|
|
@@ -45,9 +50,13 @@ const getDictionaries = async (req, res, _next) => {
|
|
|
45
50
|
}
|
|
46
51
|
};
|
|
47
52
|
const getDictionariesKeys = async (_req, res, _next) => {
|
|
48
|
-
const { project } = res.locals;
|
|
53
|
+
const { project, dictionaryRights } = res.locals;
|
|
49
54
|
if (!project) {
|
|
50
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
55
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!dictionaryRights?.read) {
|
|
59
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
|
|
51
60
|
return;
|
|
52
61
|
}
|
|
53
62
|
try {
|
|
@@ -65,15 +74,19 @@ const getDictionariesKeys = async (_req, res, _next) => {
|
|
|
65
74
|
}
|
|
66
75
|
};
|
|
67
76
|
const getDictionaryByKey = async (req, res, _next) => {
|
|
68
|
-
const { project, user } = res.locals;
|
|
77
|
+
const { project, user, dictionaryRights } = res.locals;
|
|
69
78
|
const { dictionaryKey } = req.params;
|
|
70
79
|
const { version } = req.query;
|
|
71
80
|
if (!project) {
|
|
72
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
81
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
73
82
|
return;
|
|
74
83
|
}
|
|
75
84
|
if (!user) {
|
|
76
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
85
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!dictionaryRights?.read) {
|
|
89
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
|
|
77
90
|
return;
|
|
78
91
|
}
|
|
79
92
|
try {
|
|
@@ -100,24 +113,28 @@ const getDictionaryByKey = async (req, res, _next) => {
|
|
|
100
113
|
}
|
|
101
114
|
};
|
|
102
115
|
const addDictionary = async (req, res, _next) => {
|
|
103
|
-
const { project, user } = res.locals;
|
|
116
|
+
const { project, user, dictionaryRights } = res.locals;
|
|
104
117
|
const dictionaryData = req.body;
|
|
105
118
|
if (!dictionaryData) {
|
|
106
119
|
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
122
|
if (!project) {
|
|
110
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
123
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
111
124
|
return;
|
|
112
125
|
}
|
|
113
126
|
if (!user) {
|
|
114
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
127
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
115
128
|
return;
|
|
116
129
|
}
|
|
117
130
|
if (!dictionaryData.projectIds.includes(String(project._id))) {
|
|
118
131
|
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
|
|
119
132
|
return;
|
|
120
133
|
}
|
|
134
|
+
if (!dictionaryRights?.admin) {
|
|
135
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
121
138
|
const dictionary = {
|
|
122
139
|
key: dictionaryData.key,
|
|
123
140
|
title: dictionaryData.title,
|
|
@@ -131,6 +148,16 @@ const addDictionary = async (req, res, _next) => {
|
|
|
131
148
|
const newDictionary = await dictionaryService.createDictionary(dictionary);
|
|
132
149
|
const apiResult = mapDictionaryToAPI(newDictionary, project._id);
|
|
133
150
|
const responseData = formatResponse({
|
|
151
|
+
message: t({
|
|
152
|
+
en: "Dictionary created successfully",
|
|
153
|
+
fr: "Dictionnaire cr\xE9\xE9 avec succ\xE8s",
|
|
154
|
+
es: "Diccionario creado con \xE9xito"
|
|
155
|
+
}),
|
|
156
|
+
description: t({
|
|
157
|
+
en: "Your dictionary has been created successfully",
|
|
158
|
+
fr: "Votre dictionnaire a \xE9t\xE9 cr\xE9\xE9 avec succ\xE8s",
|
|
159
|
+
es: "Su diccionario ha sido creado con \xE9xito"
|
|
160
|
+
}),
|
|
134
161
|
data: apiResult
|
|
135
162
|
});
|
|
136
163
|
res.json(responseData);
|
|
@@ -141,7 +168,7 @@ const addDictionary = async (req, res, _next) => {
|
|
|
141
168
|
}
|
|
142
169
|
};
|
|
143
170
|
const pushDictionaries = async (req, res, _next) => {
|
|
144
|
-
const { project, user } = res.locals;
|
|
171
|
+
const { project, user, dictionaryRights } = res.locals;
|
|
145
172
|
const dictionaryData = req.body.dictionaries;
|
|
146
173
|
const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);
|
|
147
174
|
if (typeof dictionaryData === "object" && Array.isArray(dictionaryData) && dictionaryData.length === 0) {
|
|
@@ -152,11 +179,19 @@ const pushDictionaries = async (req, res, _next) => {
|
|
|
152
179
|
return;
|
|
153
180
|
}
|
|
154
181
|
if (!project) {
|
|
155
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
182
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
156
183
|
return;
|
|
157
184
|
}
|
|
158
185
|
if (!user) {
|
|
159
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
186
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!dictionaryRights?.write) {
|
|
190
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!dictionaryRights?.admin) {
|
|
194
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
|
|
160
195
|
return;
|
|
161
196
|
}
|
|
162
197
|
try {
|
|
@@ -226,6 +261,16 @@ const pushDictionaries = async (req, res, _next) => {
|
|
|
226
261
|
}
|
|
227
262
|
}
|
|
228
263
|
const responseData = formatResponse({
|
|
264
|
+
message: t({
|
|
265
|
+
en: "Dictionaries updated successfully",
|
|
266
|
+
fr: "Dictionnaires mis \xE0 jour avec succ\xE8s",
|
|
267
|
+
es: "Diccionarios actualizados con \xE9xito"
|
|
268
|
+
}),
|
|
269
|
+
description: t({
|
|
270
|
+
en: "Your dictionaries have been updated successfully",
|
|
271
|
+
fr: "Vos dictionnaires ont \xE9t\xE9 mis \xE0 jour avec succ\xE8s",
|
|
272
|
+
es: "Sus diccionarios han sido actualizados con \xE9xito"
|
|
273
|
+
}),
|
|
229
274
|
data: result
|
|
230
275
|
});
|
|
231
276
|
res.json(responseData);
|
|
@@ -236,14 +281,14 @@ const pushDictionaries = async (req, res, _next) => {
|
|
|
236
281
|
}
|
|
237
282
|
};
|
|
238
283
|
const updateDictionary = async (req, res, _next) => {
|
|
239
|
-
const { project } = res.locals;
|
|
284
|
+
const { project, dictionaryRights } = res.locals;
|
|
240
285
|
const dictionaryData = req.body;
|
|
241
286
|
if (!dictionaryData) {
|
|
242
287
|
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
|
|
243
288
|
return;
|
|
244
289
|
}
|
|
245
290
|
if (!project) {
|
|
246
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
291
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
247
292
|
return;
|
|
248
293
|
}
|
|
249
294
|
if (!dictionaryData.projectIds?.includes(String(project._id))) {
|
|
@@ -254,6 +299,10 @@ const updateDictionary = async (req, res, _next) => {
|
|
|
254
299
|
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
|
|
255
300
|
return;
|
|
256
301
|
}
|
|
302
|
+
if (!dictionaryRights?.write) {
|
|
303
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
257
306
|
try {
|
|
258
307
|
const updatedDictionary = await dictionaryService.updateDictionaryById(
|
|
259
308
|
dictionaryData._id,
|
|
@@ -261,6 +310,16 @@ const updateDictionary = async (req, res, _next) => {
|
|
|
261
310
|
);
|
|
262
311
|
const apiResult = mapDictionaryToAPI(updatedDictionary, project._id);
|
|
263
312
|
const responseData = formatResponse({
|
|
313
|
+
message: t({
|
|
314
|
+
en: "Dictionary updated successfully",
|
|
315
|
+
fr: "Dictionnaire mis \xE0 jour avec succ\xE8s",
|
|
316
|
+
es: "Diccionario actualizado con \xE9xito"
|
|
317
|
+
}),
|
|
318
|
+
description: t({
|
|
319
|
+
en: "Your dictionary has been updated successfully",
|
|
320
|
+
fr: "Votre dictionnaire a \xE9t\xE9 mis \xE0 jour avec succ\xE8s",
|
|
321
|
+
es: "Su diccionario ha sido actualizado con \xE9xito"
|
|
322
|
+
}),
|
|
264
323
|
data: apiResult
|
|
265
324
|
});
|
|
266
325
|
res.json(responseData);
|
|
@@ -271,14 +330,18 @@ const updateDictionary = async (req, res, _next) => {
|
|
|
271
330
|
}
|
|
272
331
|
};
|
|
273
332
|
const deleteDictionary = async (req, res, _next) => {
|
|
274
|
-
const { project } = res.locals;
|
|
333
|
+
const { project, dictionaryRights } = res.locals;
|
|
275
334
|
const { dictionaryId } = req.params;
|
|
276
335
|
if (!dictionaryId) {
|
|
277
336
|
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
|
|
278
337
|
return;
|
|
279
338
|
}
|
|
280
339
|
if (!project) {
|
|
281
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
340
|
+
ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (!dictionaryRights?.admin) {
|
|
344
|
+
ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
|
|
282
345
|
return;
|
|
283
346
|
}
|
|
284
347
|
try {
|
|
@@ -300,6 +363,16 @@ const deleteDictionary = async (req, res, _next) => {
|
|
|
300
363
|
logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);
|
|
301
364
|
const apiResult = mapDictionaryToAPI(deletedDictionary, project._id);
|
|
302
365
|
const responseData = formatResponse({
|
|
366
|
+
message: t({
|
|
367
|
+
en: "Dictionary deleted successfully",
|
|
368
|
+
fr: "Dictionnaire supprim\xE9 avec succ\xE8s",
|
|
369
|
+
es: "Diccionario eliminado con \xE9xito"
|
|
370
|
+
}),
|
|
371
|
+
description: t({
|
|
372
|
+
en: "Your dictionary has been deleted successfully",
|
|
373
|
+
fr: "Votre dictionnaire a \xE9t\xE9 supprim\xE9 avec succ\xE8s",
|
|
374
|
+
es: "Su diccionario ha sido eliminado con \xE9xito"
|
|
375
|
+
}),
|
|
303
376
|
data: apiResult
|
|
304
377
|
});
|
|
305
378
|
res.json(responseData);
|
|
@@ -1 +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,uBAA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,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,iBAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;AAQO,MAAM,mBAAmB,OAC9B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,aAAa,IAAI,IAAI;AAE7B,MAAI,CAAC,cAAc;AACjB,iBAAa,2BAA2B,KAAK,yBAAyB;AACtE;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,iBAAa,2BAA2B,KAAK,mBAAmB;AAChE;AAAA,EACF;AAEA,MAAI;AACF,UAAM,qBACJ,MAAM,kBAAkB,kBAAkB,YAAY;AAExD,QAAI,CAAC,mBAAmB,WAAW,SAAS,QAAQ,GAAG,GAAG;AACxD,mBAAa;AAAA,QACX;AAAA,QACA;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,oBACJ,MAAM,kBAAkB,qBAAqB,YAAY;AAE3D,QAAI,CAAC,mBAAmB;AACtB,mBAAa,2BAA2B,KAAK,wBAAwB;AAAA,QACnE;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,WAAO,KAAK,uBAAuB,OAAO,kBAAkB,GAAG,CAAC,EAAE;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":[]}
|
|
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 { t } from 'express-intlayer';\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, dictionaryRights } = res.locals;\n const { filters, pageSize, skip, page, getNumberOfPages } =\n getDictionaryFiltersAndPagination(req);\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\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, dictionaryRights } = res.locals;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\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, dictionaryRights } = res.locals;\n const { dictionaryKey } = req.params;\n const { version } = req.query as GetDictionaryQuery;\n\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!dictionaryRights?.read) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_READ');\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, dictionaryRights } = 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_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\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 (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\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 message: t({\n en: 'Dictionary created successfully',\n fr: 'Dictionnaire créé avec succès',\n es: 'Diccionario creado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been created successfully',\n fr: 'Votre dictionnaire a été créé avec succès',\n es: 'Su diccionario ha sido creado con éxito',\n }),\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, dictionaryRights } = 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_DEFINED');\n return;\n }\n\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n\n if (!dictionaryRights?.write) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_WRITE');\n return;\n }\n\n if (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\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 message: t({\n en: 'Dictionaries updated successfully',\n fr: 'Dictionnaires mis à jour avec succès',\n es: 'Diccionarios actualizados con éxito',\n }),\n description: t({\n en: 'Your dictionaries have been updated successfully',\n fr: 'Vos dictionnaires ont été mis à jour avec succès',\n es: 'Sus diccionarios han sido actualizados con éxito',\n }),\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, dictionaryRights } = 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_DEFINED');\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 if (!dictionaryRights?.write) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_WRITE');\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 message: t({\n en: 'Dictionary updated successfully',\n fr: 'Dictionnaire mis à jour avec succès',\n es: 'Diccionario actualizado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been updated successfully',\n fr: 'Votre dictionnaire a été mis à jour avec succès',\n es: 'Su diccionario ha sido actualizado con éxito',\n }),\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, dictionaryRights } = 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_DEFINED');\n return;\n }\n\n if (!dictionaryRights?.admin) {\n ErrorHandler.handleGenericErrorResponse(res, 'DICTIONARY_RIGHTS_NOT_ADMIN');\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 message: t({\n en: 'Dictionary deleted successfully',\n fr: 'Dictionnaire supprimé avec succès',\n es: 'Diccionario eliminado con éxito',\n }),\n description: t({\n en: 'Your dictionary has been deleted successfully',\n fr: 'Votre dictionnaire a été supprimé avec succès',\n es: 'Su diccionario ha sido eliminado con éxito',\n }),\n data: apiResult,\n });\n\n res.json(responseData);\n return;\n } catch (error) {\n ErrorHandler.handleAppErrorResponse(res, error as A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A,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,iBAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -7,16 +7,25 @@ import { ErrorHandler } from './../utils/errors/index.mjs';
|
|
|
7
7
|
import {
|
|
8
8
|
getOrganizationFiltersAndPagination
|
|
9
9
|
} from './../utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs';
|
|
10
|
+
import { getPLanDetails } from './../utils/plan.mjs';
|
|
10
11
|
import {
|
|
11
12
|
formatPaginatedResponse,
|
|
12
13
|
formatResponse
|
|
13
14
|
} from './../utils/responseData.mjs';
|
|
15
|
+
import { t } from "express-intlayer";
|
|
14
16
|
import * as organizationService from './../services/organization.service.mjs';
|
|
15
17
|
const getOrganizations = async (req, res, _next) => {
|
|
16
|
-
const { user } = res.locals;
|
|
18
|
+
const { user, organizationRights } = res.locals;
|
|
17
19
|
const { filters, pageSize, skip, page, getNumberOfPages } = getOrganizationFiltersAndPagination(req);
|
|
18
20
|
if (!user) {
|
|
19
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
21
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (!organizationRights?.read) {
|
|
25
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
26
|
+
res,
|
|
27
|
+
"ORGANIZATION_RIGHTS_NOT_READ"
|
|
28
|
+
);
|
|
20
29
|
return;
|
|
21
30
|
}
|
|
22
31
|
const restrictedFilter = {
|
|
@@ -45,7 +54,15 @@ const getOrganizations = async (req, res, _next) => {
|
|
|
45
54
|
}
|
|
46
55
|
};
|
|
47
56
|
const getOrganization = async (req, res, _next) => {
|
|
57
|
+
const { organizationRights } = res.locals;
|
|
48
58
|
const { organizationId } = req.params;
|
|
59
|
+
if (!organizationRights?.read) {
|
|
60
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
61
|
+
res,
|
|
62
|
+
"ORGANIZATION_RIGHTS_NOT_READ"
|
|
63
|
+
);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
49
66
|
if (!organizationId) {
|
|
50
67
|
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_ID_NOT_FOUND");
|
|
51
68
|
return;
|
|
@@ -67,7 +84,7 @@ const addOrganization = async (req, res, _next) => {
|
|
|
67
84
|
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_DATA_NOT_FOUND");
|
|
68
85
|
}
|
|
69
86
|
if (!user) {
|
|
70
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
87
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
71
88
|
return;
|
|
72
89
|
}
|
|
73
90
|
try {
|
|
@@ -76,6 +93,16 @@ const addOrganization = async (req, res, _next) => {
|
|
|
76
93
|
user._id
|
|
77
94
|
);
|
|
78
95
|
const responseData = formatResponse({
|
|
96
|
+
message: t({
|
|
97
|
+
en: "Organization created successfully",
|
|
98
|
+
fr: "Organisation cr\xE9\xE9e avec succ\xE8s",
|
|
99
|
+
es: "Organizaci\xF3n creada con \xE9xito"
|
|
100
|
+
}),
|
|
101
|
+
description: t({
|
|
102
|
+
en: "Your organization has been created successfully",
|
|
103
|
+
fr: "Votre organisation a \xE9t\xE9 cr\xE9\xE9e avec succ\xE8s",
|
|
104
|
+
es: "Su organizaci\xF3n ha sido creada con \xE9xito"
|
|
105
|
+
}),
|
|
79
106
|
data: newOrganization
|
|
80
107
|
});
|
|
81
108
|
res.json(responseData);
|
|
@@ -86,14 +113,21 @@ const addOrganization = async (req, res, _next) => {
|
|
|
86
113
|
}
|
|
87
114
|
};
|
|
88
115
|
const updateOrganization = async (req, res, _next) => {
|
|
89
|
-
const { isOrganizationAdmin, organization } = res.locals;
|
|
116
|
+
const { isOrganizationAdmin, organization, organizationRights } = res.locals;
|
|
90
117
|
const organizationFields = req.body;
|
|
91
118
|
if (!organizationFields) {
|
|
92
119
|
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_DATA_NOT_FOUND");
|
|
93
120
|
return;
|
|
94
121
|
}
|
|
95
122
|
if (!organization) {
|
|
96
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
123
|
+
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (!organizationRights?.write) {
|
|
127
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
128
|
+
res,
|
|
129
|
+
"ORGANIZATION_RIGHTS_NOT_WRITE"
|
|
130
|
+
);
|
|
97
131
|
return;
|
|
98
132
|
}
|
|
99
133
|
if (!isOrganizationAdmin) {
|
|
@@ -109,6 +143,16 @@ const updateOrganization = async (req, res, _next) => {
|
|
|
109
143
|
organizationFields
|
|
110
144
|
);
|
|
111
145
|
const responseData = formatResponse({
|
|
146
|
+
message: t({
|
|
147
|
+
en: "Organization updated successfully",
|
|
148
|
+
fr: "Organisation mise \xE0 jour avec succ\xE8s",
|
|
149
|
+
es: "Organizaci\xF3n actualizada con \xE9xito"
|
|
150
|
+
}),
|
|
151
|
+
description: t({
|
|
152
|
+
en: "Your organization has been updated successfully",
|
|
153
|
+
fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
|
|
154
|
+
es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
|
|
155
|
+
}),
|
|
112
156
|
data: updatedOrganization
|
|
113
157
|
});
|
|
114
158
|
res.json(responseData);
|
|
@@ -119,14 +163,14 @@ const updateOrganization = async (req, res, _next) => {
|
|
|
119
163
|
}
|
|
120
164
|
};
|
|
121
165
|
const addOrganizationMember = async (req, res, _next) => {
|
|
122
|
-
const { organization, isOrganizationAdmin, user } = res.locals;
|
|
166
|
+
const { organization, isOrganizationAdmin, user, organizationRights } = res.locals;
|
|
123
167
|
const { userEmail } = req.body;
|
|
124
168
|
if (!organization) {
|
|
125
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
169
|
+
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
|
|
126
170
|
return;
|
|
127
171
|
}
|
|
128
172
|
if (!user) {
|
|
129
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
173
|
+
ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
|
|
130
174
|
return;
|
|
131
175
|
}
|
|
132
176
|
if (!isOrganizationAdmin) {
|
|
@@ -136,6 +180,26 @@ const addOrganizationMember = async (req, res, _next) => {
|
|
|
136
180
|
);
|
|
137
181
|
return;
|
|
138
182
|
}
|
|
183
|
+
if (!organizationRights?.admin) {
|
|
184
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
185
|
+
res,
|
|
186
|
+
"ORGANIZATION_RIGHTS_NOT_ADMIN"
|
|
187
|
+
);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!organization.plan) {
|
|
191
|
+
ErrorHandler.handleGenericErrorResponse(res, "PLAN_NOT_FOUND", {
|
|
192
|
+
organizationId: organization._id
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const planType = getPLanDetails(organization.plan);
|
|
197
|
+
if (planType.numberOfOrganizationUsers && organization.membersIds.length >= planType.numberOfOrganizationUsers) {
|
|
198
|
+
ErrorHandler.handleGenericErrorResponse(res, "PLAN_USER_LIMIT_REACHED", {
|
|
199
|
+
organizationId: organization._id
|
|
200
|
+
});
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
139
203
|
try {
|
|
140
204
|
let newMember = await userService.getUserByEmail(userEmail);
|
|
141
205
|
if (!newMember) {
|
|
@@ -164,6 +228,16 @@ const addOrganizationMember = async (req, res, _next) => {
|
|
|
164
228
|
membersIds: [...organization.membersIds, newMember._id]
|
|
165
229
|
});
|
|
166
230
|
const responseData = formatResponse({
|
|
231
|
+
message: t({
|
|
232
|
+
en: "Organization updated successfully",
|
|
233
|
+
fr: "Organisation mise \xE0 jour avec succ\xE8s",
|
|
234
|
+
es: "Organizaci\xF3n actualizada con \xE9xito"
|
|
235
|
+
}),
|
|
236
|
+
description: t({
|
|
237
|
+
en: "Your organization has been updated successfully",
|
|
238
|
+
fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
|
|
239
|
+
es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
|
|
240
|
+
}),
|
|
167
241
|
data: updatedOrganization
|
|
168
242
|
});
|
|
169
243
|
res.json(responseData);
|
|
@@ -174,10 +248,10 @@ const addOrganizationMember = async (req, res, _next) => {
|
|
|
174
248
|
}
|
|
175
249
|
};
|
|
176
250
|
const updateOrganizationMembers = async (req, res, _next) => {
|
|
177
|
-
const { organization, isOrganizationAdmin } = res.locals;
|
|
251
|
+
const { organization, organizationRights, isOrganizationAdmin } = res.locals;
|
|
178
252
|
const { membersIds } = req.body;
|
|
179
253
|
if (!organization) {
|
|
180
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
254
|
+
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
|
|
181
255
|
return;
|
|
182
256
|
}
|
|
183
257
|
if (!isOrganizationAdmin) {
|
|
@@ -187,6 +261,13 @@ const updateOrganizationMembers = async (req, res, _next) => {
|
|
|
187
261
|
);
|
|
188
262
|
return;
|
|
189
263
|
}
|
|
264
|
+
if (!organizationRights?.write) {
|
|
265
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
266
|
+
res,
|
|
267
|
+
"ORGANIZATION_RIGHTS_NOT_WRITE"
|
|
268
|
+
);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
190
271
|
if (membersIds?.length === 0) {
|
|
191
272
|
ErrorHandler.handleGenericErrorResponse(
|
|
192
273
|
res,
|
|
@@ -229,6 +310,16 @@ const updateOrganizationMembers = async (req, res, _next) => {
|
|
|
229
310
|
adminsIds: formattedAdmin
|
|
230
311
|
});
|
|
231
312
|
const responseData = formatResponse({
|
|
313
|
+
message: t({
|
|
314
|
+
en: "Organization updated successfully",
|
|
315
|
+
fr: "Organisation mise \xE0 jour avec succ\xE8s",
|
|
316
|
+
es: "Organizaci\xF3n actualizada con \xE9xito"
|
|
317
|
+
}),
|
|
318
|
+
description: t({
|
|
319
|
+
en: "Your organization has been updated successfully",
|
|
320
|
+
fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
|
|
321
|
+
es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
|
|
322
|
+
}),
|
|
232
323
|
data: updatedOrganization
|
|
233
324
|
});
|
|
234
325
|
res.json(responseData);
|
|
@@ -239,9 +330,9 @@ const updateOrganizationMembers = async (req, res, _next) => {
|
|
|
239
330
|
}
|
|
240
331
|
};
|
|
241
332
|
const deleteOrganization = async (_req, res, _next) => {
|
|
242
|
-
const { isOrganizationAdmin, organization } = res.locals;
|
|
333
|
+
const { isOrganizationAdmin, organization, organizationRights } = res.locals;
|
|
243
334
|
if (!organization) {
|
|
244
|
-
ErrorHandler.handleGenericErrorResponse(res, "
|
|
335
|
+
ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
|
|
245
336
|
return;
|
|
246
337
|
}
|
|
247
338
|
if (!isOrganizationAdmin) {
|
|
@@ -251,6 +342,13 @@ const deleteOrganization = async (_req, res, _next) => {
|
|
|
251
342
|
);
|
|
252
343
|
return;
|
|
253
344
|
}
|
|
345
|
+
if (!organizationRights?.admin) {
|
|
346
|
+
ErrorHandler.handleGenericErrorResponse(
|
|
347
|
+
res,
|
|
348
|
+
"ORGANIZATION_RIGHTS_NOT_ADMIN"
|
|
349
|
+
);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
254
352
|
try {
|
|
255
353
|
const deletedOrganization = await organizationService.deleteOrganizationById(organization._id);
|
|
256
354
|
if (!deletedOrganization) {
|
|
@@ -261,6 +359,16 @@ const deleteOrganization = async (_req, res, _next) => {
|
|
|
261
359
|
}
|
|
262
360
|
logger.info(`Organization deleted: ${String(deletedOrganization._id)}`);
|
|
263
361
|
const responseData = formatResponse({
|
|
362
|
+
message: t({
|
|
363
|
+
en: "Organization deleted successfully",
|
|
364
|
+
fr: "Organisation supprim\xE9e avec succ\xE8s",
|
|
365
|
+
es: "Organizaci\xF3n eliminada con \xE9xito"
|
|
366
|
+
}),
|
|
367
|
+
description: t({
|
|
368
|
+
en: "Your organization has been deleted successfully",
|
|
369
|
+
fr: "Votre organisation a \xE9t\xE9 supprim\xE9e avec succ\xE8s",
|
|
370
|
+
es: "Su organizaci\xF3n ha sido eliminada con \xE9xito"
|
|
371
|
+
}),
|
|
264
372
|
data: deletedOrganization
|
|
265
373
|
});
|
|
266
374
|
res.json(responseData);
|
|
@@ -280,6 +388,16 @@ const selectOrganization = async (req, res, _next) => {
|
|
|
280
388
|
const organization = await organizationService.getOrganizationById(organizationId);
|
|
281
389
|
sessionAuthService.setOrganizationAuth(res, organization);
|
|
282
390
|
const responseData = formatResponse({
|
|
391
|
+
message: t({
|
|
392
|
+
en: "Organization retrieved successfully",
|
|
393
|
+
fr: "Organisation r\xE9cup\xE9r\xE9e avec succ\xE8s",
|
|
394
|
+
es: "Organizaci\xF3n recuperada con \xE9xito"
|
|
395
|
+
}),
|
|
396
|
+
description: t({
|
|
397
|
+
en: "Your organization has been retrieved successfully",
|
|
398
|
+
fr: "Votre organisation a \xE9t\xE9 r\xE9cup\xE9r\xE9e avec succ\xE8s",
|
|
399
|
+
es: "Su organizaci\xF3n ha sido recuperada con \xE9xito"
|
|
400
|
+
}),
|
|
283
401
|
data: organization
|
|
284
402
|
});
|
|
285
403
|
res.json(responseData);
|
|
@@ -294,6 +412,16 @@ const unselectOrganization = (_req, res, _next) => {
|
|
|
294
412
|
sessionAuthService.clearOrganizationAuth(res);
|
|
295
413
|
sessionAuthService.clearProjectAuth(res);
|
|
296
414
|
const responseData = formatResponse({
|
|
415
|
+
message: t({
|
|
416
|
+
en: "Organization unselected successfully",
|
|
417
|
+
fr: "Organisation d\xE9s\xE9lectionn\xE9e avec succ\xE8s",
|
|
418
|
+
es: "Organizaci\xF3n deseleccionada con \xE9xito"
|
|
419
|
+
}),
|
|
420
|
+
description: t({
|
|
421
|
+
en: "Your organization has been unselected successfully",
|
|
422
|
+
fr: "Votre organisation a \xE9t\xE9 d\xE9s\xE9lectionn\xE9e avec succ\xE8s",
|
|
423
|
+
es: "Su organizaci\xF3n ha sido deseleccionada con \xE9xito"
|
|
424
|
+
}),
|
|
297
425
|
data: null
|
|
298
426
|
});
|
|
299
427
|
res.json(responseData);
|