diff --git a/next.config.js b/next.config.js index 46e3cf82..75ff3c9b 100644 --- a/next.config.js +++ b/next.config.js @@ -7,5 +7,8 @@ module.exports = { eslint: { ignoreDuringBuilds: true, }, + typescript: { + ignoreBuildErrors: true, + }, i18n, }; diff --git a/src/controllers/utils/buildDocs.ts b/src/controllers/utils/buildDocs.ts index e5bb0882..3b3d2891 100644 --- a/src/controllers/utils/buildDocs.ts +++ b/src/controllers/utils/buildDocs.ts @@ -1,5 +1,3 @@ -/* eslint-disable no-param-reassign */ -/* eslint-disable no-underscore-dangle */ import { Aggregate, Model as ModelType, PipelineStage } from 'mongoose'; import { assign, flatten, flow, omit } from 'lodash'; import Version from '../../shared/constants/Version'; @@ -42,13 +40,16 @@ const removeKeysInNestedDoc = (docs: T[], nestedDocsKey: keyof T) => { const cleanExamples = ({ examples, version }: { examples: IncomingExample[], version: Version }) => examples.map((example) => { - const cleanedExample = omit( + const cleanedExample: Omit & { + igbo: string, + english: string, + pronunciation?: string, + pronunciations?: string[], + } = omit( assign({ ...example, igbo: '', english: '', - pronunciation: '', - pronunciations: [] as string[], }), ['source', 'translations'] ); diff --git a/src/controllers/utils/minimizeWords.ts b/src/controllers/utils/minimizeWords.ts index aa841871..b552daf6 100644 --- a/src/controllers/utils/minimizeWords.ts +++ b/src/controllers/utils/minimizeWords.ts @@ -1,4 +1,4 @@ -import { assign, omit, pick } from 'lodash'; +import { assign, omit } from 'lodash'; import { Types } from 'mongoose'; import Version from '../../shared/constants/Version'; import { @@ -19,8 +19,8 @@ type MinimizedWord = Omit< examples: Partial[], tenses: string[] | undefined, dialects?: Partial[] | LegacyWordDialect | undefined, - relatedTerms?: (string | Partial<{ id: string, _id?: Types.ObjectId }>)[], - stems?: (string | Partial<{ id: string, _id?: Types.ObjectId }>)[], + relatedTerms?: (string | Partial<{ word: string, _id: Types.ObjectId }>)[], + stems?: (string | Partial<{ word: string, _id: Types.ObjectId }>)[], }; const minimizeWords = ( words: Partial[] | Partial[], @@ -52,10 +52,9 @@ const minimizeWords = ( } if (minimizedWord.examples?.length) { minimizedWord.examples = minimizedWord.examples?.map((example) => { - let minimizedExample = assign(example); - minimizedExample = omit(minimizedExample, [ + const originalExample = assign(example); + const minimizedExample = omit(originalExample, [ 'associatedWords', - 'pronunciation', 'updatedAt', 'createdAt', 'meaning', @@ -64,13 +63,8 @@ const minimizeWords = ( 'archived', 'id', ]); - if (!minimizedExample.nsibidi) { - minimizedExample = omit(minimizedExample, ['nsibidi']); - } return minimizedExample; }); - } else { - minimizedWord = omit(minimizedWord, ['example']); } const tensesValues = Object.values(minimizedWord.tenses || {}); @@ -92,23 +86,46 @@ const minimizeWords = ( } if (minimizedWord.relatedTerms?.length) { - minimizedWord.relatedTerms = minimizedWord.relatedTerms?.map((relatedTerm) => { - if (typeof relatedTerm === 'string' || !relatedTerm) { - return relatedTerm; - } - return pick(relatedTerm, ['word', 'id', '_id']); - }); + minimizedWord.relatedTerms = (minimizedWord.relatedTerms || []) + .map((relatedTerm): string | { word: string, id: string } => { + if (typeof relatedTerm === 'string' || !relatedTerm) { + return relatedTerm; + } + return { + word: relatedTerm.word || '', + id: (relatedTerm._id || '').toString(), + }; + }) + .filter((relatedTerm) => Boolean(relatedTerm)) + .filter((relatedTerm) => { + if (typeof relatedTerm === 'string') { + return relatedTerm; + } + return relatedTerm.word && relatedTerm.id; + }); } else { minimizedWord = omit(minimizedWord, ['relatedTerms']); } if (minimizedWord.stems?.length) { - minimizedWord.stems = minimizedWord.stems?.map((stem) => { - if (typeof stem === 'string' || !stem) { - return stem; - } - return pick(stem, ['word', 'id', '_id']); - }); + minimizedWord.stems = minimizedWord.stems + ?.map((stem): { word: string, id: string } | string => { + if (typeof stem === 'string' || !stem) { + return stem; + } + + return { + word: stem.word || '', + id: (stem._id || '').toString(), + }; + }) + .filter((stem) => stem) + .filter((relatedTerm) => { + if (typeof relatedTerm === 'string') { + return relatedTerm; + } + return relatedTerm.word && relatedTerm.id; + }); } else { minimizedWord = omit(minimizedWord, ['stems']); } diff --git a/src/middleware/helpers/authorizeDeveloperUsage.ts b/src/middleware/helpers/authorizeDeveloperUsage.ts index 5c1d79db..7f37725d 100644 --- a/src/middleware/helpers/authorizeDeveloperUsage.ts +++ b/src/middleware/helpers/authorizeDeveloperUsage.ts @@ -53,13 +53,13 @@ const handleDeveloperUsage = async ({ * @param param0 */ export const authorizeDeveloperUsage = async ({ - route, + path, developer, }: { - route: string, + path: string, developer: DeveloperDocument, }) => handleDeveloperUsage({ developer, - apiType: route.startsWith('speech-to-text') ? ApiType.SPEECH_TO_TEXT : ApiType.DICTIONARY, + apiType: path.startsWith('speech-to-text') ? ApiType.SPEECH_TO_TEXT : ApiType.DICTIONARY, }); diff --git a/src/middleware/validateApiKey.ts b/src/middleware/validateApiKey.ts index 6193fd5b..ad7860a3 100644 --- a/src/middleware/validateApiKey.ts +++ b/src/middleware/validateApiKey.ts @@ -34,7 +34,7 @@ const validateApiKey: MiddleWare = async (req, res, next) => { return res.status(401).send({ error: 'Your API key is invalid' }); } - await authorizeDeveloperUsage({ route: req.route, developer }); + await authorizeDeveloperUsage({ path: req.route.path, developer }); return next(); } catch (err: any) {