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", "read-excel-file": "^5.5.3",
"superjson": "^1.10.0", "superjson": "^1.10.0",
"xlsx": "^0.18.5", "xlsx": "^0.18.5",
"unique-names-generator": "^4.7.1",
"zod": "^3.18.0" "zod": "^3.18.0"
}, },
"devDependencies": { "devDependencies": {

@ -1,4 +1,4 @@
import crypto, { randomUUID } from 'crypto'; import crypto from 'crypto';
import { z } from 'zod'; import { z } from 'zod';
import { JobType } from '@prisma/client'; import { JobType } from '@prisma/client';
import * as trpc from '@trpc/server'; import * as trpc from '@trpc/server';
@ -10,6 +10,7 @@ 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 from '~/utils/offers/randomNameGenerator';
import { createValidationRegex } from '~/utils/offers/zodRegex'; import { createValidationRegex } from '~/utils/offers/zodRegex';
import { createRouter } from '../context'; import { createRouter } from '../context';
@ -266,6 +267,24 @@ export const offersProfileRouter = createRouter()
.update(Date.now().toString()) .update(Date.now().toString())
.digest('hex'); .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({ const profile = await ctx.prisma.offersProfile.create({
data: { data: {
background: { 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, monthYearReceived: order,
} }
: sortingKey === sortingKeysMap.totalCompensation : sortingKey === sortingKeysMap.totalCompensation
? { ? [
offersIntern: { {
monthlySalary: { offersIntern: {
baseValue: order, monthlySalary: {
baseValue: order,
},
}, },
}, },
} {
monthYearReceived: 'desc',
},
]
: sortingKey === sortingKeysMap.totalYoe : sortingKey === sortingKeysMap.totalYoe
? { ? [
profile: { {
background: { profile: {
totalYoe: order, background: {
totalYoe: order,
},
}, },
}, },
} {
: undefined, monthYearReceived: 'desc',
},
]
: { monthYearReceived: 'desc' },
where: { where: {
AND: [ AND: [
{ {
@ -207,22 +217,32 @@ export const offersRouter = createRouter().query('list', {
monthYearReceived: order, monthYearReceived: order,
} }
: sortingKey === sortingKeysMap.totalCompensation : sortingKey === sortingKeysMap.totalCompensation
? { ? [
offersFullTime: { {
totalCompensation: { offersIntern: {
baseValue: order, monthlySalary: {
baseValue: order,
},
}, },
}, },
} {
monthYearReceived: 'desc',
},
]
: sortingKey === sortingKeysMap.totalYoe : sortingKey === sortingKeysMap.totalYoe
? { ? [
profile: { {
background: { profile: {
totalYoe: order, background: {
totalYoe: order,
},
}, },
}, },
} {
: undefined, monthYearReceived: 'desc',
},
]
: { monthYearReceived: 'desc' },
where: { where: {
AND: [ 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: dependencies:
unique-slug "^2.0.0" 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: unique-slug@^2.0.0:
version "2.0.2" version "2.0.2"
resolved "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.2.tgz" resolved "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.2.tgz"

Loading…
Cancel
Save