[offers][chore] Add typed response for get offers API

pull/390/head
BryannYeap 3 years ago
parent 00165a8f7d
commit bca6e85f0a

@ -73,10 +73,10 @@ export default function OffersTable({
}); });
setOffers(filteredData); setOffers(filteredData);
setPagination({ setPagination({
currentPage: (response.paging.currPage as number) + 1, currentPage: response.paging.currentPage + 1,
numOfItems: response.paging.numOfItemsInPage, numOfItems: response.paging.numOfItems,
numOfPages: response.paging.numOfPages, numOfPages: response.paging.numOfPages,
totalItems: response.paging.totalNumberOfOffers, totalItems: response.paging.totalItems,
}); });
}, },
}, },

@ -22,9 +22,12 @@ import type {
AnalysisOffer, AnalysisOffer,
Background, Background,
CreateOfferProfileResponse, CreateOfferProfileResponse,
DashboardOffer,
Education, Education,
Experience, Experience,
GetOffersResponse,
OffersCompany, OffersCompany,
Paging,
Profile, Profile,
ProfileAnalysis, ProfileAnalysis,
ProfileOffer, ProfileOffer,
@ -522,3 +525,52 @@ export const addToProfileResponseMapper = (updatedProfile: {
return addToProfileResponse; return addToProfileResponse;
}; };
export const dashboardOfferDtoMapper = (
offer: OffersOffer & {
OffersFullTime:
| (OffersFullTime & {
baseSalary: OffersCurrency;
bonus: OffersCurrency;
stocks: OffersCurrency;
totalCompensation: OffersCurrency;
})
| null;
OffersIntern: (OffersIntern & { monthlySalary: OffersCurrency }) | null;
company: Company;
profile: OffersProfile & { background: OffersBackground | null };
},
) => {
const dashboardOfferDto: DashboardOffer = {
company: offersCompanyDtoMapper(offer.company),
id: offer.id,
income: valuationDtoMapper({ currency: '', value: -1 }),
monthYearReceived: offer.monthYearReceived,
profileId: offer.profileId,
title: offer.OffersFullTime?.title ?? '',
totalYoe: offer.profile.background?.totalYoe ?? -1,
};
if (offer.OffersFullTime) {
dashboardOfferDto.income = valuationDtoMapper(
offer.OffersFullTime.totalCompensation,
);
} else if (offer.OffersIntern) {
dashboardOfferDto.income = valuationDtoMapper(
offer.OffersIntern.monthlySalary,
);
}
return dashboardOfferDto;
};
export const getOffersResponseMapper = (
data: Array<DashboardOffer>,
paging: Paging,
) => {
const getOffersResponse: GetOffersResponse = {
data,
paging,
};
return getOffersResponse;
};

@ -1,6 +1,11 @@
import { z } from 'zod'; import { z } from 'zod';
import { TRPCError } from '@trpc/server'; import { TRPCError } from '@trpc/server';
import {
dashboardOfferDtoMapper,
getOffersResponseMapper,
} from '~/mappers/offers-mappers';
import { createRouter } from '../context'; import { createRouter } from '../context';
const yoeCategoryMap: Record<number, string> = { const yoeCategoryMap: Record<number, string> = {
@ -299,14 +304,14 @@ export const offersRouter = createRouter().query('list', {
: data.length; : data.length;
const paginatedData = data.slice(startRecordIndex, endRecordIndex); const paginatedData = data.slice(startRecordIndex, endRecordIndex);
return { return getOffersResponseMapper(
data: paginatedData, paginatedData.map((offer) => dashboardOfferDtoMapper(offer)),
paging: { {
currPage: input.offset, currentPage: input.offset,
numOfItemsInPage: paginatedData.length, numOfItems: paginatedData.length,
numOfPages: Math.ceil(data.length / input.limit), numOfPages: Math.ceil(data.length / input.limit),
totalNumberOfOffers: data.length, totalItems: data.length,
}, },
}; );
}, },
}); });

@ -65,6 +65,7 @@ export type DashboardOffer = {
id: string; id: string;
income: Valuation; income: Valuation;
monthYearReceived: Date; monthYearReceived: Date;
profileId: string;
title: string; title: string;
totalYoe: number; totalYoe: number;
}; };
@ -124,10 +125,10 @@ export type GetOffersResponse = {
}; };
export type Paging = { export type Paging = {
currPage: number; currentPage: number;
numOfItemsInPage: number; numOfItems: number;
numOfPages: number; numOfPages: number;
totalNumberOfOffers: number; totalItems: number;
}; };
export type CreateOfferProfileResponse = { export type CreateOfferProfileResponse = {
@ -136,7 +137,7 @@ export type CreateOfferProfileResponse = {
}; };
export type OffersDiscussion = { export type OffersDiscussion = {
data: Array<OReply>; data: Array<Reply>;
}; };
export type ProfileAnalysis = { export type ProfileAnalysis = {
@ -182,4 +183,4 @@ export type AddToProfileResponse = {
id: string; id: string;
profileName: string; profileName: string;
userId: string; userId: string;
}; };

Loading…
Cancel
Save