@ -10,7 +10,10 @@ import {
} from '~/mappers/offers-mappers' ;
} from '~/mappers/offers-mappers' ;
import { baseCurrencyString } from '~/utils/offers/currency' ;
import { baseCurrencyString } from '~/utils/offers/currency' ;
import { convert } from '~/utils/offers/currency/currencyExchange' ;
import { convert } from '~/utils/offers/currency/currencyExchange' ;
import { generateRandomName , generateRandomStringForToken } from '~/utils/offers/randomGenerator' ;
import {
generateRandomName ,
generateRandomStringForToken ,
} from '~/utils/offers/randomGenerator' ;
import { createValidationRegex } from '~/utils/offers/zodRegex' ;
import { createValidationRegex } from '~/utils/offers/zodRegex' ;
import { createRouter } from '../context' ;
import { createRouter } from '../context' ;
@ -48,7 +51,6 @@ const offer = z.object({
bonusId : z.string ( ) . nullish ( ) ,
bonusId : z.string ( ) . nullish ( ) ,
id : z.string ( ) . optional ( ) ,
id : z.string ( ) . optional ( ) ,
level : z.string ( ) . nullish ( ) ,
level : z.string ( ) . nullish ( ) ,
specialization : z.string ( ) ,
stocks : valuation.nullish ( ) ,
stocks : valuation.nullish ( ) ,
stocksId : z.string ( ) . nullish ( ) ,
stocksId : z.string ( ) . nullish ( ) ,
title : z.string ( ) ,
title : z.string ( ) ,
@ -62,7 +64,6 @@ const offer = z.object({
id : z.string ( ) . optional ( ) ,
id : z.string ( ) . optional ( ) ,
internshipCycle : z.string ( ) . nullish ( ) ,
internshipCycle : z.string ( ) . nullish ( ) ,
monthlySalary : valuation.nullish ( ) ,
monthlySalary : valuation.nullish ( ) ,
specialization : z.string ( ) ,
startYear : z.number ( ) . nullish ( ) ,
startYear : z.number ( ) . nullish ( ) ,
title : z.string ( ) ,
title : z.string ( ) ,
totalCompensation : valuation.nullish ( ) , // Full time
totalCompensation : valuation.nullish ( ) , // Full time
@ -86,7 +87,6 @@ const experience = z.object({
location : z.string ( ) . nullish ( ) ,
location : z.string ( ) . nullish ( ) ,
monthlySalary : valuation.nullish ( ) ,
monthlySalary : valuation.nullish ( ) ,
monthlySalaryId : z.string ( ) . nullish ( ) ,
monthlySalaryId : z.string ( ) . nullish ( ) ,
specialization : z.string ( ) . nullish ( ) ,
title : z.string ( ) . nullish ( ) ,
title : z.string ( ) . nullish ( ) ,
totalCompensation : valuation.nullish ( ) ,
totalCompensation : valuation.nullish ( ) ,
totalCompensationId : z.string ( ) . nullish ( ) ,
totalCompensationId : z.string ( ) . nullish ( ) ,
@ -300,7 +300,6 @@ export const offersProfileRouter = createRouter()
durationInMonths : x.durationInMonths ,
durationInMonths : x.durationInMonths ,
jobType : x.jobType ,
jobType : x.jobType ,
level : x.level ,
level : x.level ,
specialization : x.specialization ,
title : x.title ,
title : x.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {
@ -321,7 +320,6 @@ export const offersProfileRouter = createRouter()
jobType : x.jobType ,
jobType : x.jobType ,
level : x.level ,
level : x.level ,
location : x.location ,
location : x.location ,
specialization : x.specialization ,
title : x.title ,
title : x.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {
@ -363,7 +361,6 @@ export const offersProfileRouter = createRouter()
value : x.monthlySalary.value ,
value : x.monthlySalary.value ,
} ,
} ,
} ,
} ,
specialization : x.specialization ,
title : x.title ,
title : x.title ,
} ;
} ;
}
}
@ -382,7 +379,6 @@ export const offersProfileRouter = createRouter()
value : x.monthlySalary.value ,
value : x.monthlySalary.value ,
} ,
} ,
} ,
} ,
specialization : x.specialization ,
title : x.title ,
title : x.title ,
} ;
} ;
}
}
@ -442,7 +438,6 @@ export const offersProfileRouter = createRouter()
value : x.offersIntern.monthlySalary.value ,
value : x.offersIntern.monthlySalary.value ,
} ,
} ,
} ,
} ,
specialization : x.offersIntern.specialization ,
startYear : x.offersIntern.startYear ,
startYear : x.offersIntern.startYear ,
title : x.offersIntern.title ,
title : x.offersIntern.title ,
} ,
} ,
@ -452,17 +447,10 @@ export const offersProfileRouter = createRouter()
if (
if (
x . jobType === JobType . FULLTIME &&
x . jobType === JobType . FULLTIME &&
x . offersFullTime &&
x . offersFullTime &&
x . offersFullTime . baseSalary ? . currency != null &&
x . offersFullTime . baseSalary ? . value != null &&
x . offersFullTime . bonus ? . currency != null &&
x . offersFullTime . bonus ? . value != null &&
x . offersFullTime . stocks ? . currency != null &&
x . offersFullTime . stocks ? . value != null &&
x . offersFullTime . totalCompensation ? . currency != null &&
x . offersFullTime . totalCompensation ? . currency != null &&
x . offersFullTime . totalCompensation ? . value != null &&
x . offersFullTime . totalCompensation ? . value != null &&
x . offersFullTime . level != null &&
x . offersFullTime . level != null &&
x . offersFullTime . title != null &&
x . offersFullTime . title != null
x . offersFullTime . specialization != null
) {
) {
return {
return {
comments : x.comments ,
comments : x.comments ,
@ -477,44 +465,53 @@ export const offersProfileRouter = createRouter()
negotiationStrategy : x.negotiationStrategy ,
negotiationStrategy : x.negotiationStrategy ,
offersFullTime : {
offersFullTime : {
create : {
create : {
baseSalary : {
baseSalary :
create : {
x . offersFullTime ? . baseSalary != null
baseCurrency : baseCurrencyString ,
? {
baseValue : await convert (
create : {
x . offersFullTime . baseSalary . value ,
baseCurrency : baseCurrencyString ,
x . offersFullTime . baseSalary . currency ,
baseValue : await convert (
baseCurrencyString ,
x . offersFullTime . baseSalary . value ,
) ,
x . offersFullTime . baseSalary . currency ,
currency : x.offersFullTime.baseSalary.currency ,
baseCurrencyString ,
value : x.offersFullTime.baseSalary.value ,
) ,
} ,
currency :
} ,
x . offersFullTime . baseSalary . currency ,
bonus : {
value : x.offersFullTime.baseSalary.value ,
create : {
} ,
baseCurrency : baseCurrencyString ,
}
baseValue : await convert (
: undefined ,
x . offersFullTime . bonus . value ,
bonus :
x . offersFullTime . bonus . currency ,
x . offersFullTime ? . bonus != null
baseCurrencyString ,
? {
) ,
create : {
currency : x.offersFullTime.bonus.currency ,
baseCurrency : baseCurrencyString ,
value : x.offersFullTime.bonus.value ,
baseValue : await convert (
} ,
x . offersFullTime . bonus . value ,
} ,
x . offersFullTime . bonus . currency ,
baseCurrencyString ,
) ,
currency : x.offersFullTime.bonus.currency ,
value : x.offersFullTime.bonus.value ,
} ,
}
: undefined ,
level : x.offersFullTime.level ,
level : x.offersFullTime.level ,
specialization : x.offersFullTime.specialization ,
stocks :
stocks : {
x . offersFullTime ? . stocks != null
create : {
? {
baseCurrency : baseCurrencyString ,
create : {
baseValue : await convert (
baseCurrency : baseCurrencyString ,
x . offersFullTime . stocks . value ,
baseValue : await convert (
x . offersFullTime . stocks . currency ,
x . offersFullTime . stocks . value ,
baseCurrencyString ,
x . offersFullTime . stocks . currency ,
) ,
baseCurrencyString ,
currency : x.offersFullTime.stocks.currency ,
) ,
value : x.offersFullTime.stocks.value ,
currency : x.offersFullTime.stocks.currency ,
} ,
value : x.offersFullTime.stocks.value ,
} ,
} ,
}
: undefined ,
title : x.offersFullTime.title ,
title : x.offersFullTime.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {
@ -714,7 +711,6 @@ export const offersProfileRouter = createRouter()
companyId : exp.companyId , // TODO: check if can change with connect or whether there is a difference
companyId : exp.companyId , // TODO: check if can change with connect or whether there is a difference
durationInMonths : exp.durationInMonths ,
durationInMonths : exp.durationInMonths ,
level : exp.level ,
level : exp.level ,
specialization : exp.specialization ,
} ,
} ,
where : {
where : {
id : exp.id ,
id : exp.id ,
@ -821,7 +817,6 @@ export const offersProfileRouter = createRouter()
jobType : exp.jobType ,
jobType : exp.jobType ,
level : exp.level ,
level : exp.level ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {
@ -851,7 +846,6 @@ export const offersProfileRouter = createRouter()
jobType : exp.jobType ,
jobType : exp.jobType ,
level : exp.level ,
level : exp.level ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {
@ -887,7 +881,6 @@ export const offersProfileRouter = createRouter()
jobType : exp.jobType ,
jobType : exp.jobType ,
level : exp.level ,
level : exp.level ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -905,7 +898,6 @@ export const offersProfileRouter = createRouter()
jobType : exp.jobType ,
jobType : exp.jobType ,
level : exp.level ,
level : exp.level ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -945,7 +937,6 @@ export const offersProfileRouter = createRouter()
value : exp.monthlySalary.value ,
value : exp.monthlySalary.value ,
} ,
} ,
} ,
} ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -974,7 +965,6 @@ export const offersProfileRouter = createRouter()
value : exp.monthlySalary.value ,
value : exp.monthlySalary.value ,
} ,
} ,
} ,
} ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -997,7 +987,6 @@ export const offersProfileRouter = createRouter()
durationInMonths : exp.durationInMonths ,
durationInMonths : exp.durationInMonths ,
jobType : exp.jobType ,
jobType : exp.jobType ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -1014,7 +1003,6 @@ export const offersProfileRouter = createRouter()
durationInMonths : exp.durationInMonths ,
durationInMonths : exp.durationInMonths ,
jobType : exp.jobType ,
jobType : exp.jobType ,
location : exp.location ,
location : exp.location ,
specialization : exp.specialization ,
title : exp.title ,
title : exp.title ,
} ,
} ,
} ,
} ,
@ -1121,7 +1109,6 @@ export const offersProfileRouter = createRouter()
data : {
data : {
internshipCycle :
internshipCycle :
offerToUpdate . offersIntern . internshipCycle ? ? undefined ,
offerToUpdate . offersIntern . internshipCycle ? ? undefined ,
specialization : offerToUpdate.offersIntern.specialization ,
startYear : offerToUpdate.offersIntern.startYear ? ? undefined ,
startYear : offerToUpdate.offersIntern.startYear ? ? undefined ,
title : offerToUpdate.offersIntern.title ,
title : offerToUpdate.offersIntern.title ,
} ,
} ,
@ -1150,7 +1137,6 @@ export const offersProfileRouter = createRouter()
await ctx . prisma . offersFullTime . update ( {
await ctx . prisma . offersFullTime . update ( {
data : {
data : {
level : offerToUpdate.offersFullTime.level ? ? undefined ,
level : offerToUpdate.offersFullTime.level ? ? undefined ,
specialization : offerToUpdate.offersFullTime.specialization ,
title : offerToUpdate.offersFullTime.title ,
title : offerToUpdate.offersFullTime.title ,
} ,
} ,
where : {
where : {
@ -1174,7 +1160,7 @@ export const offersProfileRouter = createRouter()
} ,
} ,
} ) ;
} ) ;
}
}
if ( offerToUpdate . offersFullTime . bonus ) {
if ( offerToUpdate . offersFullTime . bonus != null ) {
await ctx . prisma . offersCurrency . update ( {
await ctx . prisma . offersCurrency . update ( {
data : {
data : {
baseCurrency : baseCurrencyString ,
baseCurrency : baseCurrencyString ,
@ -1191,7 +1177,7 @@ export const offersProfileRouter = createRouter()
} ,
} ,
} ) ;
} ) ;
}
}
if ( offerToUpdate . offersFullTime . stocks ) {
if ( offerToUpdate . offersFullTime . stocks != null ) {
await ctx . prisma . offersCurrency . update ( {
await ctx . prisma . offersCurrency . update ( {
data : {
data : {
baseCurrency : baseCurrencyString ,
baseCurrency : baseCurrencyString ,
@ -1269,8 +1255,6 @@ export const offersProfileRouter = createRouter()
offerToUpdate . offersIntern . monthlySalary . value ,
offerToUpdate . offersIntern . monthlySalary . value ,
} ,
} ,
} ,
} ,
specialization :
offerToUpdate . offersIntern . specialization ,
startYear : offerToUpdate.offersIntern.startYear ,
startYear : offerToUpdate.offersIntern.startYear ,
title : offerToUpdate.offersIntern.title ,
title : offerToUpdate.offersIntern.title ,
} ,
} ,
@ -1286,12 +1270,6 @@ export const offersProfileRouter = createRouter()
if (
if (
offerToUpdate . jobType === JobType . FULLTIME &&
offerToUpdate . jobType === JobType . FULLTIME &&
offerToUpdate . offersFullTime &&
offerToUpdate . offersFullTime &&
offerToUpdate . offersFullTime . baseSalary ? . currency != null &&
offerToUpdate . offersFullTime . baseSalary ? . value != null &&
offerToUpdate . offersFullTime . bonus ? . currency != null &&
offerToUpdate . offersFullTime . bonus ? . value != null &&
offerToUpdate . offersFullTime . stocks ? . currency != null &&
offerToUpdate . offersFullTime . stocks ? . value != null &&
offerToUpdate . offersFullTime . totalCompensation ? . currency !=
offerToUpdate . offersFullTime . totalCompensation ? . currency !=
null &&
null &&
offerToUpdate . offersFullTime . totalCompensation ? . value != null &&
offerToUpdate . offersFullTime . totalCompensation ? . value != null &&
@ -1313,51 +1291,66 @@ export const offersProfileRouter = createRouter()
negotiationStrategy : offerToUpdate.negotiationStrategy ,
negotiationStrategy : offerToUpdate.negotiationStrategy ,
offersFullTime : {
offersFullTime : {
create : {
create : {
baseSalary : {
baseSalary :
create : {
offerToUpdate . offersFullTime ? . baseSalary != null
baseCurrency : baseCurrencyString ,
? {
baseValue : await convert (
create : {
offerToUpdate . offersFullTime . baseSalary . value ,
baseCurrency : baseCurrencyString ,
offerToUpdate . offersFullTime . baseSalary
baseValue : await convert (
. currency ,
offerToUpdate . offersFullTime . baseSalary
baseCurrencyString ,
. value ,
) ,
offerToUpdate . offersFullTime . baseSalary
currency :
. currency ,
offerToUpdate . offersFullTime . baseSalary
baseCurrencyString ,
. currency ,
) ,
value :
currency :
offerToUpdate . offersFullTime . baseSalary . value ,
offerToUpdate . offersFullTime . baseSalary
} ,
. currency ,
} ,
value :
bonus : {
offerToUpdate . offersFullTime . baseSalary
create : {
. value ,
baseCurrency : baseCurrencyString ,
} ,
baseValue : await convert (
}
offerToUpdate . offersFullTime . bonus . value ,
: undefined ,
offerToUpdate . offersFullTime . bonus . currency ,
bonus :
baseCurrencyString ,
offerToUpdate . offersFullTime ? . bonus != null
) ,
? {
currency :
create : {
offerToUpdate . offersFullTime . bonus . currency ,
baseCurrency : baseCurrencyString ,
value : offerToUpdate.offersFullTime.bonus.value ,
baseValue : await convert (
} ,
offerToUpdate . offersFullTime . bonus . value ,
} ,
offerToUpdate . offersFullTime . bonus
. currency ,
baseCurrencyString ,
) ,
currency :
offerToUpdate . offersFullTime . bonus
. currency ,
value :
offerToUpdate . offersFullTime . bonus . value ,
} ,
}
: undefined ,
level : offerToUpdate.offersFullTime.level ,
level : offerToUpdate.offersFullTime.level ,
specialization :
stocks :
offerToUpdate . offersFullTime . specialization ,
offerToUpdate . offersFullTime ? . stocks != null
stocks : {
? {
create : {
create : {
baseCurrency : baseCurrencyString ,
baseCurrency : baseCurrencyString ,
baseValue : await convert (
baseValue : await convert (
offerToUpdate . offersFullTime . stocks . value ,
offerToUpdate . offersFullTime . stocks . value ,
offerToUpdate . offersFullTime . stocks . currency ,
offerToUpdate . offersFullTime . stocks
baseCurrencyString ,
. currency ,
) ,
baseCurrencyString ,
currency :
) ,
offerToUpdate . offersFullTime . stocks . currency ,
currency :
value : offerToUpdate.offersFullTime.stocks.value ,
offerToUpdate . offersFullTime . stocks
} ,
. currency ,
} ,
value :
offerToUpdate . offersFullTime . stocks . value ,
} ,
}
: undefined ,
title : offerToUpdate.offersFullTime.title ,
title : offerToUpdate.offersFullTime.title ,
totalCompensation : {
totalCompensation : {
create : {
create : {