[offers][fix] Fix pagination, include yoe in DTO and fix story bug

pull/356/head
BryannYeap 2 years ago
parent e6f2be64b4
commit 7052e8c175

@ -2,25 +2,29 @@ import React from 'react';
import { trpc } from '~/utils/trpc'; import { trpc } from '~/utils/trpc';
function test() { function Test() {
const data = trpc.useQuery([ const data = trpc.useQuery([
'offers.list', 'offers.list',
{ {
limit: 3, limit: 5,
location: 'Singapore, Singapore', location: 'Singapore, Singapore',
offset: 0, offset: 0,
sortBy: '-monthYearReceived', sortBy: '-totalYoe',
yoeCategory: 0, yoeCategory: 1,
}, },
]); ]);
return ( return (
<ul> <>
{data.data?.map((x) => { <ul>
return <li key={x.id}>{JSON.stringify(x)}</li>; {data.data?.data.map((x) => {
})} return <li key={x.id}>{JSON.stringify(x)}</li>;
</ul> })}
</ul>
<br />
<p>{JSON.stringify(data.data?.paging)}</p>
</>
); );
} }
export default test; export default Test;

@ -22,7 +22,7 @@ const getYoeRange = (yoeCategory: number) => {
const ascOrder = '+'; const ascOrder = '+';
const descOrder = '-'; const descOrder = '-';
const sortingKeys = ['monthYearReceived', 'totalCompensation', 'yoe']; const sortingKeys = ['monthYearReceived', 'totalCompensation', 'totalYoe'];
const createSortByValidationRegex = () => { const createSortByValidationRegex = () => {
const startsWithPlusOrMinusOnly = '^[+-]{1}'; const startsWithPlusOrMinusOnly = '^[+-]{1}';
@ -65,9 +65,12 @@ export const offersRouter = createRouter().query('list', {
}, },
}, },
company: true, company: true,
profile: {
include: {
background: true,
},
},
}, },
skip: input.limit * input.offset,
take: input.limit,
where: { where: {
AND: [ AND: [
{ {
@ -103,10 +106,13 @@ export const offersRouter = createRouter().query('list', {
}, },
}, },
company: true, company: true,
profile: {
include: {
background: true,
},
},
}, },
// Junior, Mid // Junior, Mid
skip: input.limit * input.offset,
take: input.limit,
where: { where: {
AND: [ AND: [
{ {
@ -160,9 +166,12 @@ export const offersRouter = createRouter().query('list', {
}, },
}, },
company: true, company: true,
profile: {
include: {
background: true,
},
},
}, },
skip: input.limit * input.offset,
take: input.limit,
where: { where: {
AND: [ AND: [
{ {
@ -259,6 +268,16 @@ export const offersRouter = createRouter().query('list', {
return salary1 - salary2; return salary1 - salary2;
} }
} }
if (sortingKey === 'totalYoe') {
const yoe1 = offer1.profile.background?.totalYoe;
const yoe2 = offer2.profile.background?.totalYoe;
if (yoe1 && yoe2) {
return yoe1 - yoe2;
}
}
return defaultReturn; return defaultReturn;
})(); })();
} }
@ -286,12 +305,35 @@ export const offersRouter = createRouter().query('list', {
} }
} }
if (sortingKey === 'totalYoe') {
const yoe1 = offer1.profile.background?.totalYoe;
const yoe2 = offer2.profile.background?.totalYoe;
if (yoe1 && yoe2) {
return yoe2 - yoe1;
}
}
return defaultReturn; return defaultReturn;
})(); })();
} }
return defaultReturn; return defaultReturn;
}); });
return data; const startRecordIndex: number = input.limit * input.offset;
const endRecordIndex: number =
startRecordIndex + input.limit <= data.length
? startRecordIndex + input.limit
: data.length;
const paginatedData = data.slice(startRecordIndex, endRecordIndex);
return {
data: paginatedData,
paging: {
currPage: input.offset,
numOfItemsInPage: paginatedData.length,
numOfPages: Math.ceil(data.length / input.limit),
},
};
}, },
}); });

@ -8,7 +8,7 @@ export type SlideOutEnterFrom = 'end' | 'start';
type Props = Readonly<{ type Props = Readonly<{
children: React.ReactNode; children: React.ReactNode;
className: string; className?: string;
enterFrom?: SlideOutEnterFrom; enterFrom?: SlideOutEnterFrom;
isShown?: boolean; isShown?: boolean;
onClose?: () => void; onClose?: () => void;

Loading…
Cancel
Save