[offers][chore] Speed up fetching of dashboard offers

pull/433/head
Bryann Yeap Kok Keong 2 years ago
parent 000f22a50c
commit db19a84080

@ -73,7 +73,7 @@ export const offersRouter = createRouter().query('list', {
const order = getOrder(input.sortBy.charAt(0)); const order = getOrder(input.sortBy.charAt(0));
const sortingKey = input.sortBy.substring(1); const sortingKey = input.sortBy.substring(1);
let data = !yoeRange const data = !yoeRange
? await ctx.prisma.offersOffer.findMany({ ? await ctx.prisma.offersOffer.findMany({
// Internship // Internship
include: { include: {
@ -303,11 +303,18 @@ export const offersRouter = createRouter().query('list', {
}, },
}); });
const startRecordIndex: number = input.limit * input.offset;
const endRecordIndex: number =
startRecordIndex + input.limit <= data.length
? startRecordIndex + input.limit
: data.length;
let paginatedData = data.slice(startRecordIndex, endRecordIndex);
// CONVERTING // CONVERTING
const currency = input.currency?.toUpperCase(); const currency = input.currency?.toUpperCase();
if (currency != null && currency in Currency) { if (currency != null && currency in Currency) {
data = await Promise.all( paginatedData = await Promise.all(
data.map(async (offer) => { paginatedData.map(async (offer) => {
if (offer.offersFullTime?.totalCompensation != null) { if (offer.offersFullTime?.totalCompensation != null) {
offer.offersFullTime.totalCompensation.value = offer.offersFullTime.totalCompensation.value =
await convertWithDate( await convertWithDate(
@ -367,13 +374,6 @@ export const offersRouter = createRouter().query('list', {
); );
} }
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 getOffersResponseMapper( return getOffersResponseMapper(
paginatedData.map((offer) => dashboardOfferDtoMapper(offer)), paginatedData.map((offer) => dashboardOfferDtoMapper(offer)),
{ {

Loading…
Cancel
Save