@intlayer/backend 3.5.4 → 3.5.6

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 (256) hide show
  1. package/dist/cjs/controllers/ai.controller.cjs +238 -0
  2. package/dist/cjs/controllers/ai.controller.cjs.map +1 -0
  3. package/dist/cjs/controllers/dictionary.controller.cjs +50 -17
  4. package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
  5. package/dist/cjs/controllers/project.controller.cjs +2 -6
  6. package/dist/cjs/controllers/project.controller.cjs.map +1 -1
  7. package/dist/cjs/controllers/tag.controller.cjs +235 -0
  8. package/dist/cjs/controllers/tag.controller.cjs.map +1 -0
  9. package/dist/cjs/controllers/user.controller.cjs +1 -0
  10. package/dist/cjs/controllers/user.controller.cjs.map +1 -1
  11. package/dist/cjs/export.cjs.map +1 -1
  12. package/dist/cjs/index.cjs +4 -0
  13. package/dist/cjs/index.cjs.map +1 -1
  14. package/dist/cjs/middlewares/request.middleware.cjs +4 -0
  15. package/dist/cjs/middlewares/request.middleware.cjs.map +1 -1
  16. package/dist/cjs/models/tag.model.cjs +31 -0
  17. package/dist/cjs/models/tag.model.cjs.map +1 -0
  18. package/dist/cjs/routes/ai.routes.cjs +69 -0
  19. package/dist/cjs/routes/ai.routes.cjs.map +1 -0
  20. package/dist/cjs/routes/dictionary.routes.cjs +4 -4
  21. package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
  22. package/dist/cjs/routes/tags.routes.cjs +60 -0
  23. package/dist/cjs/routes/tags.routes.cjs.map +1 -0
  24. package/dist/cjs/schemas/dictionary.schema.cjs +31 -6
  25. package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
  26. package/dist/cjs/schemas/project.schema.cjs +5 -0
  27. package/dist/cjs/schemas/project.schema.cjs.map +1 -1
  28. package/dist/cjs/schemas/tag.schema.cjs +64 -0
  29. package/dist/cjs/schemas/tag.schema.cjs.map +1 -0
  30. package/dist/cjs/services/dictionary.service.cjs +139 -27
  31. package/dist/cjs/services/dictionary.service.cjs.map +1 -1
  32. package/dist/cjs/services/project.service.cjs +14 -5
  33. package/dist/cjs/services/project.service.cjs.map +1 -1
  34. package/dist/cjs/services/tag.service.cjs +91 -0
  35. package/dist/cjs/services/tag.service.cjs.map +1 -0
  36. package/dist/cjs/types/dictionary.types.cjs.map +1 -1
  37. package/dist/cjs/types/project.types.cjs.map +1 -1
  38. package/dist/cjs/types/tag.types.cjs +17 -0
  39. package/dist/cjs/types/tag.types.cjs.map +1 -0
  40. package/dist/cjs/utils/auditDictionary/CJS_FORMAT.md +23 -0
  41. package/dist/cjs/utils/auditDictionary/JSON_FORMAT.md +26 -0
  42. package/dist/cjs/utils/auditDictionary/JSX_FORMAT.md +28 -0
  43. package/dist/cjs/utils/auditDictionary/MJS_FORMAT.md +23 -0
  44. package/dist/cjs/utils/auditDictionary/PROMPT.md +151 -0
  45. package/dist/cjs/utils/auditDictionary/TSX_FORMAT.md +28 -0
  46. package/dist/cjs/utils/auditDictionary/TS_FORMAT.md +22 -0
  47. package/dist/cjs/utils/auditDictionary/index.cjs +98 -0
  48. package/dist/cjs/utils/auditDictionary/index.cjs.map +1 -0
  49. package/dist/cjs/utils/auditDictionaryField/PROMPT.md +115 -0
  50. package/dist/cjs/utils/auditDictionaryField/index.cjs +81 -0
  51. package/dist/cjs/utils/auditDictionaryField/index.cjs.map +1 -0
  52. package/dist/cjs/utils/auditDictionaryMetadata/PROMPT.md +76 -0
  53. package/dist/cjs/utils/auditDictionaryMetadata/index.cjs +78 -0
  54. package/dist/cjs/utils/auditDictionaryMetadata/index.cjs.map +1 -0
  55. package/dist/cjs/utils/auditTag/PROMPT.md +34 -0
  56. package/dist/cjs/utils/auditTag/index.cjs +74 -0
  57. package/dist/cjs/utils/auditTag/index.cjs.map +1 -0
  58. package/dist/cjs/utils/ensureArrayQueryFilter.cjs +39 -0
  59. package/dist/cjs/utils/ensureArrayQueryFilter.cjs.map +1 -0
  60. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs +35 -0
  61. package/dist/cjs/utils/ensureMongoDocumentToObject.cjs.map +1 -0
  62. package/dist/cjs/utils/errors/ErrorHandler.cjs +1 -1
  63. package/dist/cjs/utils/errors/ErrorHandler.cjs.map +1 -1
  64. package/dist/cjs/utils/errors/errorCodes.cjs +104 -0
  65. package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
  66. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs +10 -11
  67. package/dist/cjs/utils/filtersAndPagination/getDictionaryFiltersAndPagination.cjs.map +1 -1
  68. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs +6 -10
  69. package/dist/cjs/utils/filtersAndPagination/getOrganizationFiltersAndPagination.cjs.map +1 -1
  70. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs +6 -10
  71. package/dist/cjs/utils/filtersAndPagination/getProjectFiltersAndPagination.cjs.map +1 -1
  72. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs +51 -0
  73. package/dist/cjs/utils/filtersAndPagination/getTagFiltersAndPagination.cjs.map +1 -0
  74. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs +2 -9
  75. package/dist/cjs/utils/filtersAndPagination/getUserFiltersAndPagination.cjs.map +1 -1
  76. package/dist/cjs/utils/mapper/dictionary.cjs +8 -4
  77. package/dist/cjs/utils/mapper/dictionary.cjs.map +1 -1
  78. package/dist/cjs/utils/mapper/organization.cjs +2 -4
  79. package/dist/cjs/utils/mapper/organization.cjs.map +1 -1
  80. package/dist/cjs/utils/mapper/project.cjs +2 -4
  81. package/dist/cjs/utils/mapper/project.cjs.map +1 -1
  82. package/dist/cjs/utils/mapper/tag.cjs +37 -0
  83. package/dist/cjs/utils/mapper/tag.cjs.map +1 -0
  84. package/dist/cjs/utils/mapper/user.cjs +2 -4
  85. package/dist/cjs/utils/mapper/user.cjs.map +1 -1
  86. package/dist/cjs/utils/removeObjectKeys.cjs +35 -0
  87. package/dist/cjs/utils/removeObjectKeys.cjs.map +1 -0
  88. package/dist/cjs/utils/validation/validateProject.cjs +17 -10
  89. package/dist/cjs/utils/validation/validateProject.cjs.map +1 -1
  90. package/dist/cjs/utils/validation/validateTag.cjs +93 -0
  91. package/dist/cjs/utils/validation/validateTag.cjs.map +1 -0
  92. package/dist/esm/controllers/ai.controller.mjs +201 -0
  93. package/dist/esm/controllers/ai.controller.mjs.map +1 -0
  94. package/dist/esm/controllers/dictionary.controller.mjs +50 -17
  95. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  96. package/dist/esm/controllers/project.controller.mjs +2 -6
  97. package/dist/esm/controllers/project.controller.mjs.map +1 -1
  98. package/dist/esm/controllers/tag.controller.mjs +203 -0
  99. package/dist/esm/controllers/tag.controller.mjs.map +1 -0
  100. package/dist/esm/controllers/user.controller.mjs +1 -0
  101. package/dist/esm/controllers/user.controller.mjs.map +1 -1
  102. package/dist/esm/export.mjs.map +1 -1
  103. package/dist/esm/index.mjs +4 -0
  104. package/dist/esm/index.mjs.map +1 -1
  105. package/dist/esm/middlewares/request.middleware.mjs +4 -0
  106. package/dist/esm/middlewares/request.middleware.mjs.map +1 -1
  107. package/dist/esm/models/tag.model.mjs +7 -0
  108. package/dist/esm/models/tag.model.mjs.map +1 -0
  109. package/dist/esm/routes/ai.routes.mjs +49 -0
  110. package/dist/esm/routes/ai.routes.mjs.map +1 -0
  111. package/dist/esm/routes/dictionary.routes.mjs +4 -4
  112. package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
  113. package/dist/esm/routes/tags.routes.mjs +40 -0
  114. package/dist/esm/routes/tags.routes.mjs.map +1 -0
  115. package/dist/esm/schemas/dictionary.schema.mjs +31 -6
  116. package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
  117. package/dist/esm/schemas/project.schema.mjs +5 -0
  118. package/dist/esm/schemas/project.schema.mjs.map +1 -1
  119. package/dist/esm/schemas/tag.schema.mjs +45 -0
  120. package/dist/esm/schemas/tag.schema.mjs.map +1 -0
  121. package/dist/esm/services/dictionary.service.mjs +137 -27
  122. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  123. package/dist/esm/services/project.service.mjs +14 -5
  124. package/dist/esm/services/project.service.mjs.map +1 -1
  125. package/dist/esm/services/tag.service.mjs +61 -0
  126. package/dist/esm/services/tag.service.mjs.map +1 -0
  127. package/dist/esm/types/tag.types.mjs +1 -0
  128. package/dist/esm/types/tag.types.mjs.map +1 -0
  129. package/dist/esm/utils/auditDictionary/CJS_FORMAT.md +23 -0
  130. package/dist/esm/utils/auditDictionary/JSON_FORMAT.md +26 -0
  131. package/dist/esm/utils/auditDictionary/JSX_FORMAT.md +28 -0
  132. package/dist/esm/utils/auditDictionary/MJS_FORMAT.md +23 -0
  133. package/dist/esm/utils/auditDictionary/PROMPT.md +151 -0
  134. package/dist/esm/utils/auditDictionary/TSX_FORMAT.md +28 -0
  135. package/dist/esm/utils/auditDictionary/TS_FORMAT.md +22 -0
  136. package/dist/esm/utils/auditDictionary/index.mjs +73 -0
  137. package/dist/esm/utils/auditDictionary/index.mjs.map +1 -0
  138. package/dist/esm/utils/auditDictionaryField/PROMPT.md +115 -0
  139. package/dist/esm/utils/auditDictionaryField/index.mjs +56 -0
  140. package/dist/esm/utils/auditDictionaryField/index.mjs.map +1 -0
  141. package/dist/esm/utils/auditDictionaryMetadata/PROMPT.md +76 -0
  142. package/dist/esm/utils/auditDictionaryMetadata/index.mjs +53 -0
  143. package/dist/esm/utils/auditDictionaryMetadata/index.mjs.map +1 -0
  144. package/dist/esm/utils/auditTag/PROMPT.md +34 -0
  145. package/dist/esm/utils/auditTag/index.mjs +49 -0
  146. package/dist/esm/utils/auditTag/index.mjs.map +1 -0
  147. package/dist/esm/utils/ensureArrayQueryFilter.mjs +15 -0
  148. package/dist/esm/utils/ensureArrayQueryFilter.mjs.map +1 -0
  149. package/dist/esm/utils/ensureMongoDocumentToObject.mjs +11 -0
  150. package/dist/esm/utils/ensureMongoDocumentToObject.mjs.map +1 -0
  151. package/dist/esm/utils/errors/ErrorHandler.mjs +1 -1
  152. package/dist/esm/utils/errors/ErrorHandler.mjs.map +1 -1
  153. package/dist/esm/utils/errors/errorCodes.mjs +104 -0
  154. package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
  155. package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs +10 -11
  156. package/dist/esm/utils/filtersAndPagination/getDictionaryFiltersAndPagination.mjs.map +1 -1
  157. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs +6 -10
  158. package/dist/esm/utils/filtersAndPagination/getOrganizationFiltersAndPagination.mjs.map +1 -1
  159. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs +6 -10
  160. package/dist/esm/utils/filtersAndPagination/getProjectFiltersAndPagination.mjs.map +1 -1
  161. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs +29 -0
  162. package/dist/esm/utils/filtersAndPagination/getTagFiltersAndPagination.mjs.map +1 -0
  163. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs +2 -9
  164. package/dist/esm/utils/filtersAndPagination/getUserFiltersAndPagination.mjs.map +1 -1
  165. package/dist/esm/utils/mapper/dictionary.mjs +8 -4
  166. package/dist/esm/utils/mapper/dictionary.mjs.map +1 -1
  167. package/dist/esm/utils/mapper/organization.mjs +2 -4
  168. package/dist/esm/utils/mapper/organization.mjs.map +1 -1
  169. package/dist/esm/utils/mapper/project.mjs +2 -4
  170. package/dist/esm/utils/mapper/project.mjs.map +1 -1
  171. package/dist/esm/utils/mapper/tag.mjs +12 -0
  172. package/dist/esm/utils/mapper/tag.mjs.map +1 -0
  173. package/dist/esm/utils/mapper/user.mjs +2 -4
  174. package/dist/esm/utils/mapper/user.mjs.map +1 -1
  175. package/dist/esm/utils/removeObjectKeys.mjs +11 -0
  176. package/dist/esm/utils/removeObjectKeys.mjs.map +1 -0
  177. package/dist/esm/utils/validation/validateProject.mjs +17 -10
  178. package/dist/esm/utils/validation/validateProject.mjs.map +1 -1
  179. package/dist/esm/utils/validation/validateTag.mjs +65 -0
  180. package/dist/esm/utils/validation/validateTag.mjs.map +1 -0
  181. package/dist/types/controllers/ai.controller.d.ts +61 -0
  182. package/dist/types/controllers/ai.controller.d.ts.map +1 -0
  183. package/dist/types/controllers/dictionary.controller.d.ts +6 -3
  184. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  185. package/dist/types/controllers/project.controller.d.ts +2 -4
  186. package/dist/types/controllers/project.controller.d.ts.map +1 -1
  187. package/dist/types/controllers/tag.controller.d.ts +39 -0
  188. package/dist/types/controllers/tag.controller.d.ts.map +1 -0
  189. package/dist/types/controllers/user.controller.d.ts.map +1 -1
  190. package/dist/types/export.d.ts +3 -0
  191. package/dist/types/export.d.ts.map +1 -1
  192. package/dist/types/index.d.ts.map +1 -1
  193. package/dist/types/models/dictionary.model.d.ts +1 -0
  194. package/dist/types/models/dictionary.model.d.ts.map +1 -1
  195. package/dist/types/models/tag.model.d.ts +3 -0
  196. package/dist/types/models/tag.model.d.ts.map +1 -0
  197. package/dist/types/routes/ai.routes.d.ts +25 -0
  198. package/dist/types/routes/ai.routes.d.ts.map +1 -0
  199. package/dist/types/routes/dictionary.routes.d.ts +6 -2
  200. package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
  201. package/dist/types/routes/tags.routes.d.ts +29 -0
  202. package/dist/types/routes/tags.routes.d.ts.map +1 -0
  203. package/dist/types/schemas/dictionary.schema.d.ts +1 -0
  204. package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
  205. package/dist/types/schemas/project.schema.d.ts.map +1 -1
  206. package/dist/types/schemas/tag.schema.d.ts +16 -0
  207. package/dist/types/schemas/tag.schema.d.ts.map +1 -0
  208. package/dist/types/services/dictionary.service.d.ts +10 -2
  209. package/dist/types/services/dictionary.service.d.ts.map +1 -1
  210. package/dist/types/services/project.service.d.ts.map +1 -1
  211. package/dist/types/services/tag.service.d.ts +45 -0
  212. package/dist/types/services/tag.service.d.ts.map +1 -0
  213. package/dist/types/types/dictionary.types.d.ts +14 -4
  214. package/dist/types/types/dictionary.types.d.ts.map +1 -1
  215. package/dist/types/types/project.types.d.ts +3 -0
  216. package/dist/types/types/project.types.d.ts.map +1 -1
  217. package/dist/types/types/tag.types.d.ts +26 -0
  218. package/dist/types/types/tag.types.d.ts.map +1 -0
  219. package/dist/types/utils/audit/index.d.ts +28 -0
  220. package/dist/types/utils/audit/index.d.ts.map +1 -0
  221. package/dist/types/utils/auditDictionary/index.d.ts +24 -0
  222. package/dist/types/utils/auditDictionary/index.d.ts.map +1 -0
  223. package/dist/types/utils/auditDictionaryField/index.d.ts +24 -0
  224. package/dist/types/utils/auditDictionaryField/index.d.ts.map +1 -0
  225. package/dist/types/utils/auditDictionaryMetadata/index.d.ts +21 -0
  226. package/dist/types/utils/auditDictionaryMetadata/index.d.ts.map +1 -0
  227. package/dist/types/utils/auditTag/index.d.ts +27 -0
  228. package/dist/types/utils/auditTag/index.d.ts.map +1 -0
  229. package/dist/types/utils/ensureArrayQueryFilter.d.ts +2 -0
  230. package/dist/types/utils/ensureArrayQueryFilter.d.ts.map +1 -0
  231. package/dist/types/utils/ensureMongoDocumentToObject.d.ts +8 -0
  232. package/dist/types/utils/ensureMongoDocumentToObject.d.ts.map +1 -0
  233. package/dist/types/utils/errors/ErrorHandler.d.ts.map +1 -1
  234. package/dist/types/utils/errors/errorCodes.d.ts +104 -0
  235. package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
  236. package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts +2 -0
  237. package/dist/types/utils/filtersAndPagination/getDictionaryFiltersAndPagination.d.ts.map +1 -1
  238. package/dist/types/utils/filtersAndPagination/getOrganizationFiltersAndPagination.d.ts.map +1 -1
  239. package/dist/types/utils/filtersAndPagination/getProjectFiltersAndPagination.d.ts.map +1 -1
  240. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts +24 -0
  241. package/dist/types/utils/filtersAndPagination/getTagFiltersAndPagination.d.ts.map +1 -0
  242. package/dist/types/utils/filtersAndPagination/getUserFiltersAndPagination.d.ts.map +1 -1
  243. package/dist/types/utils/mapper/dictionary.d.ts +1 -1
  244. package/dist/types/utils/mapper/dictionary.d.ts.map +1 -1
  245. package/dist/types/utils/mapper/organization.d.ts.map +1 -1
  246. package/dist/types/utils/mapper/project.d.ts.map +1 -1
  247. package/dist/types/utils/mapper/tag.d.ts +16 -0
  248. package/dist/types/utils/mapper/tag.d.ts.map +1 -0
  249. package/dist/types/utils/mapper/user.d.ts +2 -2
  250. package/dist/types/utils/mapper/user.d.ts.map +1 -1
  251. package/dist/types/utils/removeObjectKeys.d.ts +2 -0
  252. package/dist/types/utils/removeObjectKeys.d.ts.map +1 -0
  253. package/dist/types/utils/validation/validateProject.d.ts.map +1 -1
  254. package/dist/types/utils/validation/validateTag.d.ts +16 -0
  255. package/dist/types/utils/validation/validateTag.d.ts.map +1 -0
  256. package/package.json +6 -5
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var ai_controller_exports = {};
30
+ __export(ai_controller_exports, {
31
+ auditContentDeclaration: () => auditContentDeclaration,
32
+ auditContentDeclarationField: () => auditContentDeclarationField,
33
+ auditContentDeclarationMetadata: () => auditContentDeclarationMetadata,
34
+ auditTag: () => auditTag
35
+ });
36
+ module.exports = __toCommonJS(ai_controller_exports);
37
+ var import_dictionary = require('./../services/dictionary.service.cjs');
38
+ var import_tag = require('./../services/tag.service.cjs');
39
+ var tagService = __toESM(require('./../services/tag.service.cjs'), 1);
40
+ var auditContentDeclarationUtil = __toESM(require('./../utils/auditDictionary/index.cjs'), 1);
41
+ var auditContentDeclarationFieldUtil = __toESM(require('./../utils/auditDictionaryField/index.cjs'), 1);
42
+ var auditContentDeclarationMetadataUtil = __toESM(require('./../utils/auditDictionaryMetadata/index.cjs'), 1);
43
+ var auditTagUtil = __toESM(require('./../utils/auditTag/index.cjs'), 1);
44
+ var import_errors = require('./../utils/errors/index.cjs');
45
+ var import_responseData = require('./../utils/responseData.cjs');
46
+ const auditContentDeclaration = async (req, res, _next) => {
47
+ const { user, project } = res.locals;
48
+ const {
49
+ fileContent,
50
+ filePath,
51
+ openAiApiKey,
52
+ customPrompt,
53
+ model,
54
+ locales,
55
+ defaultLocale,
56
+ tagsKeys
57
+ } = req.body;
58
+ if (!openAiApiKey) {
59
+ if (!user) {
60
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
61
+ return;
62
+ }
63
+ if (!project) {
64
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
65
+ return;
66
+ }
67
+ }
68
+ try {
69
+ let tags = [];
70
+ if (project?.organizationId) {
71
+ tags = await (0, import_tag.getTagsByKeys)(tagsKeys, project.organizationId);
72
+ }
73
+ const auditResponse = await auditContentDeclarationUtil.auditDictionary({
74
+ fileContent,
75
+ filePath,
76
+ model,
77
+ openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,
78
+ customPrompt,
79
+ locales,
80
+ defaultLocale,
81
+ tags
82
+ });
83
+ if (!auditResponse) {
84
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "AUDIT_FAILED");
85
+ return;
86
+ }
87
+ const responseData = (0, import_responseData.formatResponse)({
88
+ data: auditResponse
89
+ });
90
+ res.json(responseData);
91
+ return;
92
+ } catch (error) {
93
+ import_errors.ErrorHandler.handleAppErrorResponse(res, error);
94
+ return;
95
+ }
96
+ };
97
+ const auditContentDeclarationField = async (req, res, _next) => {
98
+ const { user, project } = res.locals;
99
+ const {
100
+ fileContent,
101
+ openAiApiKey,
102
+ customPrompt,
103
+ model,
104
+ locales,
105
+ tagsKeys,
106
+ keyPath
107
+ } = req.body;
108
+ if (!openAiApiKey) {
109
+ if (!user) {
110
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
111
+ return;
112
+ }
113
+ if (!project) {
114
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
115
+ return;
116
+ }
117
+ }
118
+ try {
119
+ let tags = [];
120
+ if (project?.organizationId) {
121
+ tags = await (0, import_tag.getTagsByKeys)(tagsKeys, project.organizationId);
122
+ }
123
+ const auditResponse = await auditContentDeclarationFieldUtil.auditDictionaryField({
124
+ fileContent,
125
+ model,
126
+ openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,
127
+ customPrompt,
128
+ locales,
129
+ tags,
130
+ keyPath
131
+ });
132
+ if (!auditResponse) {
133
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "AUDIT_FAILED");
134
+ return;
135
+ }
136
+ const responseData = (0, import_responseData.formatResponse)({
137
+ data: auditResponse
138
+ });
139
+ res.json(responseData);
140
+ return;
141
+ } catch (error) {
142
+ import_errors.ErrorHandler.handleAppErrorResponse(res, error);
143
+ return;
144
+ }
145
+ };
146
+ const auditContentDeclarationMetadata = async (req, res, _next) => {
147
+ const { user, organization, project } = res.locals;
148
+ const { fileContent, openAiApiKey, customPrompt, model } = req.body;
149
+ if (!openAiApiKey) {
150
+ if (!user) {
151
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
152
+ return;
153
+ }
154
+ if (!organization) {
155
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "ORGANIZATION_NOT_DEFINED");
156
+ return;
157
+ }
158
+ if (!project) {
159
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
160
+ return;
161
+ }
162
+ }
163
+ try {
164
+ const tags = await tagService.findTags(
165
+ {
166
+ organizationId: organization?._id
167
+ },
168
+ 0,
169
+ 1e3
170
+ );
171
+ const auditResponse = await auditContentDeclarationMetadataUtil.auditDictionaryMetadata({
172
+ fileContent,
173
+ model,
174
+ openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,
175
+ customPrompt,
176
+ tags
177
+ });
178
+ if (!auditResponse) {
179
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "AUDIT_FAILED");
180
+ return;
181
+ }
182
+ const responseData = (0, import_responseData.formatResponse)({
183
+ data: auditResponse
184
+ });
185
+ res.json(responseData);
186
+ return;
187
+ } catch (error) {
188
+ import_errors.ErrorHandler.handleAppErrorResponse(res, error);
189
+ return;
190
+ }
191
+ };
192
+ const auditTag = async (req, res, _next) => {
193
+ const { user, project } = res.locals;
194
+ const { openAiApiKey, customPrompt, model, tag } = req.body;
195
+ if (!openAiApiKey) {
196
+ if (!user) {
197
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "USER_NOT_DEFINED");
198
+ return;
199
+ }
200
+ if (!project) {
201
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
202
+ return;
203
+ }
204
+ }
205
+ try {
206
+ let dictionaries = [];
207
+ if (project?.organizationId) {
208
+ dictionaries = await (0, import_dictionary.getDictionariesByTags)([tag.key], project._id);
209
+ }
210
+ const auditResponse = await auditTagUtil.auditTag({
211
+ model,
212
+ openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,
213
+ customPrompt,
214
+ dictionaries,
215
+ tag
216
+ });
217
+ if (!auditResponse) {
218
+ import_errors.ErrorHandler.handleGenericErrorResponse(res, "AUDIT_FAILED");
219
+ return;
220
+ }
221
+ const responseData = (0, import_responseData.formatResponse)({
222
+ data: auditResponse
223
+ });
224
+ res.json(responseData);
225
+ return;
226
+ } catch (error) {
227
+ import_errors.ErrorHandler.handleAppErrorResponse(res, error);
228
+ return;
229
+ }
230
+ };
231
+ // Annotate the CommonJS export names for ESM import in node:
232
+ 0 && (module.exports = {
233
+ auditContentDeclaration,
234
+ auditContentDeclarationField,
235
+ auditContentDeclarationMetadata,
236
+ auditTag
237
+ });
238
+ //# sourceMappingURL=ai.controller.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/controllers/ai.controller.ts"],"sourcesContent":["import { type KeyPath } from '@intlayer/core';\nimport type { ResponseWithInformation } from '@middlewares/sessionAuth.middleware';\nimport { getDictionariesByTags } from '@services/dictionary.service';\nimport { getTagsByKeys } from '@services/tag.service';\nimport * as tagService from '@services/tag.service';\nimport * as auditContentDeclarationUtil from '@utils/auditDictionary';\nimport * as auditContentDeclarationFieldUtil from '@utils/auditDictionaryField';\nimport * as auditContentDeclarationMetadataUtil from '@utils/auditDictionaryMetadata';\nimport * as auditTagUtil from '@utils/auditTag';\nimport { AppError, ErrorHandler } from '@utils/errors';\nimport { formatResponse, type ResponseData } from '@utils/responseData';\nimport type { NextFunction, Request } from 'express';\nimport { Locales } from 'intlayer';\nimport type { Dictionary } from '@/types/dictionary.types';\nimport type { Tag } from '@/types/tag.types';\n\nexport type AuditContentDeclarationBody = {\n openAiApiKey?: string;\n customPrompt?: string;\n locales: Locales[];\n defaultLocale: Locales;\n fileContent: string;\n filePath?: string;\n model?: string;\n tagsKeys?: string[];\n};\nexport type AuditContentDeclarationResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclaration = async (\n req: Request<AuditContentDeclarationBody>,\n res: ResponseWithInformation<AuditContentDeclarationResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project } = res.locals;\n const {\n fileContent,\n filePath,\n openAiApiKey,\n customPrompt,\n model,\n locales,\n defaultLocale,\n tagsKeys,\n } = req.body;\n\n if (!openAiApiKey) {\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse = await auditContentDeclarationUtil.auditDictionary({\n fileContent,\n filePath,\n model,\n openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n customPrompt,\n locales,\n defaultLocale,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\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 AuditContentDeclarationFieldBody = {\n openAiApiKey?: string;\n customPrompt?: string;\n locales: Locales[];\n fileContent: string;\n filePath?: string;\n model?: string;\n tagsKeys?: string[];\n keyPath: KeyPath[];\n};\nexport type AuditContentDeclarationFieldResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationField = async (\n req: Request<AuditContentDeclarationFieldBody>,\n res: ResponseWithInformation<AuditContentDeclarationFieldResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project } = res.locals;\n const {\n fileContent,\n openAiApiKey,\n customPrompt,\n model,\n locales,\n tagsKeys,\n keyPath,\n } = req.body;\n\n if (!openAiApiKey) {\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n }\n\n try {\n let tags: Tag[] = [];\n\n if (project?.organizationId) {\n tags = await getTagsByKeys(tagsKeys, project.organizationId);\n }\n\n const auditResponse =\n await auditContentDeclarationFieldUtil.auditDictionaryField({\n fileContent,\n model,\n openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n customPrompt,\n locales,\n tags,\n keyPath,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\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 AuditContentDeclarationMetadataBody = {\n openAiApiKey?: string;\n customPrompt?: string;\n fileContent: string;\n model?: string;\n};\nexport type AuditContentDeclarationMetadataResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditContentDeclarationMetadata = async (\n req: Request<AuditContentDeclarationMetadataBody>,\n res: ResponseWithInformation<AuditContentDeclarationMetadataResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, organization, project } = res.locals;\n const { fileContent, openAiApiKey, customPrompt, model } = req.body;\n\n if (!openAiApiKey) {\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!organization) {\n ErrorHandler.handleGenericErrorResponse(res, 'ORGANIZATION_NOT_DEFINED');\n return;\n }\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n }\n\n try {\n const tags: Tag[] = await tagService.findTags(\n {\n organizationId: organization?._id,\n },\n 0,\n 1000\n );\n\n const auditResponse =\n await auditContentDeclarationMetadataUtil.auditDictionaryMetadata({\n fileContent,\n model,\n openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n customPrompt,\n tags,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\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 AuditTagBody = {\n openAiApiKey?: string;\n customPrompt?: string;\n filePath?: string;\n model?: string;\n tag: Tag;\n};\nexport type AuditTagResult =\n ResponseData<auditContentDeclarationUtil.AuditFileResultData>;\n\n/**\n * Retrieves a list of dictionaries based on filters and pagination.\n */\nexport const auditTag = async (\n req: Request<undefined, undefined, AuditTagBody>,\n res: ResponseWithInformation<AuditTagResult>,\n _next: NextFunction\n): Promise<void> => {\n const { user, project } = res.locals;\n const { openAiApiKey, customPrompt, model, tag } = req.body;\n\n if (!openAiApiKey) {\n if (!user) {\n ErrorHandler.handleGenericErrorResponse(res, 'USER_NOT_DEFINED');\n return;\n }\n if (!project) {\n ErrorHandler.handleGenericErrorResponse(res, 'PROJECT_NOT_DEFINED');\n return;\n }\n }\n\n try {\n let dictionaries: Dictionary[] = [];\n if (project?.organizationId) {\n dictionaries = await getDictionariesByTags([tag.key], project._id);\n }\n\n const auditResponse = await auditTagUtil.auditTag({\n model,\n openAiApiKey: openAiApiKey ?? process.env.OPENAI_API_KEY!,\n customPrompt,\n dictionaries,\n tag,\n });\n\n if (!auditResponse) {\n ErrorHandler.handleGenericErrorResponse(res, 'AUDIT_FAILED');\n return;\n }\n\n const responseData =\n formatResponse<auditContentDeclarationUtil.AuditFileResultData>({\n data: auditResponse,\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;AAEA,wBAAsC;AACtC,iBAA8B;AAC9B,iBAA4B;AAC5B,kCAA6C;AAC7C,uCAAkD;AAClD,0CAAqD;AACrD,mBAA8B;AAC9B,oBAAuC;AACvC,0BAAkD;AAsB3C,MAAM,0BAA0B,OACrC,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,QAAQ,IAAI,IAAI;AAC9B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,IAAI;AAER,MAAI,CAAC,cAAc;AACjB,QAAI,CAAC,MAAM;AACT,iCAAa,2BAA2B,KAAK,kBAAkB;AAC/D;AAAA,IACF;AACA,QAAI,CAAC,SAAS;AACZ,iCAAa,2BAA2B,KAAK,qBAAqB;AAClE;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AACF,QAAI,OAAc,CAAC;AAEnB,QAAI,SAAS,gBAAgB;AAC3B,aAAO,UAAM,0BAAc,UAAU,QAAQ,cAAc;AAAA,IAC7D;AAEA,UAAM,gBAAgB,MAAM,4BAA4B,gBAAgB;AAAA,MACtE;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc,gBAAgB,QAAQ,IAAI;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,eAAe;AAClB,iCAAa,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BAAe,UAAM,yCAAsB,CAAC,IAAI,GAAG,GAAG,QAAQ,GAAG;AAAA,IACnE;AAEA,UAAM,gBAAgB,MAAM,aAAa,SAAS;AAAA,MAChD;AAAA,MACA,cAAc,gBAAgB,QAAQ,IAAI;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,eAAe;AAClB,iCAAa,2BAA2B,KAAK,cAAc;AAC3D;AAAA,IACF;AAEA,UAAM,mBACJ,oCAAgE;AAAA,MAC9D,MAAM;AAAA,IACR,CAAC;AAEH,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,+BAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
@@ -67,7 +67,7 @@ const getDictionaries = async (req, res, _next) => {
67
67
  );
68
68
  const totalItems = await dictionaryService.countDictionaries(filters);
69
69
  const dictionariesAPI = dictionaries.map(
70
- (el) => (0, import_dictionary.mapDictionaryToAPI)(el, project._id)
70
+ (el) => (0, import_dictionary.mapDictionaryToAPI)(el, project._id, el.publishedVersion ?? void 0)
71
71
  );
72
72
  const responseData = (0, import_responseData.formatPaginatedResponse)({
73
73
  data: dictionariesAPI,
@@ -110,7 +110,7 @@ const getDictionariesKeys = async (_req, res, _next) => {
110
110
  const getDictionaryByKey = async (req, res, _next) => {
111
111
  const { project, user, dictionaryRights } = res.locals;
112
112
  const { dictionaryKey } = req.params;
113
- const { version } = req.query;
113
+ const version = req.query.version;
114
114
  if (!project) {
115
115
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_DEFINED");
116
116
  return;
@@ -124,18 +124,18 @@ const getDictionaryByKey = async (req, res, _next) => {
124
124
  return;
125
125
  }
126
126
  try {
127
- const dictionaries = await dictionaryService.getDictionaryByKey(
127
+ const dictionary = await dictionaryService.getDictionaryByKey(
128
128
  dictionaryKey,
129
129
  project._id
130
130
  );
131
- if (!dictionaries.projectIds.includes(String(project._id))) {
131
+ if (!dictionary.projectIds.map(String).includes(String(project._id))) {
132
132
  import_errors.ErrorHandler.handleGenericErrorResponse(
133
133
  res,
134
134
  "DICTIONARY_PROJECT_MISMATCH"
135
135
  );
136
136
  return;
137
137
  }
138
- const apiResult = (0, import_dictionary.mapDictionaryToAPI)(dictionaries, project._id, version);
138
+ const apiResult = (0, import_dictionary.mapDictionaryToAPI)(dictionary, project._id, version);
139
139
  const responseData = (0, import_responseData.formatResponse)({
140
140
  data: apiResult
141
141
  });
@@ -173,9 +173,15 @@ const addDictionary = async (req, res, _next) => {
173
173
  key: dictionaryData.key,
174
174
  title: dictionaryData.title,
175
175
  description: dictionaryData.description,
176
- content: [dictionaryData.content],
176
+ content: {
177
+ v1: {
178
+ content: dictionaryData.content
179
+ }
180
+ },
177
181
  creatorId: user._id,
178
- filePath: { [String(project._id)]: dictionaryData.filePath ?? "" },
182
+ filePath: {
183
+ [String(project._id)]: dictionaryData.filePath ?? ""
184
+ },
179
185
  projectIds: dictionaryData.projectIds ?? [String(project._id)]
180
186
  };
181
187
  try {
@@ -245,20 +251,29 @@ const pushDictionaries = async (req, res, _next) => {
245
251
  error: []
246
252
  };
247
253
  for (const dictionaryDataEl of newDictionaries) {
254
+ const publishedVersion = dictionaryDataEl.publishedVersion ? dictionaryDataEl.publishedVersion === "-1" ? null : dictionaryDataEl.publishedVersion : null;
248
255
  const dictionary = {
249
256
  title: dictionaryDataEl.title,
250
257
  description: dictionaryDataEl.description,
251
- content: [dictionaryDataEl.content],
252
258
  projectIds: [String(project._id)],
253
259
  creatorId: user._id,
254
- filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? "" },
255
- key: dictionaryDataEl.key
260
+ content: {
261
+ v1: {
262
+ content: dictionaryDataEl.content
263
+ }
264
+ },
265
+ filePath: {
266
+ [String(project._id)]: dictionaryDataEl.filePath ?? ""
267
+ },
268
+ key: dictionaryDataEl.key,
269
+ publishedVersion
256
270
  };
257
271
  try {
258
272
  const newDictionary = await dictionaryService.createDictionary(dictionary);
259
273
  result.newDictionaries.push(newDictionary.key);
260
274
  } catch (error) {
261
275
  import_errors.ErrorHandler.handleAppErrorResponse(res, error);
276
+ return;
262
277
  }
263
278
  }
264
279
  if (existingDictionariesKey.length >= 0) {
@@ -270,16 +285,32 @@ const pushDictionaries = async (req, res, _next) => {
270
285
  const existingDictionaryDB = existingDictionariesDB.find(
271
286
  (dictionaryDB) => dictionaryDB.key === dictionaryDataEl.key
272
287
  );
288
+ const existingContentArray = Object.values(
289
+ existingDictionaryDB.content
290
+ );
291
+ const lastContent = existingContentArray[existingContentArray.length - 1].content;
292
+ const isSameContent = JSON.stringify(lastContent) === JSON.stringify(dictionaryDataEl.content);
293
+ let newContent = existingDictionaryDB.content;
294
+ if (!isSameContent) {
295
+ const newContentVersion = dictionaryService.incrementVersion(existingDictionaryDB);
296
+ newContent = {
297
+ ...newContent,
298
+ [newContentVersion]: {
299
+ content: dictionaryDataEl.content
300
+ }
301
+ };
302
+ }
303
+ const publishedVersion = dictionaryDataEl.publishedVersion ? dictionaryDataEl.publishedVersion === "-1" ? null : dictionaryDataEl.publishedVersion : null;
273
304
  const dictionary = {
274
305
  ...existingDictionaryDB,
275
306
  ...dictionaryDataEl,
276
- content: [
277
- ...existingDictionaryDB.content ?? [],
278
- dictionaryDataEl.content
279
- ],
307
+ content: newContent,
280
308
  projectIds: [String(project._id)],
281
309
  creatorId: user._id,
282
- filePath: { [String(project._id)]: dictionaryDataEl.filePath ?? "" },
310
+ filePath: {
311
+ [String(project._id)]: dictionaryDataEl.filePath ?? ""
312
+ },
313
+ publishedVersion,
283
314
  key: dictionaryDataEl.key
284
315
  };
285
316
  try {
@@ -291,6 +322,7 @@ const pushDictionaries = async (req, res, _next) => {
291
322
  result.updatedDictionaries.push(newDictionary.key);
292
323
  } catch (error) {
293
324
  import_errors.ErrorHandler.handleAppErrorResponse(res, error);
325
+ return;
294
326
  }
295
327
  }
296
328
  }
@@ -315,6 +347,7 @@ const pushDictionaries = async (req, res, _next) => {
315
347
  }
316
348
  };
317
349
  const updateDictionary = async (req, res, _next) => {
350
+ const { dictionaryId } = req.params;
318
351
  const { project, dictionaryRights } = res.locals;
319
352
  const dictionaryData = req.body;
320
353
  if (!dictionaryData) {
@@ -329,7 +362,7 @@ const updateDictionary = async (req, res, _next) => {
329
362
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_PROJECT_MISMATCH");
330
363
  return;
331
364
  }
332
- if (typeof dictionaryData._id === "undefined") {
365
+ if (typeof dictionaryId === "undefined") {
333
366
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "DICTIONARY_ID_NOT_FOUND");
334
367
  return;
335
368
  }
@@ -339,7 +372,7 @@ const updateDictionary = async (req, res, _next) => {
339
372
  }
340
373
  try {
341
374
  const updatedDictionary = await dictionaryService.updateDictionaryById(
342
- dictionaryData._id,
375
+ dictionaryId,
343
376
  dictionaryData
344
377
  );
345
378
  const apiResult = (0, import_dictionary.mapDictionaryToAPI)(updatedDictionary, project._id);
@@ -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 { 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,oBAAuC;AACvC,+CAGO;AAEP,wBAAmC;AACnC,0BAKO;AAEP,8BAAkB;AAeX,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,SAAS,iBAAiB,IAAI,IAAI;AAChD,QAAM,EAAE,SAAS,UAAU,MAAM,MAAM,iBAAiB,QACtD,4EAAkC,GAAG;AAEvC,M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jB,+BAAa,2BAA2B,KAAK,yBAAyB;AACtE;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,+BAAa,2BAA2B,KAAK,qBAAqB;AAClE;AAAA,EACF;AAEA,MAAI,CAAC,kBAAkB,OAAO;AAC5B,+BAAa,2BAA2B,KAAK,6BAA6B;AAC1E;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,aAAS,2BAAE;AAAA,QACT,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,iBAAa,2BAAE;AAAA,QACb,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,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 VersionedContent,\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, el.publishedVersion ?? undefined)\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?: string };\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, any, any, GetDictionaryQuery>,\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.version;\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 dictionary = await dictionaryService.getDictionaryByKey(\n dictionaryKey,\n project._id\n );\n\n if (!dictionary.projectIds.map(String).includes(String(project._id))) {\n ErrorHandler.handleGenericErrorResponse(\n res,\n 'DICTIONARY_PROJECT_MISMATCH'\n );\n return;\n }\n\n const apiResult = mapDictionaryToAPI(dictionary, 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: {\n v1: {\n content: dictionaryData.content,\n },\n },\n creatorId: user._id,\n filePath: {\n [String(project._id)]: dictionaryData.filePath ?? '',\n },\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 = {\n dictionaries: LocalDictionary[];\n};\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 publishedVersion = dictionaryDataEl.publishedVersion\n ? dictionaryDataEl.publishedVersion === '-1'\n ? null\n : dictionaryDataEl.publishedVersion\n : null;\n\n const dictionary: DictionaryData = {\n title: dictionaryDataEl.title,\n description: dictionaryDataEl.description,\n projectIds: [String(project._id)],\n creatorId: user._id,\n content: {\n v1: {\n content: dictionaryDataEl.content,\n },\n },\n filePath: {\n [String(project._id)]: dictionaryDataEl.filePath ?? '',\n },\n key: dictionaryDataEl.key,\n publishedVersion,\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 return;\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 existingContentArray = Object.values(\n existingDictionaryDB.content\n );\n\n const lastContent =\n existingContentArray[existingContentArray.length - 1].content;\n\n const isSameContent =\n JSON.stringify(lastContent) ===\n JSON.stringify(dictionaryDataEl.content);\n\n let newContent: VersionedContent = existingDictionaryDB.content;\n\n if (!isSameContent) {\n const newContentVersion =\n dictionaryService.incrementVersion(existingDictionaryDB);\n\n newContent = {\n ...newContent,\n [newContentVersion]: {\n content: dictionaryDataEl.content,\n },\n };\n }\n\n const publishedVersion = dictionaryDataEl.publishedVersion\n ? dictionaryDataEl.publishedVersion === '-1'\n ? null\n : dictionaryDataEl.publishedVersion\n : null;\n\n const dictionary: DictionaryData = {\n ...existingDictionaryDB,\n ...dictionaryDataEl,\n content: newContent,\n projectIds: [String(project._id)],\n creatorId: user._id,\n filePath: {\n [String(project._id)]: dictionaryDataEl.filePath ?? '',\n },\n publishedVersion,\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 return;\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 UpdateDictionaryParam = { dictionaryId: string };\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<UpdateDictionaryParam, any, UpdateDictionaryBody>,\n res: ResponseWithInformation<UpdateDictionaryResult>,\n _next: NextFunction\n): Promise<void> => {\n const { dictionaryId } = req.params;\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 dictionaryId === '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 dictionaryId,\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,oBAAuC;AACvC,+CAGO;AAEP,wBAAmC;AACnC,0BAKO;AAEP,8BAAkB;AAgBX,MAAM,kBAAkB,OAC7B,KACA,KACA,UACkB;AAClB,QAAM,EAAE,MAAM,SAAS,iBAAiB,IAAI,IAAI;AAChD,QAAM,EAAE,SAAS,UAAU,MAAM,MAAM,iBAAiB,QACtD,4EAAkC,GAAG;AAEvC,MAAI,CAAC,SAAS;AACZ,+BAAa,2BAA2B,KAAK,qBAAqB;AAClE;AAAA,EACF;AACA,MAAI,CAAC,MAAM;AACT,+BAAa,2BAA2B,KAAK,kBAAkB;AAC/D;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB,MAAM;AAC3B,+BAAa,2BAA2B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AAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,iBAAa,2BAAE;AAAA,QACb,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN,CAAC;AAAA,MACD,MAAM;AAAA,IACR,CAAC;AAED,QAAI,KAAK,YAAY;AACrB;AAAA,EACF,SAAS,OAAO;AACd,+BAAa,uBAAuB,KAAK,KAAiB;AAC1D;AAAA,EACF;AACF;","names":[]}
@@ -194,10 +194,6 @@ const updateProject = async (req, res, _next) => {
194
194
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_RIGHTS_NOT_WRITE");
195
195
  return;
196
196
  }
197
- if (String(project._id) !== String(projectData._id)) {
198
- import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_ID_MISMATCH");
199
- return;
200
- }
201
197
  if (String(project.organizationId) !== String(organization._id)) {
202
198
  import_errors.ErrorHandler.handleGenericErrorResponse(res, "PROJECT_NOT_IN_ORGANIZATION");
203
199
  return;
@@ -205,7 +201,7 @@ const updateProject = async (req, res, _next) => {
205
201
  try {
206
202
  const updatedProject = await projectService.updateProjectById(
207
203
  project._id,
208
- project
204
+ projectData
209
205
  );
210
206
  const formattedProject = (0, import_project.mapProjectToAPI)(
211
207
  updatedProject,
@@ -343,7 +339,7 @@ const deleteProject = async (_req, res, _next) => {
343
339
  }
344
340
  try {
345
341
  const projectToDelete = await projectService.getProjectById(project._id);
346
- if (projectToDelete.organizationId !== organization._id) {
342
+ if (String(projectToDelete.organizationId) !== String(organization._id)) {
347
343
  import_errors.ErrorHandler.handleGenericErrorResponse(
348
344
  res,
349
345
  "PROJECT_NOT_IN_ORGANIZATION"