Skip to content

Commit

Permalink
fix(routes): fix logic for determine routes and stop checking TS duri…
Browse files Browse the repository at this point in the history
…ng prod build
  • Loading branch information
ijemmao committed Sep 27, 2024
1 parent 1c80d3e commit 884bf42
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ module.exports = {
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
i18n,
};
11 changes: 6 additions & 5 deletions src/controllers/utils/buildDocs.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,13 +40,16 @@ const removeKeysInNestedDoc = <T>(docs: T[], nestedDocsKey: keyof T) => {

const cleanExamples = ({ examples, version }: { examples: IncomingExample[], version: Version }) =>
examples.map((example) => {
const cleanedExample = omit(
const cleanedExample: Omit<IncomingExample, 'source' | 'translations'> & {
igbo: string,
english: string,
pronunciation?: string,
pronunciations?: string[],
} = omit(
assign({
...example,
igbo: '',
english: '',
pronunciation: '',
pronunciations: [] as string[],
}),
['source', 'translations']
);
Expand Down
63 changes: 40 additions & 23 deletions src/controllers/utils/minimizeWords.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,8 +19,8 @@ type MinimizedWord = Omit<
examples: Partial<OutgoingExample>[],
tenses: string[] | undefined,
dialects?: Partial<WordDialect>[] | 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<OutgoingWord>[] | Partial<OutgoingLegacyWord>[],
Expand Down Expand Up @@ -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',
Expand All @@ -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 || {});
Expand All @@ -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']);
}
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/helpers/authorizeDeveloperUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
2 changes: 1 addition & 1 deletion src/middleware/validateApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 884bf42

Please sign in to comment.