Skip to content

Commit

Permalink
chore: fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johangirod committed Nov 27, 2023
1 parent 9a9ab0e commit 6e6ba32
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
4 changes: 1 addition & 3 deletions components/finances-section/association/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export const FinancesAssociationSection: React.FC<{
tooltip: {
callbacks: {
label(tooltipItem) {
return formatCurrency(
tooltipItem.parsed.y.toString()
).toString();
return formatCurrency(tooltipItem.parsed.y.toString());
},
},
},
Expand Down
4 changes: 1 addition & 3 deletions components/finances-section/societe/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export const FinancesSocieteSection: React.FC<{
tooltip: {
callbacks: {
label(tooltipItem) {
return formatCurrency(
tooltipItem.parsed.y.toString()
).toString();
return formatCurrency(tooltipItem.parsed.y.toString());
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions pages/personne/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export const getServerSideProps: GetServerSideProps = postServerSideProps(
const page = parseIntWithDefaultValue(pageParam, 1);

const [beginingOfMonth, endOfMonth] = formatMonthIntervalFromPartialDate(
context.query.partialDate || ''
);
(context.query.partialDate as string) || ''
) ?? ['', ''];

const dmin = context.query.dmin || beginingOfMonth;
const dmax = context.query.dmax || endOfMonth;
const dmin = (context.query.dmin as string) || beginingOfMonth;
const dmax = (context.query.dmax as string) || endOfMonth;

const searchFilterParams = new SearchFilterParams({
...context.query,
Expand Down
32 changes: 17 additions & 15 deletions utils/helpers/formatting/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ export const formatPercentage = safe((value: string, digits: number = 1) => {
return parseFloat(value).toFixed(digits) + '%';
});

export const formatCurrency = safe((value: string) => {
const number = parseInt(value, 10);
if (!number && number !== 0) {
return value;
}
export const formatCurrency = safe(
(value: string | number | undefined | null) => {
const number = parseInt(value + '', 10);
if (!number && number !== 0) {
return value as string;
}

const unitlist = ['€', 'K €', 'M €', 'Mds €'];
const sign = Math.sign(number);
const unitlist = ['€', 'K €', 'M €', 'Mds €'];
const sign = Math.sign(number);

const orderOfMagnitude = Math.floor(
(Math.abs(number).toString().length - 1) / 3
);
const magnitude = Math.pow(1000, orderOfMagnitude);
const roundedValue = Math.floor(Math.abs(number / magnitude) * 10) / 10;
const orderOfMagnitude = Math.floor(
(Math.abs(number).toString().length - 1) / 3
);
const magnitude = Math.pow(1000, orderOfMagnitude);
const roundedValue = Math.floor(Math.abs(number / magnitude) * 10) / 10;

return `${sign * roundedValue} ${unitlist[orderOfMagnitude]}`;
});
return `${sign * roundedValue} ${unitlist[orderOfMagnitude]}`;
}
);

export const formatDateYear = safe(
(date: string | Date): string | undefined => {
Expand Down Expand Up @@ -131,7 +133,7 @@ export const formatMonthIntervalFromPartialDate = safe((dPartial: string) => {
0
).getDate();

return [`${dPartial}-01`, `${dPartial}-${lastDayOfMonth}`];
return [`${dPartial}-01`, `${dPartial}-${lastDayOfMonth}`] as const;
});

export const formatAge = safe((date: string | Date) => {
Expand Down
10 changes: 9 additions & 1 deletion utils/server-side-props-helper/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ const handleExceptions = (exception: any, req: IncomingMessage | undefined) => {
console.error('=== Error-handler failed to handle exception ===');
console.error(exception);
console.error(e);
return redirectServerError('Error-handler failed to handle exception', {});
return redirectServerError(
new ErrorHandlerException('Error-handler failed to handle exception', {
cause: e,
})
);
}
};

class ErrorHandlerException extends Error {
name = 'ErrorHandlerException';
}

const getScope = (req: IncomingMessage | undefined, slug: string) => {
let sirenOrSiret = {} as any;

Expand Down
2 changes: 1 addition & 1 deletion utils/user-agent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const isUserAgentABot = (userAgent: string) => {
RegExp(crawler.pattern.toLocaleLowerCase()).test(userAgent)
);
});
} catch (e) {
} catch (e: any) {
logWarningInSentry(new UserAgentParsingException(e));
return false;
}
Expand Down

0 comments on commit 6e6ba32

Please sign in to comment.