@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.
Files changed (272) hide show
  1. package/dist/cjs/controllers/dictionary.controller.cjs +91 -18
  2. package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
  3. package/dist/cjs/controllers/organization.controller.cjs +140 -12
  4. package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
  5. package/dist/cjs/controllers/project.controller.cjs +181 -31
  6. package/dist/cjs/controllers/project.controller.cjs.map +1 -1
  7. package/dist/cjs/controllers/projectAccessKey.controller.cjs +61 -10
  8. package/dist/cjs/controllers/projectAccessKey.controller.cjs.map +1 -1
  9. package/dist/cjs/controllers/sessionAuth.controller.cjs +291 -62
  10. package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -1
  11. package/dist/cjs/controllers/stripe.controller.cjs +84 -0
  12. package/dist/cjs/controllers/stripe.controller.cjs.map +1 -0
  13. package/dist/cjs/controllers/user.controller.cjs +49 -20
  14. package/dist/cjs/controllers/user.controller.cjs.map +1 -1
  15. package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs +182 -0
  16. package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs.map +1 -0
  17. package/dist/cjs/emails/SubscriptionPaymentError.cjs +182 -0
  18. package/dist/cjs/emails/SubscriptionPaymentError.cjs.map +1 -0
  19. package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs +188 -0
  20. package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs.map +1 -0
  21. package/dist/cjs/export.cjs.map +1 -1
  22. package/dist/cjs/index.cjs +16 -5
  23. package/dist/cjs/index.cjs.map +1 -1
  24. package/dist/cjs/middlewares/oAuth2.middleware.cjs +10 -0
  25. package/dist/cjs/middlewares/oAuth2.middleware.cjs.map +1 -1
  26. package/dist/cjs/middlewares/sessionAuth.middleware.cjs +50 -10
  27. package/dist/cjs/middlewares/sessionAuth.middleware.cjs.map +1 -1
  28. package/dist/cjs/routes/dictionary.routes.cjs +2 -62
  29. package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
  30. package/dist/cjs/routes/organization.routes.cjs +1 -25
  31. package/dist/cjs/routes/organization.routes.cjs.map +1 -1
  32. package/dist/cjs/routes/project.routes.cjs +10 -85
  33. package/dist/cjs/routes/project.routes.cjs.map +1 -1
  34. package/dist/cjs/routes/sessionAuth.routes.cjs +26 -25
  35. package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -1
  36. package/dist/cjs/routes/stripe.routes.cjs +42 -0
  37. package/dist/cjs/routes/stripe.routes.cjs.map +1 -0
  38. package/dist/cjs/routes/user.routes.cjs +6 -27
  39. package/dist/cjs/routes/user.routes.cjs.map +1 -1
  40. package/dist/cjs/schemas/organization.schema.cjs +5 -0
  41. package/dist/cjs/schemas/organization.schema.cjs.map +1 -1
  42. package/dist/cjs/{middlewares/admin.middleware.cjs → schemas/plans.schema.cjs} +32 -20
  43. package/dist/cjs/schemas/plans.schema.cjs.map +1 -0
  44. package/dist/cjs/schemas/project.schema.cjs +14 -1
  45. package/dist/cjs/schemas/project.schema.cjs.map +1 -1
  46. package/dist/cjs/schemas/user.schema.cjs +5 -1
  47. package/dist/cjs/schemas/user.schema.cjs.map +1 -1
  48. package/dist/cjs/services/dictionary.service.cjs.map +1 -1
  49. package/dist/cjs/services/email.service.cjs +113 -43
  50. package/dist/cjs/services/email.service.cjs.map +1 -1
  51. package/dist/cjs/services/oAuth2.service.cjs +16 -8
  52. package/dist/cjs/services/oAuth2.service.cjs.map +1 -1
  53. package/dist/cjs/services/organization.service.cjs +63 -8
  54. package/dist/cjs/services/organization.service.cjs.map +1 -1
  55. package/dist/cjs/services/project.service.cjs +9 -5
  56. package/dist/cjs/services/project.service.cjs.map +1 -1
  57. package/dist/cjs/services/projectAccessKey.service.cjs +42 -10
  58. package/dist/cjs/services/projectAccessKey.service.cjs.map +1 -1
  59. package/dist/cjs/services/sessionAuth.service.cjs +9 -11
  60. package/dist/cjs/services/sessionAuth.service.cjs.map +1 -1
  61. package/dist/cjs/services/subscription.service.cjs +201 -0
  62. package/dist/cjs/services/subscription.service.cjs.map +1 -0
  63. package/dist/cjs/services/user.service.cjs +1 -3
  64. package/dist/cjs/services/user.service.cjs.map +1 -1
  65. package/dist/cjs/types/dictionary.types.cjs.map +1 -1
  66. package/dist/cjs/types/organization.types.cjs.map +1 -1
  67. package/dist/cjs/types/plan.types.cjs +17 -0
  68. package/dist/cjs/types/plan.types.cjs.map +1 -0
  69. package/dist/cjs/types/project.types.cjs.map +1 -1
  70. package/dist/cjs/types/session.types.cjs.map +1 -1
  71. package/dist/cjs/types/user.types.cjs.map +1 -1
  72. package/dist/cjs/utils/errors/ErrorHandler.cjs +29 -9
  73. package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
  74. package/dist/cjs/utils/errors/ErrorsClass.cjs +17 -3
  75. package/dist/cjs/utils/errors/ErrorsClass.cjs.map +1 -1
  76. package/dist/cjs/utils/errors/errorCodes.cjs +321 -9
  77. package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
  78. package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
  79. package/dist/cjs/utils/mapper/project.cjs +19 -3
  80. package/dist/cjs/utils/mapper/project.cjs.map +1 -1
  81. package/dist/cjs/utils/mapper/user.cjs.map +1 -1
  82. package/dist/cjs/utils/plan.cjs +75 -0
  83. package/dist/cjs/utils/plan.cjs.map +1 -0
  84. package/dist/cjs/utils/responseData.cjs +8 -0
  85. package/dist/cjs/utils/responseData.cjs.map +1 -1
  86. package/dist/cjs/webhooks/stripe.webhook.cjs +133 -0
  87. package/dist/cjs/webhooks/stripe.webhook.cjs.map +1 -0
  88. package/dist/esm/controllers/dictionary.controller.mjs +91 -18
  89. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  90. package/dist/esm/controllers/organization.controller.mjs +140 -12
  91. package/dist/esm/controllers/organization.controller.mjs.map +1 -1
  92. package/dist/esm/controllers/project.controller.mjs +181 -31
  93. package/dist/esm/controllers/project.controller.mjs.map +1 -1
  94. package/dist/esm/controllers/projectAccessKey.controller.mjs +61 -10
  95. package/dist/esm/controllers/projectAccessKey.controller.mjs.map +1 -1
  96. package/dist/esm/controllers/sessionAuth.controller.mjs +287 -61
  97. package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -1
  98. package/dist/esm/controllers/stripe.controller.mjs +60 -0
  99. package/dist/esm/controllers/stripe.controller.mjs.map +1 -0
  100. package/dist/esm/controllers/user.controller.mjs +49 -20
  101. package/dist/esm/controllers/user.controller.mjs.map +1 -1
  102. package/dist/esm/emails/SubscriptionPaymentCancellation.mjs +168 -0
  103. package/dist/esm/emails/SubscriptionPaymentCancellation.mjs.map +1 -0
  104. package/dist/esm/emails/SubscriptionPaymentError.mjs +168 -0
  105. package/dist/esm/emails/SubscriptionPaymentError.mjs.map +1 -0
  106. package/dist/esm/emails/SubscriptionPaymentSuccess.mjs +174 -0
  107. package/dist/esm/emails/SubscriptionPaymentSuccess.mjs.map +1 -0
  108. package/dist/esm/export.mjs.map +1 -1
  109. package/dist/esm/index.mjs +19 -7
  110. package/dist/esm/index.mjs.map +1 -1
  111. package/dist/esm/middlewares/oAuth2.middleware.mjs +10 -0
  112. package/dist/esm/middlewares/oAuth2.middleware.mjs.map +1 -1
  113. package/dist/esm/middlewares/sessionAuth.middleware.mjs +49 -9
  114. package/dist/esm/middlewares/sessionAuth.middleware.mjs.map +1 -1
  115. package/dist/esm/routes/dictionary.routes.mjs +2 -62
  116. package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
  117. package/dist/esm/routes/organization.routes.mjs +1 -25
  118. package/dist/esm/routes/organization.routes.mjs.map +1 -1
  119. package/dist/esm/routes/project.routes.mjs +10 -85
  120. package/dist/esm/routes/project.routes.mjs.map +1 -1
  121. package/dist/esm/routes/sessionAuth.routes.mjs +29 -26
  122. package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -1
  123. package/dist/esm/routes/stripe.routes.mjs +17 -0
  124. package/dist/esm/routes/stripe.routes.mjs.map +1 -0
  125. package/dist/esm/routes/user.routes.mjs +6 -27
  126. package/dist/esm/routes/user.routes.mjs.map +1 -1
  127. package/dist/esm/schemas/organization.schema.mjs +5 -0
  128. package/dist/esm/schemas/organization.schema.mjs.map +1 -1
  129. package/dist/esm/schemas/plans.schema.mjs +32 -0
  130. package/dist/esm/schemas/plans.schema.mjs.map +1 -0
  131. package/dist/esm/schemas/project.schema.mjs +13 -1
  132. package/dist/esm/schemas/project.schema.mjs.map +1 -1
  133. package/dist/esm/schemas/user.schema.mjs +5 -1
  134. package/dist/esm/schemas/user.schema.mjs.map +1 -1
  135. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  136. package/dist/esm/services/email.service.mjs +125 -43
  137. package/dist/esm/services/email.service.mjs.map +1 -1
  138. package/dist/esm/services/oAuth2.service.mjs +16 -8
  139. package/dist/esm/services/oAuth2.service.mjs.map +1 -1
  140. package/dist/esm/services/organization.service.mjs +58 -7
  141. package/dist/esm/services/organization.service.mjs.map +1 -1
  142. package/dist/esm/services/project.service.mjs +9 -5
  143. package/dist/esm/services/project.service.mjs.map +1 -1
  144. package/dist/esm/services/projectAccessKey.service.mjs +42 -10
  145. package/dist/esm/services/projectAccessKey.service.mjs.map +1 -1
  146. package/dist/esm/services/sessionAuth.service.mjs +9 -10
  147. package/dist/esm/services/sessionAuth.service.mjs.map +1 -1
  148. package/dist/esm/services/subscription.service.mjs +178 -0
  149. package/dist/esm/services/subscription.service.mjs.map +1 -0
  150. package/dist/esm/services/user.service.mjs +1 -3
  151. package/dist/esm/services/user.service.mjs.map +1 -1
  152. package/dist/esm/types/plan.types.mjs +1 -0
  153. package/dist/esm/types/plan.types.mjs.map +1 -0
  154. package/dist/esm/utils/errors/ErrorHandler.mjs +29 -9
  155. package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
  156. package/dist/esm/utils/errors/ErrorsClass.mjs +17 -3
  157. package/dist/esm/utils/errors/ErrorsClass.mjs.map +1 -1
  158. package/dist/esm/utils/errors/errorCodes.mjs +321 -9
  159. package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
  160. package/dist/esm/utils/mapper/organization.mjs.map +1 -1
  161. package/dist/esm/utils/mapper/project.mjs +17 -2
  162. package/dist/esm/utils/mapper/project.mjs.map +1 -1
  163. package/dist/esm/utils/mapper/user.mjs.map +1 -1
  164. package/dist/esm/utils/plan.mjs +50 -0
  165. package/dist/esm/utils/plan.mjs.map +1 -0
  166. package/dist/esm/utils/responseData.mjs +8 -0
  167. package/dist/esm/utils/responseData.mjs.map +1 -1
  168. package/dist/esm/webhooks/stripe.webhook.mjs +113 -0
  169. package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -0
  170. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  171. package/dist/types/controllers/organization.controller.d.ts.map +1 -1
  172. package/dist/types/controllers/project.controller.d.ts +9 -7
  173. package/dist/types/controllers/project.controller.d.ts.map +1 -1
  174. package/dist/types/controllers/projectAccessKey.controller.d.ts.map +1 -1
  175. package/dist/types/controllers/sessionAuth.controller.d.ts +28 -9
  176. package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -1
  177. package/dist/types/controllers/stripe.controller.d.ts +17 -0
  178. package/dist/types/controllers/stripe.controller.d.ts.map +1 -0
  179. package/dist/types/controllers/user.controller.d.ts.map +1 -1
  180. package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +20 -0
  181. package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -0
  182. package/dist/types/emails/SubscriptionPaymentError.d.ts +20 -0
  183. package/dist/types/emails/SubscriptionPaymentError.d.ts.map +1 -0
  184. package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +20 -0
  185. package/dist/types/emails/SubscriptionPaymentSuccess.d.ts.map +1 -0
  186. package/dist/types/export.d.ts +2 -0
  187. package/dist/types/export.d.ts.map +1 -1
  188. package/dist/types/index.d.ts.map +1 -1
  189. package/dist/types/middlewares/oAuth2.middleware.d.ts.map +1 -1
  190. package/dist/types/middlewares/sessionAuth.middleware.d.ts +13 -7
  191. package/dist/types/middlewares/sessionAuth.middleware.d.ts.map +1 -1
  192. package/dist/types/models/dictionary.model.d.ts +1 -1
  193. package/dist/types/models/oAuth2.model.d.ts +1 -1
  194. package/dist/types/models/organization.model.d.ts +2 -1
  195. package/dist/types/models/organization.model.d.ts.map +1 -1
  196. package/dist/types/models/plan.moddel.d.ts +11 -0
  197. package/dist/types/models/plan.moddel.d.ts.map +1 -0
  198. package/dist/types/models/project.model.d.ts +1 -1
  199. package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
  200. package/dist/types/routes/organization.routes.d.ts.map +1 -1
  201. package/dist/types/routes/project.routes.d.ts.map +1 -1
  202. package/dist/types/routes/sessionAuth.routes.d.ts +15 -2
  203. package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -1
  204. package/dist/types/routes/stripe.routes.d.ts +10 -0
  205. package/dist/types/routes/stripe.routes.d.ts.map +1 -0
  206. package/dist/types/routes/user.routes.d.ts.map +1 -1
  207. package/dist/types/schemas/dictionary.schema.d.ts +2 -2
  208. package/dist/types/schemas/oAuth2.schema.d.ts +2 -2
  209. package/dist/types/schemas/organization.schema.d.ts +3 -2
  210. package/dist/types/schemas/organization.schema.d.ts.map +1 -1
  211. package/dist/types/schemas/plans.schema.d.ts +16 -0
  212. package/dist/types/schemas/plans.schema.d.ts.map +1 -0
  213. package/dist/types/schemas/project.schema.d.ts +12 -3
  214. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  215. package/dist/types/schemas/user.schema.d.ts +2 -2
  216. package/dist/types/schemas/user.schema.d.ts.map +1 -1
  217. package/dist/types/services/dictionary.service.d.ts +9 -9
  218. package/dist/types/services/dictionary.service.d.ts.map +1 -1
  219. package/dist/types/services/email.service.d.ts +33 -4
  220. package/dist/types/services/email.service.d.ts.map +1 -1
  221. package/dist/types/services/oAuth2.service.d.ts +7 -5
  222. package/dist/types/services/oAuth2.service.d.ts.map +1 -1
  223. package/dist/types/services/organization.service.d.ts +27 -6
  224. package/dist/types/services/organization.service.d.ts.map +1 -1
  225. package/dist/types/services/plans.service.d.ts +35 -0
  226. package/dist/types/services/plans.service.d.ts.map +1 -0
  227. package/dist/types/services/project.service.d.ts +6 -6
  228. package/dist/types/services/project.service.d.ts.map +1 -1
  229. package/dist/types/services/projectAccessKey.service.d.ts +4 -4
  230. package/dist/types/services/projectAccessKey.service.d.ts.map +1 -1
  231. package/dist/types/services/sessionAuth.service.d.ts +9 -16
  232. package/dist/types/services/sessionAuth.service.d.ts.map +1 -1
  233. package/dist/types/services/subscription.service.d.ts +22 -0
  234. package/dist/types/services/subscription.service.d.ts.map +1 -0
  235. package/dist/types/services/user.service.d.ts +11 -19
  236. package/dist/types/services/user.service.d.ts.map +1 -1
  237. package/dist/types/types/dictionary.types.d.ts +2 -2
  238. package/dist/types/types/dictionary.types.d.ts.map +1 -1
  239. package/dist/types/types/organization.types.d.ts +4 -2
  240. package/dist/types/types/organization.types.d.ts.map +1 -1
  241. package/dist/types/types/plan.types.d.ts +18 -0
  242. package/dist/types/types/plan.types.d.ts.map +1 -0
  243. package/dist/types/types/project.types.d.ts +13 -2
  244. package/dist/types/types/project.types.d.ts.map +1 -1
  245. package/dist/types/types/session.types.d.ts +6 -6
  246. package/dist/types/types/session.types.d.ts.map +1 -1
  247. package/dist/types/types/user.types.d.ts +2 -1
  248. package/dist/types/types/user.types.d.ts.map +1 -1
  249. package/dist/types/utils/errors/ErrorHandler.d.ts +5 -3
  250. package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
  251. package/dist/types/utils/errors/ErrorsClass.d.ts +4 -1
  252. package/dist/types/utils/errors/ErrorsClass.d.ts.map +1 -1
  253. package/dist/types/utils/errors/errorCodes.d.ts +313 -1
  254. package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
  255. package/dist/types/utils/mapper/organization.d.ts +1 -1
  256. package/dist/types/utils/mapper/organization.d.ts.map +1 -1
  257. package/dist/types/utils/mapper/project.d.ts +10 -1
  258. package/dist/types/utils/mapper/project.d.ts.map +1 -1
  259. package/dist/types/utils/mapper/user.d.ts +1 -1
  260. package/dist/types/utils/mapper/user.d.ts.map +1 -1
  261. package/dist/types/utils/plan.d.ts +17 -0
  262. package/dist/types/utils/plan.d.ts.map +1 -0
  263. package/dist/types/utils/responseData.d.ts +13 -2
  264. package/dist/types/utils/responseData.d.ts.map +1 -1
  265. package/dist/types/webhooks/stripe.d.ts +3 -0
  266. package/dist/types/webhooks/stripe.d.ts.map +1 -0
  267. package/dist/types/webhooks/stripe.webhook.d.ts +3 -0
  268. package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -0
  269. package/package.json +27 -24
  270. package/dist/cjs/middlewares/admin.middleware.cjs.map +0 -1
  271. package/dist/esm/middlewares/admin.middleware.mjs +0 -20
  272. package/dist/esm/middlewares/admin.middleware.mjs.map +0 -1
@@ -43,15 +43,20 @@ var import_errors = require('./../utils/errors/index.cjs');
43
43
  var import_getDictionaryFiltersAndPagination = require('./../utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs');
44
44
  var import_dictionary = require('./../utils/mapper/dictionary.cjs');
45
45
  var import_responseData = require('./../utils/responseData.cjs');
46
+ var import_express_intlayer = require("express-intlayer");
46
47
  const getDictionaries = async (req, res, _next) => {
47
- const { user, project } = res.locals;
48
+ const { user, project, dictionaryRights } = res.locals;
48
49
  const { filters, pageSize, skip, page, getNumberOfPages } = (0, import_getDictionaryFiltersAndPagination.getDictionaryFiltersAndPagination)(req);
49
50
  if (!project) {
50
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
51
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
51
52
  return;
52
53
  }
53
54
  if (!user) {
54
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
55
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
56
+ return;
57
+ }
58
+ if (!dictionaryRights?.read) {
59
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
55
60
  return;
56
61
  }
57
62
  try {
@@ -79,9 +84,13 @@ const getDictionaries = async (req, res, _next) => {
79
84
  }
80
85
  };
81
86
  const getDictionariesKeys = async (_req, res, _next) => {
82
- const { project } = res.locals;
87
+ const { project, dictionaryRights } = res.locals;
83
88
  if (!project) {
84
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
89
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
90
+ return;
91
+ }
92
+ if (!dictionaryRights?.read) {
93
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
85
94
  return;
86
95
  }
87
96
  try {
@@ -99,15 +108,19 @@ const getDictionariesKeys = async (_req, res, _next) => {
99
108
  }
100
109
  };
101
110
  const getDictionaryByKey = async (req, res, _next) => {
102
- const { project, user } = res.locals;
111
+ const { project, user, dictionaryRights } = res.locals;
103
112
  const { dictionaryKey } = req.params;
104
113
  const { version } = req.query;
105
114
  if (!project) {
106
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
115
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
107
116
  return;
108
117
  }
109
118
  if (!user) {
110
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
119
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
120
+ return;
121
+ }
122
+ if (!dictionaryRights?.read) {
123
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_READ");
111
124
  return;
112
125
  }
113
126
  try {
@@ -134,24 +147,28 @@ const getDictionaryByKey = async (req, res, _next) => {
134
147
  }
135
148
  };
136
149
  const addDictionary = async (req, res, _next) => {
137
- const { project, user } = res.locals;
150
+ const { project, user, dictionaryRights } = res.locals;
138
151
  const dictionaryData = req.body;
139
152
  if (!dictionaryData) {
140
153
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
141
154
  return;
142
155
  }
143
156
  if (!project) {
144
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
157
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
145
158
  return;
146
159
  }
147
160
  if (!user) {
148
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
161
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
149
162
  return;
150
163
  }
151
164
  if (!dictionaryData.projectIds.includes(String(project._id))) {
152
165
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
153
166
  return;
154
167
  }
168
+ if (!dictionaryRights?.admin) {
169
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
170
+ return;
171
+ }
155
172
  const dictionary = {
156
173
  key: dictionaryData.key,
157
174
  title: dictionaryData.title,
@@ -165,6 +182,16 @@ const addDictionary = async (req, res, _next) => {
165
182
  const newDictionary = await dictionaryService.createDictionary(dictionary);
166
183
  const apiResult = (0, import_dictionary.mapDictionaryToAPI)(newDictionary, project._id);
167
184
  const responseData = (0, import_responseData.formatResponse)({
185
+ message: (0, import_express_intlayer.t)({
186
+ en: "Dictionary created successfully",
187
+ fr: "Dictionnaire cr\xE9\xE9 avec succ\xE8s",
188
+ es: "Diccionario creado con \xE9xito"
189
+ }),
190
+ description: (0, import_express_intlayer.t)({
191
+ en: "Your dictionary has been created successfully",
192
+ fr: "Votre dictionnaire a \xE9t\xE9 cr\xE9\xE9 avec succ\xE8s",
193
+ es: "Su diccionario ha sido creado con \xE9xito"
194
+ }),
168
195
  data: apiResult
169
196
  });
170
197
  res.json(responseData);
@@ -175,7 +202,7 @@ const addDictionary = async (req, res, _next) => {
175
202
  }
176
203
  };
177
204
  const pushDictionaries = async (req, res, _next) => {
178
- const { project, user } = res.locals;
205
+ const { project, user, dictionaryRights } = res.locals;
179
206
  const dictionaryData = req.body.dictionaries;
180
207
  const dictionariesKeys = dictionaryData.map((dictionary) => dictionary.key);
181
208
  if (typeof dictionaryData === "object" && Array.isArray(dictionaryData) && dictionaryData.length === 0) {
@@ -186,11 +213,19 @@ const pushDictionaries = async (req, res, _next) => {
186
213
  return;
187
214
  }
188
215
  if (!project) {
189
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
216
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
190
217
  return;
191
218
  }
192
219
  if (!user) {
193
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
220
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
221
+ return;
222
+ }
223
+ if (!dictionaryRights?.write) {
224
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
225
+ return;
226
+ }
227
+ if (!dictionaryRights?.admin) {
228
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
194
229
  return;
195
230
  }
196
231
  try {
@@ -260,6 +295,16 @@ const pushDictionaries = async (req, res, _next) => {
260
295
  }
261
296
  }
262
297
  const responseData = (0, import_responseData.formatResponse)({
298
+ message: (0, import_express_intlayer.t)({
299
+ en: "Dictionaries updated successfully",
300
+ fr: "Dictionnaires mis \xE0 jour avec succ\xE8s",
301
+ es: "Diccionarios actualizados con \xE9xito"
302
+ }),
303
+ description: (0, import_express_intlayer.t)({
304
+ en: "Your dictionaries have been updated successfully",
305
+ fr: "Vos dictionnaires ont \xE9t\xE9 mis \xE0 jour avec succ\xE8s",
306
+ es: "Sus diccionarios han sido actualizados con \xE9xito"
307
+ }),
263
308
  data: result
264
309
  });
265
310
  res.json(responseData);
@@ -270,14 +315,14 @@ const pushDictionaries = async (req, res, _next) => {
270
315
  }
271
316
  };
272
317
  const updateDictionary = async (req, res, _next) => {
273
- const { project } = res.locals;
318
+ const { project, dictionaryRights } = res.locals;
274
319
  const dictionaryData = req.body;
275
320
  if (!dictionaryData) {
276
321
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_DATA_NOT_FOUND");
277
322
  return;
278
323
  }
279
324
  if (!project) {
280
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
325
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
281
326
  return;
282
327
  }
283
328
  if (!dictionaryData.projectIds?.includes(String(project._id))) {
@@ -288,6 +333,10 @@ const updateDictionary = async (req, res, _next) => {
288
333
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
289
334
  return;
290
335
  }
336
+ if (!dictionaryRights?.write) {
337
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_WRITE");
338
+ return;
339
+ }
291
340
  try {
292
341
  const updatedDictionary = await dictionaryService.updateDictionaryById(
293
342
  dictionaryData._id,
@@ -295,6 +344,16 @@ const updateDictionary = async (req, res, _next) => {
295
344
  );
296
345
  const apiResult = (0, import_dictionary.mapDictionaryToAPI)(updatedDictionary, project._id);
297
346
  const responseData = (0, import_responseData.formatResponse)({
347
+ message: (0, import_express_intlayer.t)({
348
+ en: "Dictionary updated successfully",
349
+ fr: "Dictionnaire mis \xE0 jour avec succ\xE8s",
350
+ es: "Diccionario actualizado con \xE9xito"
351
+ }),
352
+ description: (0, import_express_intlayer.t)({
353
+ en: "Your dictionary has been updated successfully",
354
+ fr: "Votre dictionnaire a \xE9t\xE9 mis \xE0 jour avec succ\xE8s",
355
+ es: "Su diccionario ha sido actualizado con \xE9xito"
356
+ }),
298
357
  data: apiResult
299
358
  });
300
359
  res.json(responseData);
@@ -305,14 +364,18 @@ const updateDictionary = async (req, res, _next) => {
305
364
  }
306
365
  };
307
366
  const deleteDictionary = async (req, res, _next) => {
308
- const { project } = res.locals;
367
+ const { project, dictionaryRights } = res.locals;
309
368
  const { dictionaryId } = req.params;
310
369
  if (!dictionaryId) {
311
370
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
312
371
  return;
313
372
  }
314
373
  if (!project) {
315
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_FOUND");
374
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
375
+ return;
376
+ }
377
+ if (!dictionaryRights?.admin) {
378
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_RIGHTS_NOT_ADMIN");
316
379
  return;
317
380
  }
318
381
  try {
@@ -334,6 +397,16 @@ const deleteDictionary = async (req, res, _next) => {
334
397
  import_logger.logger.info(`Dictionary deleted: ${String(deletedDictionary._id)}`);
335
398
  const apiResult = (0, import_dictionary.mapDictionaryToAPI)(deletedDictionary, project._id);
336
399
  const responseData = (0, import_responseData.formatResponse)({
400
+ message: (0, import_express_intlayer.t)({
401
+ en: "Dictionary deleted successfully",
402
+ fr: "Dictionnaire supprim\xE9 avec succ\xE8s",
403
+ es: "Diccionario eliminado con \xE9xito"
404
+ }),
405
+ description: (0, import_express_intlayer.t)({
406
+ en: "Your dictionary has been deleted successfully",
407
+ fr: "Votre dictionnaire a \xE9t\xE9 supprim\xE9 avec succ\xE8s",
408
+ es: "Su diccionario ha sido eliminado con \xE9xito"
409
+ }),
337
410
  data: apiResult
338
411
  });
339
412
  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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuB;AAEvB,wBAAmC;AACnC,oBAAuC;AACvC,+CAGO;AAEP,wBAAmC;AACnC,0BAKO;AAgBA,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM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KACA,UACkB;AAClB,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,aAAa,IAAI,IAAI;AAE7B,MAAI,CAAC,cAAc;AACjB,+BAAa,2BAA2B,KAAK,yBAAyB;AACtE;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,+BAAa,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,iCAAa;AAAA,QACX;AAAA,QACA;AAAA,MACF;AACA;AAAA,IACF;AAEA,UAAM,oBACJ,MAAM,kBAAkB,qBAAqB,YAAY;AAE3D,QAAI,CAAC,mBAAmB;AACtB,iCAAa,2BAA2B,KAAK,wBAAwB;AAAA,QACnE;AAAA,MACF,CAAC;AACD;AAAA,IACF;AAEA,yBAAO,KAAK,uBAAuB,OAAO,kBAAkB,GAAG,CAAC,EAAE;AAElE,UAAM,gBAAY,sCAAmB,mBAAmB,QAAQ,GAAG;AAEnE,UAAM,mBAAe,oCAA8B;AAAA,MACjD,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,+BAAa,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 AppError);\n return;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuB;AAEvB,wBAAmC;AACnC,oBAA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C1D;AAAA,EACF;AACF;","names":[]}
@@ -46,13 +46,22 @@ var sessionAuthService = __toESM(require('./../services/sessionAuth.service.cjs'
46
46
  var userService = __toESM(require('./../services/user.service.cjs'), 1);
47
47
  var import_errors = require('./../utils/errors/index.cjs');
48
48
  var import_getOrganizationFiltersAndPagination = require('./../utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs');
49
+ var import_plan = require('./../utils/plan.cjs');
49
50
  var import_responseData = require('./../utils/responseData.cjs');
51
+ var import_express_intlayer = require("express-intlayer");
50
52
  var organizationService = __toESM(require('./../services/organization.service.cjs'), 1);
51
53
  const getOrganizations = async (req, res, _next) => {
52
- const { user } = res.locals;
54
+ const { user, organizationRights } = res.locals;
53
55
  const { filters, pageSize, skip, page, getNumberOfPages } = (0, import_getOrganizationFiltersAndPagination.getOrganizationFiltersAndPagination)(req);
54
56
  if (!user) {
55
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
57
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
58
+ return;
59
+ }
60
+ if (!organizationRights?.read) {
61
+ import_errors.ErrorHandler.handleGenericErrorResponse(
62
+ res,
63
+ "ORGANIZATION_RIGHTS_NOT_READ"
64
+ );
56
65
  return;
57
66
  }
58
67
  const restrictedFilter = {
@@ -81,7 +90,15 @@ const getOrganizations = async (req, res, _next) => {
81
90
  }
82
91
  };
83
92
  const getOrganization = async (req, res, _next) => {
93
+ const { organizationRights } = res.locals;
84
94
  const { organizationId } = req.params;
95
+ if (!organizationRights?.read) {
96
+ import_errors.ErrorHandler.handleGenericErrorResponse(
97
+ res,
98
+ "ORGANIZATION_RIGHTS_NOT_READ"
99
+ );
100
+ return;
101
+ }
85
102
  if (!organizationId) {
86
103
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_ID_NOT_FOUND");
87
104
  return;
@@ -103,7 +120,7 @@ const addOrganization = async (req, res, _next) => {
103
120
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_DATA_NOT_FOUND");
104
121
  }
105
122
  if (!user) {
106
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
123
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
107
124
  return;
108
125
  }
109
126
  try {
@@ -112,6 +129,16 @@ const addOrganization = async (req, res, _next) => {
112
129
  user._id
113
130
  );
114
131
  const responseData = (0, import_responseData.formatResponse)({
132
+ message: (0, import_express_intlayer.t)({
133
+ en: "Organization created successfully",
134
+ fr: "Organisation cr\xE9\xE9e avec succ\xE8s",
135
+ es: "Organizaci\xF3n creada con \xE9xito"
136
+ }),
137
+ description: (0, import_express_intlayer.t)({
138
+ en: "Your organization has been created successfully",
139
+ fr: "Votre organisation a \xE9t\xE9 cr\xE9\xE9e avec succ\xE8s",
140
+ es: "Su organizaci\xF3n ha sido creada con \xE9xito"
141
+ }),
115
142
  data: newOrganization
116
143
  });
117
144
  res.json(responseData);
@@ -122,14 +149,21 @@ const addOrganization = async (req, res, _next) => {
122
149
  }
123
150
  };
124
151
  const updateOrganization = async (req, res, _next) => {
125
- const { isOrganizationAdmin, organization } = res.locals;
152
+ const { isOrganizationAdmin, organization, organizationRights } = res.locals;
126
153
  const organizationFields = req.body;
127
154
  if (!organizationFields) {
128
155
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_DATA_NOT_FOUND");
129
156
  return;
130
157
  }
131
158
  if (!organization) {
132
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_FOUND");
159
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
160
+ return;
161
+ }
162
+ if (!organizationRights?.write) {
163
+ import_errors.ErrorHandler.handleGenericErrorResponse(
164
+ res,
165
+ "ORGANIZATION_RIGHTS_NOT_WRITE"
166
+ );
133
167
  return;
134
168
  }
135
169
  if (!isOrganizationAdmin) {
@@ -145,6 +179,16 @@ const updateOrganization = async (req, res, _next) => {
145
179
  organizationFields
146
180
  );
147
181
  const responseData = (0, import_responseData.formatResponse)({
182
+ message: (0, import_express_intlayer.t)({
183
+ en: "Organization updated successfully",
184
+ fr: "Organisation mise \xE0 jour avec succ\xE8s",
185
+ es: "Organizaci\xF3n actualizada con \xE9xito"
186
+ }),
187
+ description: (0, import_express_intlayer.t)({
188
+ en: "Your organization has been updated successfully",
189
+ fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
190
+ es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
191
+ }),
148
192
  data: updatedOrganization
149
193
  });
150
194
  res.json(responseData);
@@ -155,14 +199,14 @@ const updateOrganization = async (req, res, _next) => {
155
199
  }
156
200
  };
157
201
  const addOrganizationMember = async (req, res, _next) => {
158
- const { organization, isOrganizationAdmin, user } = res.locals;
202
+ const { organization, isOrganizationAdmin, user, organizationRights } = res.locals;
159
203
  const { userEmail } = req.body;
160
204
  if (!organization) {
161
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_FOUND");
205
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
162
206
  return;
163
207
  }
164
208
  if (!user) {
165
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_FOUND");
209
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
166
210
  return;
167
211
  }
168
212
  if (!isOrganizationAdmin) {
@@ -172,6 +216,26 @@ const addOrganizationMember = async (req, res, _next) => {
172
216
  );
173
217
  return;
174
218
  }
219
+ if (!organizationRights?.admin) {
220
+ import_errors.ErrorHandler.handleGenericErrorResponse(
221
+ res,
222
+ "ORGANIZATION_RIGHTS_NOT_ADMIN"
223
+ );
224
+ return;
225
+ }
226
+ if (!organization.plan) {
227
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PLAN_NOT_FOUND", {
228
+ organizationId: organization._id
229
+ });
230
+ return;
231
+ }
232
+ const planType = (0, import_plan.getPLanDetails)(organization.plan);
233
+ if (planType.numberOfOrganizationUsers && organization.membersIds.length >= planType.numberOfOrganizationUsers) {
234
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PLAN_USER_LIMIT_REACHED", {
235
+ organizationId: organization._id
236
+ });
237
+ return;
238
+ }
175
239
  try {
176
240
  let newMember = await userService.getUserByEmail(userEmail);
177
241
  if (!newMember) {
@@ -200,6 +264,16 @@ const addOrganizationMember = async (req, res, _next) => {
200
264
  membersIds: [...organization.membersIds, newMember._id]
201
265
  });
202
266
  const responseData = (0, import_responseData.formatResponse)({
267
+ message: (0, import_express_intlayer.t)({
268
+ en: "Organization updated successfully",
269
+ fr: "Organisation mise \xE0 jour avec succ\xE8s",
270
+ es: "Organizaci\xF3n actualizada con \xE9xito"
271
+ }),
272
+ description: (0, import_express_intlayer.t)({
273
+ en: "Your organization has been updated successfully",
274
+ fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
275
+ es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
276
+ }),
203
277
  data: updatedOrganization
204
278
  });
205
279
  res.json(responseData);
@@ -210,10 +284,10 @@ const addOrganizationMember = async (req, res, _next) => {
210
284
  }
211
285
  };
212
286
  const updateOrganizationMembers = async (req, res, _next) => {
213
- const { organization, isOrganizationAdmin } = res.locals;
287
+ const { organization, organizationRights, isOrganizationAdmin } = res.locals;
214
288
  const { membersIds } = req.body;
215
289
  if (!organization) {
216
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_FOUND");
290
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
217
291
  return;
218
292
  }
219
293
  if (!isOrganizationAdmin) {
@@ -223,6 +297,13 @@ const updateOrganizationMembers = async (req, res, _next) => {
223
297
  );
224
298
  return;
225
299
  }
300
+ if (!organizationRights?.write) {
301
+ import_errors.ErrorHandler.handleGenericErrorResponse(
302
+ res,
303
+ "ORGANIZATION_RIGHTS_NOT_WRITE"
304
+ );
305
+ return;
306
+ }
226
307
  if (membersIds?.length === 0) {
227
308
  import_errors.ErrorHandler.handleGenericErrorResponse(
228
309
  res,
@@ -265,6 +346,16 @@ const updateOrganizationMembers = async (req, res, _next) => {
265
346
  adminsIds: formattedAdmin
266
347
  });
267
348
  const responseData = (0, import_responseData.formatResponse)({
349
+ message: (0, import_express_intlayer.t)({
350
+ en: "Organization updated successfully",
351
+ fr: "Organisation mise \xE0 jour avec succ\xE8s",
352
+ es: "Organizaci\xF3n actualizada con \xE9xito"
353
+ }),
354
+ description: (0, import_express_intlayer.t)({
355
+ en: "Your organization has been updated successfully",
356
+ fr: "Votre organisation a \xE9t\xE9 mise \xE0 jour avec succ\xE8s",
357
+ es: "Su organizaci\xF3n ha sido actualizada con \xE9xito"
358
+ }),
268
359
  data: updatedOrganization
269
360
  });
270
361
  res.json(responseData);
@@ -275,9 +366,9 @@ const updateOrganizationMembers = async (req, res, _next) => {
275
366
  }
276
367
  };
277
368
  const deleteOrganization = async (_req, res, _next) => {
278
- const { isOrganizationAdmin, organization } = res.locals;
369
+ const { isOrganizationAdmin, organization, organizationRights } = res.locals;
279
370
  if (!organization) {
280
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_FOUND");
371
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
281
372
  return;
282
373
  }
283
374
  if (!isOrganizationAdmin) {
@@ -287,6 +378,13 @@ const deleteOrganization = async (_req, res, _next) => {
287
378
  );
288
379
  return;
289
380
  }
381
+ if (!organizationRights?.admin) {
382
+ import_errors.ErrorHandler.handleGenericErrorResponse(
383
+ res,
384
+ "ORGANIZATION_RIGHTS_NOT_ADMIN"
385
+ );
386
+ return;
387
+ }
290
388
  try {
291
389
  const deletedOrganization = await organizationService.deleteOrganizationById(organization._id);
292
390
  if (!deletedOrganization) {
@@ -297,6 +395,16 @@ const deleteOrganization = async (_req, res, _next) => {
297
395
  }
298
396
  import_logger.logger.info(`Organization deleted: ${String(deletedOrganization._id)}`);
299
397
  const responseData = (0, import_responseData.formatResponse)({
398
+ message: (0, import_express_intlayer.t)({
399
+ en: "Organization deleted successfully",
400
+ fr: "Organisation supprim\xE9e avec succ\xE8s",
401
+ es: "Organizaci\xF3n eliminada con \xE9xito"
402
+ }),
403
+ description: (0, import_express_intlayer.t)({
404
+ en: "Your organization has been deleted successfully",
405
+ fr: "Votre organisation a \xE9t\xE9 supprim\xE9e avec succ\xE8s",
406
+ es: "Su organizaci\xF3n ha sido eliminada con \xE9xito"
407
+ }),
300
408
  data: deletedOrganization
301
409
  });
302
410
  res.json(responseData);
@@ -316,6 +424,16 @@ const selectOrganization = async (req, res, _next) => {
316
424
  const organization = await organizationService.getOrganizationById(organizationId);
317
425
  sessionAuthService.setOrganizationAuth(res, organization);
318
426
  const responseData = (0, import_responseData.formatResponse)({
427
+ message: (0, import_express_intlayer.t)({
428
+ en: "Organization retrieved successfully",
429
+ fr: "Organisation r\xE9cup\xE9r\xE9e avec succ\xE8s",
430
+ es: "Organizaci\xF3n recuperada con \xE9xito"
431
+ }),
432
+ description: (0, import_express_intlayer.t)({
433
+ en: "Your organization has been retrieved successfully",
434
+ fr: "Votre organisation a \xE9t\xE9 r\xE9cup\xE9r\xE9e avec succ\xE8s",
435
+ es: "Su organizaci\xF3n ha sido recuperada con \xE9xito"
436
+ }),
319
437
  data: organization
320
438
  });
321
439
  res.json(responseData);
@@ -330,6 +448,16 @@ const unselectOrganization = (_req, res, _next) => {
330
448
  sessionAuthService.clearOrganizationAuth(res);
331
449
  sessionAuthService.clearProjectAuth(res);
332
450
  const responseData = (0, import_responseData.formatResponse)({
451
+ message: (0, import_express_intlayer.t)({
452
+ en: "Organization unselected successfully",
453
+ fr: "Organisation d\xE9s\xE9lectionn\xE9e avec succ\xE8s",
454
+ es: "Organizaci\xF3n deseleccionada con \xE9xito"
455
+ }),
456
+ description: (0, import_express_intlayer.t)({
457
+ en: "Your organization has been unselected successfully",
458
+ fr: "Votre organisation a \xE9t\xE9 d\xE9s\xE9lectionn\xE9e avec succ\xE8s",
459
+ es: "Su organizaci\xF3n ha sido deseleccionada con \xE9xito"
460
+ }),
333
461
  data: null
334
462
  });
335
463
  res.json(responseData);