Merge branch 'main' into stuart/seed-db

# Conflicts:
#	apps/portal/package.json
pull/501/head^2
Stuart Long Chay Boon 3 years ago
commit 3423535d12

@ -43,6 +43,7 @@
"read-excel-file": "^5.5.3",
"superjson": "^1.10.0",
"xlsx": "^0.18.5",
"unique-names-generator": "^4.7.1",
"zod": "^3.18.0"
},
"devDependencies": {

@ -1,4 +1,4 @@
import crypto, { randomUUID } from 'crypto';
import crypto from 'crypto';
import { z } from 'zod';
import { JobType } from '@prisma/client';
import * as trpc from '@trpc/server';
@ -10,6 +10,7 @@ import {
} from '~/mappers/offers-mappers';
import { baseCurrencyString } from '~/utils/offers/currency';
import { convert } from '~/utils/offers/currency/currencyExchange';
import generateRandomName from '~/utils/offers/randomNameGenerator';
import { createValidationRegex } from '~/utils/offers/zodRegex';
import { createRouter } from '../context';
@ -266,6 +267,24 @@ export const offersProfileRouter = createRouter()
.update(Date.now().toString())
.digest('hex');
// Generate random name until unique
let uniqueName: string = generateRandomName();
let sameNameProfiles = await ctx.prisma.offersProfile.findMany({
where: {
profileName: uniqueName
}
})
while (sameNameProfiles.length !== 0) {
uniqueName = generateRandomName();
sameNameProfiles = await ctx.prisma.offersProfile.findMany({
where: {
profileName: uniqueName
}
})
}
const profile = await ctx.prisma.offersProfile.create({
data: {
background: {
@ -538,7 +557,7 @@ export const offersProfileRouter = createRouter()
}),
),
},
profileName: randomUUID().substring(0, 10),
profileName: uniqueName,
},
});

@ -103,22 +103,32 @@ export const offersRouter = createRouter().query('list', {
monthYearReceived: order,
}
: sortingKey === sortingKeysMap.totalCompensation
? {
offersIntern: {
monthlySalary: {
baseValue: order,
? [
{
offersIntern: {
monthlySalary: {
baseValue: order,
},
},
},
}
{
monthYearReceived: 'desc',
},
]
: sortingKey === sortingKeysMap.totalYoe
? {
profile: {
background: {
totalYoe: order,
? [
{
profile: {
background: {
totalYoe: order,
},
},
},
}
: undefined,
{
monthYearReceived: 'desc',
},
]
: { monthYearReceived: 'desc' },
where: {
AND: [
{
@ -207,22 +217,32 @@ export const offersRouter = createRouter().query('list', {
monthYearReceived: order,
}
: sortingKey === sortingKeysMap.totalCompensation
? {
offersFullTime: {
totalCompensation: {
baseValue: order,
? [
{
offersIntern: {
monthlySalary: {
baseValue: order,
},
},
},
}
{
monthYearReceived: 'desc',
},
]
: sortingKey === sortingKeysMap.totalYoe
? {
profile: {
background: {
totalYoe: order,
? [
{
profile: {
background: {
totalYoe: order,
},
},
},
}
: undefined,
{
monthYearReceived: 'desc',
},
]
: { monthYearReceived: 'desc' },
where: {
AND: [
{

@ -0,0 +1,13 @@
import type { Config } from 'unique-names-generator';
import { adjectives, animals,colors, uniqueNamesGenerator } from 'unique-names-generator';
const customConfig: Config = {
dictionaries: [adjectives, colors, animals],
length: 3,
separator: '-',
};
export default function generateRandomName(): string {
return uniqueNamesGenerator(customConfig)
}

@ -14550,6 +14550,11 @@ unique-filename@^1.1.1:
dependencies:
unique-slug "^2.0.0"
unique-names-generator@^4.7.1:
version "4.7.1"
resolved "https://registry.yarnpkg.com/unique-names-generator/-/unique-names-generator-4.7.1.tgz#966407b12ba97f618928f77322cfac8c80df5597"
integrity sha512-lMx9dX+KRmG8sq6gulYYpKWZc9RlGsgBR6aoO8Qsm3qvkSJ+3rAymr+TnV8EDMrIrwuFJ4kruzMWM/OpYzPoow==
unique-slug@^2.0.0:
version "2.0.2"
resolved "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.2.tgz"

Loading…
Cancel
Save