[offers][feat] Create Offer Analysis API

pull/379/head
BryannYeap 3 years ago
parent 7b51ee7e88
commit b7e0d8ff90

@ -4,7 +4,7 @@ import { trpc } from '~/utils/trpc';
function Test() {
const [createdData, setCreatedData] = useState('');
const [error, setError] = useState("");
const [error, setError] = useState('');
const createMutation = trpc.useMutation(['offers.profile.create'], {
onError(err: any) {
@ -15,14 +15,17 @@ function Test() {
},
});
const addToUserProfileMutation = trpc.useMutation(['offers.profile.addToUserProfile'], {
const addToUserProfileMutation = trpc.useMutation(
['offers.profile.addToUserProfile'],
{
onError(err: any) {
alert(err);
},
onSuccess(data) {
setCreatedData(JSON.stringify(data));
},
})
},
);
const deleteCommentMutation = trpc.useMutation(['offers.comments.delete'], {
onError(err: any) {
@ -38,9 +41,9 @@ function Test() {
id: 'cl97fprun001j7iyg6ev9x983',
profileId: 'cl96stky5002ew32gx2kale2x',
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1',
userId: 'cl97dl51k001e7iygd5v5gt58'
})
}
userId: 'cl97dl51k001e7iygd5v5gt58',
});
};
const updateCommentMutation = trpc.useMutation(['offers.comments.update'], {
onError(err: any) {
@ -56,9 +59,9 @@ function Test() {
id: 'cl97fxb0y001l7iyg14sdobt2',
message: 'hello hello',
profileId: 'cl96stky5002ew32gx2kale2x',
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba'
})
}
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
});
};
const createCommentMutation = trpc.useMutation(['offers.comments.create'], {
onError(err: any) {
@ -74,16 +77,16 @@ function Test() {
message: 'hello',
profileId: 'cl96stky5002ew32gx2kale2x',
// UserId: 'cl97dl51k001e7iygd5v5gt58'
})
}
});
};
const handleLink = () => {
addToUserProfileMutation.mutate({
profileId: 'cl96stky5002ew32gx2kale2x',
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
userId: 'cl97dl51k001e7iygd5v5gt58'
})
}
userId: 'cl97dl51k001e7iygd5v5gt58',
});
};
const handleClick = () => {
createMutation.mutate({
@ -126,7 +129,6 @@ function Test() {
},
offers: [
{
OffersFullTime: {
baseSalary: {
currency: 'SGD',
@ -189,23 +191,30 @@ function Test() {
};
const profileId = 'cl96stky5002ew32gx2kale2x'; // Remember to change this filed after testing deleting
const data = trpc.useQuery([
const data = trpc.useQuery(
[
`offers.profile.listOne`,
{
profileId,
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
token:
'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
},
], {
],
{
onError(err) {
setError(err.shape?.message || "")
}
});
setError(err.shape?.message || '');
},
},
);
const replies = trpc.useQuery(['offers.comments.getComments', {profileId: 'cl96stky5002ew32gx2kale2x'}], {
const replies = trpc.useQuery(
['offers.comments.getComments', { profileId: 'cl96stky5002ew32gx2kale2x' }],
{
onError(err) {
setError(err.shape?.message || "")
setError(err.shape?.message || '');
},
});
},
);
const deleteMutation = trpc.useMutation(['offers.profile.delete']);
@ -230,357 +239,363 @@ function Test() {
background: {
educations: [
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
endDate: new Date("2018-09-30T07:58:54.000Z"),
field: "Computer Science",
id: "cl96stky6002gw32gey2ffawd",
school: "National University of Singapore",
startDate: new Date("2014-09-30T07:58:54.000Z"),
type: "Bachelors"
}
backgroundId: 'cl96stky6002fw32g6vj4meyr',
endDate: new Date('2018-09-30T07:58:54.000Z'),
field: 'Computer Science',
id: 'cl96stky6002gw32gey2ffawd',
school: 'National University of Singapore',
startDate: new Date('2014-09-30T07:58:54.000Z'),
type: 'Bachelors',
},
],
experiences: [
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
backgroundId: 'cl96stky6002fw32g6vj4meyr',
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
durationInMonths: 24,
id: "cl96stky6002iw32gpt6t87s2",
jobType: "FULLTIME",
level: "Junior",
id: 'cl96stky6002iw32gpt6t87s2',
jobType: 'FULLTIME',
level: 'Junior',
monthlySalary: null,
monthlySalaryId: null,
specialization: "Front End",
title: "Software Engineer",
specialization: 'Front End',
title: 'Software Engineer',
totalCompensation: {
currency: "SGD",
id: "cl96stky6002jw32g73svfacr",
value: 104100
currency: 'SGD',
id: 'cl96stky6002jw32g73svfacr',
value: 104100,
},
totalCompensationId: 'cl96stky6002jw32g73svfacr',
},
totalCompensationId: "cl96stky6002jw32g73svfacr"
}
],
id: "cl96stky6002fw32g6vj4meyr",
offersProfileId: "cl96stky5002ew32gx2kale2x",
id: 'cl96stky6002fw32g6vj4meyr',
offersProfileId: 'cl96stky5002ew32gx2kale2x',
specificYoes: [
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Backend",
id: "cl96t7890004tw32g5in3px5j",
yoe: 2
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Backend',
id: 'cl96t7890004tw32g5in3px5j',
yoe: 2,
},
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Backend",
id: "cl96tb87x004xw32gnu17jbzv",
yoe: 2
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Backend',
id: 'cl96tb87x004xw32gnu17jbzv',
yoe: 2,
},
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Backend",
id: "cl976t39z00007iygt3np3cgo",
yoe: 2
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Backend',
id: 'cl976t39z00007iygt3np3cgo',
yoe: 2,
},
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Front End",
id: "cl96stky7002mw32gn4jc7uml",
yoe: 2
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Front End',
id: 'cl96stky7002mw32gn4jc7uml',
yoe: 2,
},
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Full Stack",
id: "cl96stky7002nw32gpprghtxr",
yoe: 2
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Full Stack',
id: 'cl96stky7002nw32gpprghtxr',
yoe: 2,
},
{
backgroundId: "cl96stky6002fw32g6vj4meyr",
domain: "Backend",
id: "cl976we5h000p7iygiomdo9fh",
yoe: 2
}
backgroundId: 'cl96stky6002fw32g6vj4meyr',
domain: 'Backend',
id: 'cl976we5h000p7iygiomdo9fh',
yoe: 2,
},
],
totalYoe: 6
totalYoe: 6,
},
createdAt: "2022-10-13T08:28:13.518Z",
createdAt: '2022-10-13T08:28:13.518Z',
discussion: [],
id: "cl96stky5002ew32gx2kale2x",
id: 'cl96stky5002ew32gx2kale2x',
isEditable: true,
offers: [
{
OffersFullTime: {
baseSalary: {
currency: "SGD",
id: "cl976t4de00067iyg3pjir7k9",
value: 1999999999
currency: 'SGD',
id: 'cl976t4de00067iyg3pjir7k9',
value: 1999999999,
},
baseSalaryId: "cl976t4de00067iyg3pjir7k9",
baseSalaryId: 'cl976t4de00067iyg3pjir7k9',
bonus: {
currency: "SGD",
id: "cl976t4de00087iygcnlmh8aw",
value: 1410065407
},
bonusId: "cl976t4de00087iygcnlmh8aw",
id: "cl976t4de00057iygq3ktce3v",
level: "EXPERT",
specialization: "FRONTEND",
currency: 'SGD',
id: 'cl976t4de00087iygcnlmh8aw',
value: 1410065407,
},
bonusId: 'cl976t4de00087iygcnlmh8aw',
id: 'cl976t4de00057iygq3ktce3v',
level: 'EXPERT',
specialization: 'FRONTEND',
stocks: {
currency: "SGD",
id: "cl976t4df000a7iygkrsgr1xh",
value: -558038585
currency: 'SGD',
id: 'cl976t4df000a7iygkrsgr1xh',
value: -558038585,
},
stocksId: "cl976t4df000a7iygkrsgr1xh",
title: "Software Engineer",
stocksId: 'cl976t4df000a7iygkrsgr1xh',
title: 'Software Engineer',
totalCompensation: {
currency: "SGD",
id: "cl976t4df000c7iyg73ryf5uw",
value: 55555555
currency: 'SGD',
id: 'cl976t4df000c7iyg73ryf5uw',
value: 55555555,
},
totalCompensationId: "cl976t4df000c7iyg73ryf5uw"
totalCompensationId: 'cl976t4df000c7iyg73ryf5uw',
},
OffersIntern: null,
comments: "this IS SO IEUHDAEUIGDI",
comments: 'this IS SO IEUHDAEUIGDI',
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
id: "cl976t4de00047iygl0zbce11",
jobType: "FULLTIME",
location: "Singapore, Singapore",
monthYearReceived: new Date("2022-09-30T07:58:54.000Z"),
negotiationStrategy: "Charmed the guy with my face",
offersFullTimeId: "cl976t4de00057iygq3ktce3v",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
id: 'cl976t4de00047iygl0zbce11',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl976t4de00057iygq3ktce3v',
offersInternId: null,
profileId: "cl96stky5002ew32gx2kale2x"
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: {
currency: "SGD",
id: "cl96stky80033w32gxw5goc4z",
value: 84000
currency: 'SGD',
id: 'cl96stky80033w32gxw5goc4z',
value: 84000,
},
baseSalaryId: "cl96stky80033w32gxw5goc4z",
baseSalaryId: 'cl96stky80033w32gxw5goc4z',
bonus: {
currency: "SGD",
id: "cl96stky80035w32gajjwdo1p",
value: 123456789
},
bonusId: "cl96stky80035w32gajjwdo1p",
id: "cl96stky80032w32gep9ovgj3",
level: "Junior",
specialization: "Front End",
currency: 'SGD',
id: 'cl96stky80035w32gajjwdo1p',
value: 123456789,
},
bonusId: 'cl96stky80035w32gajjwdo1p',
id: 'cl96stky80032w32gep9ovgj3',
level: 'Junior',
specialization: 'Front End',
stocks: {
currency: "SGD",
id: "cl96stky90037w32gu04t6ybh",
value: 100
currency: 'SGD',
id: 'cl96stky90037w32gu04t6ybh',
value: 100,
},
stocksId: "cl96stky90037w32gu04t6ybh",
title: "Software Engineer",
stocksId: 'cl96stky90037w32gu04t6ybh',
title: 'Software Engineer',
totalCompensation: {
currency: "SGD",
id: "cl96stky90039w32glbpktd0o",
value: 104100
currency: 'SGD',
id: 'cl96stky90039w32glbpktd0o',
value: 104100,
},
totalCompensationId: "cl96stky90039w32glbpktd0o"
totalCompensationId: 'cl96stky90039w32glbpktd0o',
},
OffersIntern: null,
comments: null,
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
id: "cl96stky80031w32gau9mu1gs",
jobType: "FULLTIME",
location: "Singapore, Singapore",
monthYearReceived: new Date("2022-09-30T07:58:54.000Z"),
negotiationStrategy: "Leveraged having million offers",
offersFullTimeId: "cl96stky80032w32gep9ovgj3",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
id: 'cl96stky80031w32gau9mu1gs',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Leveraged having million offers',
offersFullTimeId: 'cl96stky80032w32gep9ovgj3',
offersInternId: null,
profileId: "cl96stky5002ew32gx2kale2x"
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: {
currency: "SGD",
id: "cl96stky9003dw32gcvqbijlo",
value: 1
currency: 'SGD',
id: 'cl96stky9003dw32gcvqbijlo',
value: 1,
},
baseSalaryId: "cl96stky9003dw32gcvqbijlo",
baseSalaryId: 'cl96stky9003dw32gcvqbijlo',
bonus: {
currency: "SGD",
id: "cl96stky9003fw32goc3zqxwr",
value: 0
},
bonusId: "cl96stky9003fw32goc3zqxwr",
id: "cl96stky9003cw32g5v10izfu",
level: "Senior",
specialization: "Front End",
currency: 'SGD',
id: 'cl96stky9003fw32goc3zqxwr',
value: 0,
},
bonusId: 'cl96stky9003fw32goc3zqxwr',
id: 'cl96stky9003cw32g5v10izfu',
level: 'Senior',
specialization: 'Front End',
stocks: {
currency: "SGD",
id: "cl96stky9003hw32g1lbbkqqr",
value: 999999
currency: 'SGD',
id: 'cl96stky9003hw32g1lbbkqqr',
value: 999999,
},
stocksId: "cl96stky9003hw32g1lbbkqqr",
title: "Software Engineer DOG",
stocksId: 'cl96stky9003hw32g1lbbkqqr',
title: 'Software Engineer DOG',
totalCompensation: {
currency: "SGD",
id: "cl96stky9003jw32gzumcoi7v",
value: 999999
currency: 'SGD',
id: 'cl96stky9003jw32gzumcoi7v',
value: 999999,
},
totalCompensationId: "cl96stky9003jw32gzumcoi7v"
totalCompensationId: 'cl96stky9003jw32gzumcoi7v',
},
OffersIntern: null,
comments: null,
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
id: "cl96stky9003bw32gc3l955vr",
jobType: "FULLTIME",
location: "Singapore, Singapore",
monthYearReceived: new Date("2022-09-30T07:58:54.000Z"),
negotiationStrategy: "LOst out having multiple offers",
offersFullTimeId: "cl96stky9003cw32g5v10izfu",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
id: 'cl96stky9003bw32gc3l955vr',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'LOst out having multiple offers',
offersFullTimeId: 'cl96stky9003cw32g5v10izfu',
offersInternId: null,
profileId: "cl96stky5002ew32gx2kale2x"
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: {
currency: "SGD",
id: "cl976wf28000v7iygmk1b7qaq",
value: 1999999999
currency: 'SGD',
id: 'cl976wf28000v7iygmk1b7qaq',
value: 1999999999,
},
baseSalaryId: "cl976wf28000v7iygmk1b7qaq",
baseSalaryId: 'cl976wf28000v7iygmk1b7qaq',
bonus: {
currency: "SGD",
id: "cl976wf28000x7iyg63w7kcli",
value: 1410065407
},
bonusId: "cl976wf28000x7iyg63w7kcli",
id: "cl976wf28000u7iyg6euei8e9",
level: "EXPERT",
specialization: "FRONTEND",
currency: 'SGD',
id: 'cl976wf28000x7iyg63w7kcli',
value: 1410065407,
},
bonusId: 'cl976wf28000x7iyg63w7kcli',
id: 'cl976wf28000u7iyg6euei8e9',
level: 'EXPERT',
specialization: 'FRONTEND',
stocks: {
currency: "SGD",
id: "cl976wf28000z7iyg9ivun6ap",
value: 111222333
currency: 'SGD',
id: 'cl976wf28000z7iyg9ivun6ap',
value: 111222333,
},
stocksId: "cl976wf28000z7iyg9ivun6ap",
title: "Software Engineer",
stocksId: 'cl976wf28000z7iyg9ivun6ap',
title: 'Software Engineer',
totalCompensation: {
currency: "SGD",
id: "cl976wf2800117iygmzsc0xit",
value: 55555555
currency: 'SGD',
id: 'cl976wf2800117iygmzsc0xit',
value: 55555555,
},
totalCompensationId: "cl976wf2800117iygmzsc0xit"
totalCompensationId: 'cl976wf2800117iygmzsc0xit',
},
OffersIntern: null,
comments: "this IS SO COOL",
comments: 'this IS SO COOL',
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
id: "cl976wf28000t7iyga4noyz7s",
jobType: "FULLTIME",
location: "Singapore, Singapore",
monthYearReceived: new Date("2022-09-30T07:58:54.000Z"),
negotiationStrategy: "Charmed the guy with my face",
offersFullTimeId: "cl976wf28000u7iyg6euei8e9",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
id: 'cl976wf28000t7iyga4noyz7s',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl976wf28000u7iyg6euei8e9',
offersInternId: null,
profileId: "cl96stky5002ew32gx2kale2x"
profileId: 'cl96stky5002ew32gx2kale2x',
},
{
OffersFullTime: {
baseSalary: {
currency: "SGD",
id: "cl96tbb3o0053w32gz11paaxu",
value: 1999999999
currency: 'SGD',
id: 'cl96tbb3o0053w32gz11paaxu',
value: 1999999999,
},
baseSalaryId: "cl96tbb3o0053w32gz11paaxu",
baseSalaryId: 'cl96tbb3o0053w32gz11paaxu',
bonus: {
currency: "SGD",
id: "cl96tbb3o0055w32gpyqgz5hx",
value: 1410065407
},
bonusId: "cl96tbb3o0055w32gpyqgz5hx",
id: "cl96tbb3o0052w32guguajzin",
level: "EXPERT",
specialization: "FRONTEND",
currency: 'SGD',
id: 'cl96tbb3o0055w32gpyqgz5hx',
value: 1410065407,
},
bonusId: 'cl96tbb3o0055w32gpyqgz5hx',
id: 'cl96tbb3o0052w32guguajzin',
level: 'EXPERT',
specialization: 'FRONTEND',
stocks: {
currency: "SGD",
id: "cl96tbb3o0057w32gu4nyxguf",
value: 500
currency: 'SGD',
id: 'cl96tbb3o0057w32gu4nyxguf',
value: 500,
},
stocksId: "cl96tbb3o0057w32gu4nyxguf",
title: "Software Engineer",
stocksId: 'cl96tbb3o0057w32gu4nyxguf',
title: 'Software Engineer',
totalCompensation: {
currency: "SGD",
id: "cl96tbb3o0059w32gm3iy1zk4",
value: 55555555
currency: 'SGD',
id: 'cl96tbb3o0059w32gm3iy1zk4',
value: 55555555,
},
totalCompensationId: "cl96tbb3o0059w32gm3iy1zk4"
totalCompensationId: 'cl96tbb3o0059w32gm3iy1zk4',
},
OffersIntern: null,
comments: "this rocks",
comments: 'this rocks',
company: {
createdAt: new Date("2022-10-12T16:19:05.196Z"),
description: "Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.",
id: "cl95u79f000007im531ysjg79",
logoUrl: "https://logo.clearbit.com/meta.com",
name: "Meta",
slug: "meta",
updatedAt: new Date("2022-10-12T16:19:05.196Z")
},
companyId: "cl95u79f000007im531ysjg79",
id: "cl96tbb3o0051w32gjrpaiiit",
jobType: "FULLTIME",
location: "Singapore, Singapore",
monthYearReceived: new Date("2022-09-30T07:58:54.000Z"),
negotiationStrategy: "Charmed the guy with my face",
offersFullTimeId: "cl96tbb3o0052w32guguajzin",
createdAt: new Date('2022-10-12T16:19:05.196Z'),
description:
'Meta Platforms, Inc., doing business as Meta and formerly named Facebook, Inc., and TheFacebook, Inc., is an American multinational technology conglomerate based in Menlo Park, California. The company owns Facebook, Instagram, and WhatsApp, among other products and services.',
id: 'cl95u79f000007im531ysjg79',
logoUrl: 'https://logo.clearbit.com/meta.com',
name: 'Meta',
slug: 'meta',
updatedAt: new Date('2022-10-12T16:19:05.196Z'),
},
companyId: 'cl95u79f000007im531ysjg79',
id: 'cl96tbb3o0051w32gjrpaiiit',
jobType: 'FULLTIME',
location: 'Singapore, Singapore',
monthYearReceived: new Date('2022-09-30T07:58:54.000Z'),
negotiationStrategy: 'Charmed the guy with my face',
offersFullTimeId: 'cl96tbb3o0052w32guguajzin',
offersInternId: null,
profileId: "cl96stky5002ew32gx2kale2x"
}
profileId: 'cl96stky5002ew32gx2kale2x',
},
],
profileName: "ailing bryann stuart ziqing",
token: "afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba",
userId: null
profileName: 'ailing bryann stuart ziqing',
token: 'afca11e436d21bde24543718fa957c6c625335439dc504f24ee35eae7b5ef1ba',
userId: null,
});
}
};
return (
<>

@ -6,12 +6,11 @@ function Test() {
const data = trpc.useQuery([
'offers.list',
{
companyId: 'cl95u79f000007im531ysjg79',
limit: 20,
limit: 100,
location: 'Singapore, Singapore',
offset: 0,
sortBy: '-monthYearReceived',
yoeCategory: 1,
sortBy: '-totalYoe',
yoeCategory: 2,
},
]);

@ -0,0 +1,14 @@
import React from 'react';
import { trpc } from '~/utils/trpc';
function profileAnalysis() {
const analysis = trpc.useQuery([
'offers.analysis.generate',
{ profileId: 'cl96stky5002ew32gx2kale2x' },
]);
return <div>{JSON.stringify(analysis.data)}</div>;
}
export default profileAnalysis;

@ -3,6 +3,7 @@ import superjson from 'superjson';
import { companiesRouter } from './companies-router';
import { createRouter } from './context';
import { offersRouter } from './offers/offers';
import { offersAnalysisRouter } from './offers/offers-analysis-router';
import { offersCommentsRouter } from './offers/offers-comments-router';
import { offersProfileRouter } from './offers/offers-profile-router';
import { protectedExampleRouter } from './protected-example-router';
@ -38,6 +39,7 @@ export const appRouter = createRouter()
.merge('questions.questions.', questionsQuestionRouter)
.merge('offers.', offersRouter)
.merge('offers.profile.', offersProfileRouter)
.merge('offers.analysis.', offersAnalysisRouter)
.merge('offers.comments.', offersCommentsRouter);
// Export type definition of API

@ -0,0 +1,264 @@
import { z } from 'zod';
import type {
Company,
OffersBackground,
OffersCurrency,
OffersFullTime,
OffersIntern,
OffersOffer,
OffersProfile,
} from '@prisma/client';
import { TRPCError } from '@trpc/server';
import { createRouter } from '../context';
const binarySearchOfferPercentile = (
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 };
},
similarOffers: Array<any> | string,
) => {
let start = 0;
let end = similarOffers.length - 1;
while (start <= end) {
const mid = Math.floor((start + end) / 2);
if (similarOffers[mid].id === offer.id) {
return mid;
}
if (offer.id < similarOffers[mid].id) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return -1;
};
export const offersAnalysisRouter = createRouter().query('generate', {
input: z.object({
profileId: z.string(),
}),
async resolve({ ctx, input }) {
const offers = await ctx.prisma.offersOffer.findMany({
include: {
OffersFullTime: {
include: {
baseSalary: true,
bonus: true,
stocks: true,
totalCompensation: true,
},
},
OffersIntern: {
include: {
monthlySalary: true,
},
},
company: true,
profile: {
include: {
background: true,
},
},
},
orderBy: [
{
OffersFullTime: {
totalCompensation: {
value: 'desc',
},
},
},
{
OffersIntern: {
monthlySalary: {
value: 'desc',
},
},
},
],
where: {
profileId: input.profileId,
},
});
if (!offers || offers.length === 0) {
throw new TRPCError({
code: 'NOT_FOUND',
message: 'No offers found on this profile',
});
}
const overallHighestOffer = offers[0];
// TODO: Shift yoe to background to make it mandatory
if (
!overallHighestOffer.profile.background ||
!overallHighestOffer.profile.background.totalYoe
) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Cannot analyse without YOE',
});
}
const yoe = overallHighestOffer.profile.background.totalYoe as number;
let similarOffers = await ctx.prisma.offersOffer.findMany({
include: {
OffersFullTime: {
include: {
totalCompensation: true,
},
},
OffersIntern: {
include: {
monthlySalary: true,
},
},
company: true,
profile: {
include: {
background: {
include: {
experiences: {
include: {
company: true,
},
},
},
},
},
},
},
orderBy: [
{
OffersFullTime: {
totalCompensation: {
value: 'desc',
},
},
},
{
OffersIntern: {
monthlySalary: {
value: 'desc',
},
},
},
],
where: {
AND: [
{
location: overallHighestOffer.location,
},
{
OR: [
{
OffersFullTime: {
level: overallHighestOffer.OffersFullTime?.level,
specialization:
overallHighestOffer.OffersFullTime?.specialization,
},
OffersIntern: {
specialization:
overallHighestOffer.OffersIntern?.specialization,
},
},
],
},
{
profile: {
background: {
AND: [
{
totalYoe: {
gte: Math.max(yoe - 1, 0),
lte: yoe + 1,
},
},
],
},
},
},
],
},
});
let similarCompanyOffers = similarOffers.filter(
(offer) => offer.companyId === overallHighestOffer.companyId,
);
// CALCULATE PERCENTILES
const highestOfferAgainstOverallIndex = binarySearchOfferPercentile(
overallHighestOffer,
similarOffers,
);
const highestOfferAgainstOverallPercentile =
highestOfferAgainstOverallIndex / similarOffers.length;
const highestOfferAgainstCompanyIndex = binarySearchOfferPercentile(
overallHighestOffer,
similarCompanyOffers,
);
const highestOfferAgainstCompanyPercentile =
highestOfferAgainstCompanyIndex / similarCompanyOffers.length;
// FIND TOP >=90 PERCENTILE OFFERS
similarOffers = similarOffers.filter(
(offer) => offer.id !== overallHighestOffer.id,
);
similarCompanyOffers = similarCompanyOffers.filter(
(offer) => offer.id !== overallHighestOffer.id,
);
const similarOffersCount = similarOffers.length;
const similarOffers90PercentileIndex =
Math.floor(similarOffersCount * 0.9) - 1;
const topPercentileOffers =
similarOffersCount > 1
? similarOffers.slice(
similarOffers90PercentileIndex,
similarOffers90PercentileIndex + 2,
)
: similarOffers;
const similarCompanyOffersCount = similarCompanyOffers.length;
const similarCompanyOffers90PercentileIndex =
Math.floor(similarCompanyOffersCount * 0.9) - 1;
const topPercentileCompanyOffers =
similarCompanyOffersCount > 1
? similarCompanyOffers.slice(
similarCompanyOffers90PercentileIndex,
similarCompanyOffers90PercentileIndex + 2,
)
: similarCompanyOffers;
return {
company: {
highestOfferAgainstCompanyPercentile,
similarCompanyOffersCount,
topPercentileCompanyOffers,
},
overall: {
highestOfferAgainstOverallPercentile,
similarOffersCount,
topPercentileOffers,
},
overallHighestOffer,
};
},
});

@ -16,8 +16,8 @@ const getYoeRange = (yoeCategory: number) => {
: yoeCategoryMap[yoeCategory] === 'Mid'
? { maxYoe: 7, minYoe: 4 }
: yoeCategoryMap[yoeCategory] === 'Senior'
? { maxYoe: null, minYoe: 8 }
: null;
? { maxYoe: 100, minYoe: 8 }
: null; // Internship
};
const ascOrder = '+';
@ -35,7 +35,7 @@ export const offersRouter = createRouter().query('list', {
companyId: z.string().nullish(),
dateEnd: z.date().nullish(),
dateStart: z.date().nullish(),
limit: z.number().nonnegative(),
limit: z.number().positive(),
location: z.string(),
offset: z.number().nonnegative(),
salaryMax: z.number().nullish(),
@ -43,9 +43,13 @@ export const offersRouter = createRouter().query('list', {
sortBy: z.string().regex(createSortByValidationRegex()).nullish(),
title: z.string().nullish(),
yoeCategory: z.number().min(0).max(3),
yoeMax: z.number().max(100).nullish(),
yoeMin: z.number().min(0).nullish(),
}),
async resolve({ ctx, input }) {
const yoeRange = getYoeRange(input.yoeCategory);
const yoeMin = input.yoeMin ? input.yoeMin : yoeRange?.minYoe;
const yoeMax = input.yoeMax ? input.yoeMax : yoeRange?.maxYoe;
let data = !yoeRange
? await ctx.prisma.offersOffer.findMany({
@ -89,68 +93,8 @@ export const offersRouter = createRouter().query('list', {
],
},
})
: yoeRange.maxYoe
? await ctx.prisma.offersOffer.findMany({
// Junior, Mid
include: {
OffersFullTime: {
include: {
baseSalary: true,
bonus: true,
stocks: true,
totalCompensation: true,
},
},
OffersIntern: {
include: {
monthlySalary: true,
},
},
company: true,
profile: {
include: {
background: true,
},
},
},
where: {
AND: [
{
location: input.location,
},
{
OffersIntern: {
is: null,
},
},
{
OffersFullTime: {
isNot: null,
},
},
{
profile: {
background: {
totalYoe: {
gte: yoeRange.minYoe,
},
},
},
},
{
profile: {
background: {
totalYoe: {
gte: yoeRange.maxYoe,
},
},
},
},
],
},
})
: await ctx.prisma.offersOffer.findMany({
// Senior
// Junior, Mid, Senior
include: {
OffersFullTime: {
include: {
@ -191,7 +135,8 @@ export const offersRouter = createRouter().query('list', {
profile: {
background: {
totalYoe: {
gte: yoeRange.minYoe,
gte: yoeMin,
lte: yoeMax,
},
},
},

Loading…
Cancel
Save