mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 04:33:42 +08:00
[portal] prettify files
This commit is contained in:
@ -281,6 +281,5 @@ export const questionsAnswerCommentRouter = createProtectedRouter()
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
return answerCommentVote;
|
return answerCommentVote;
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -341,6 +341,5 @@ export const questionsAnswerRouter = createProtectedRouter()
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
return questionsAnswerVote;
|
return questionsAnswerVote;
|
||||||
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
include: {
|
include: {
|
||||||
question: true,
|
question: true,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'asc',
|
createdAt: 'asc',
|
||||||
@ -23,7 +23,7 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
.query('getListById', {
|
.query('getListById', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
@ -38,7 +38,7 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
include: {
|
include: {
|
||||||
question: true,
|
question: true,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'asc',
|
createdAt: 'asc',
|
||||||
@ -47,7 +47,7 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
id: userId,
|
id: userId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
.mutation('create', {
|
.mutation('create', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
@ -163,11 +163,12 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
const userId = ctx.session?.user?.id;
|
const userId = ctx.session?.user?.id;
|
||||||
|
|
||||||
const entryToDelete = await ctx.prisma.questionsListQuestionEntry.findUnique({
|
const entryToDelete =
|
||||||
where: {
|
await ctx.prisma.questionsListQuestionEntry.findUnique({
|
||||||
id: input.id,
|
where: {
|
||||||
},
|
id: input.id,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (entryToDelete?.id !== userId) {
|
if (entryToDelete?.id !== userId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@ -176,7 +177,6 @@ export const questionListRouter = createProtectedRouter()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const listToAugment = await ctx.prisma.questionsList.findUnique({
|
const listToAugment = await ctx.prisma.questionsList.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: entryToDelete.listId,
|
id: entryToDelete.listId,
|
||||||
|
@ -168,7 +168,7 @@ export const questionsQuestionCommentRouter = createProtectedRouter()
|
|||||||
|
|
||||||
const incrementValue: number = vote === Vote.UPVOTE ? 1 : -1;
|
const incrementValue: number = vote === Vote.UPVOTE ? 1 : -1;
|
||||||
|
|
||||||
const [ questionCommentVote ] = await ctx.prisma.$transaction([
|
const [questionCommentVote] = await ctx.prisma.$transaction([
|
||||||
ctx.prisma.questionsQuestionCommentVote.create({
|
ctx.prisma.questionsQuestionCommentVote.create({
|
||||||
data: {
|
data: {
|
||||||
questionCommentId,
|
questionCommentId,
|
||||||
|
@ -6,7 +6,6 @@ import { createProtectedRouter } from './context';
|
|||||||
import type { AggregatedQuestionEncounter } from '~/types/questions';
|
import type { AggregatedQuestionEncounter } from '~/types/questions';
|
||||||
import { SortOrder } from '~/types/questions.d';
|
import { SortOrder } from '~/types/questions.d';
|
||||||
|
|
||||||
|
|
||||||
export const questionsQuestionEncounterRouter = createProtectedRouter()
|
export const questionsQuestionEncounterRouter = createProtectedRouter()
|
||||||
.query('getAggregatedEncounters', {
|
.query('getAggregatedEncounters', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
@ -32,7 +31,8 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
for (let i = 0; i < questionEncountersData.length; i++) {
|
for (let i = 0; i < questionEncountersData.length; i++) {
|
||||||
const encounter = questionEncountersData[i];
|
const encounter = questionEncountersData[i];
|
||||||
|
|
||||||
latestSeenAt = latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
|
latestSeenAt =
|
||||||
|
latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
|
||||||
|
|
||||||
if (!(encounter.company!.name in companyCounts)) {
|
if (!(encounter.company!.name in companyCounts)) {
|
||||||
companyCounts[encounter.company!.name] = 1;
|
companyCounts[encounter.company!.name] = 1;
|
||||||
@ -82,10 +82,9 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
...input,
|
...input,
|
||||||
userId,
|
userId,
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
if (questionToUpdate === null) {
|
if (questionToUpdate === null) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: 'BAD_REQUEST',
|
code: 'BAD_REQUEST',
|
||||||
@ -93,10 +92,13 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!questionToUpdate.lastSeenAt || questionToUpdate.lastSeenAt < input.seenAt) {
|
if (
|
||||||
|
!questionToUpdate.lastSeenAt ||
|
||||||
|
questionToUpdate.lastSeenAt < input.seenAt
|
||||||
|
) {
|
||||||
await tx.questionsQuestion.update({
|
await tx.questionsQuestion.update({
|
||||||
data: {
|
data: {
|
||||||
lastSeenAt : input.seenAt,
|
lastSeenAt: input.seenAt,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: input.questionId,
|
id: input.questionId,
|
||||||
@ -146,23 +148,23 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
where: {
|
where: {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
if (questionToUpdate!.lastSeenAt === questionEncounterToUpdate.seenAt) {
|
if (questionToUpdate!.lastSeenAt === questionEncounterToUpdate.seenAt) {
|
||||||
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
const latestEncounter =
|
||||||
orderBy: {
|
await ctx.prisma.questionsQuestionEncounter.findFirst({
|
||||||
seenAt: SortOrder.DESC,
|
orderBy: {
|
||||||
},
|
seenAt: SortOrder.DESC,
|
||||||
where: {
|
},
|
||||||
questionId: questionToUpdate!.id,
|
where: {
|
||||||
},
|
questionId: questionToUpdate!.id,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await tx.questionsQuestion.update({
|
await tx.questionsQuestion.update({
|
||||||
data: {
|
data: {
|
||||||
lastSeenAt : latestEncounter!.seenAt,
|
lastSeenAt: latestEncounter!.seenAt,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: questionToUpdate!.id,
|
id: questionToUpdate!.id,
|
||||||
@ -170,10 +172,8 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return questionEncounterUpdated;
|
return questionEncounterUpdated;
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.mutation('delete', {
|
.mutation('delete', {
|
||||||
@ -208,24 +208,25 @@ export const questionsQuestionEncounterRouter = createProtectedRouter()
|
|||||||
where: {
|
where: {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
},
|
},
|
||||||
})
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (questionToUpdate!.lastSeenAt === questionEncounterToDelete.seenAt) {
|
if (questionToUpdate!.lastSeenAt === questionEncounterToDelete.seenAt) {
|
||||||
const latestEncounter = await ctx.prisma.questionsQuestionEncounter.findFirst({
|
const latestEncounter =
|
||||||
orderBy: {
|
await ctx.prisma.questionsQuestionEncounter.findFirst({
|
||||||
seenAt: SortOrder.DESC,
|
orderBy: {
|
||||||
},
|
seenAt: SortOrder.DESC,
|
||||||
where: {
|
},
|
||||||
questionId: questionToUpdate!.id,
|
where: {
|
||||||
},
|
questionId: questionToUpdate!.id,
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const lastSeenVal = latestEncounter ? latestEncounter!.seenAt : null;
|
const lastSeenVal = latestEncounter ? latestEncounter!.seenAt : null;
|
||||||
|
|
||||||
await tx.questionsQuestion.update({
|
await tx.questionsQuestion.update({
|
||||||
data: {
|
data: {
|
||||||
lastSeenAt : lastSeenVal,
|
lastSeenAt: lastSeenVal,
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
id: questionToUpdate!.id,
|
id: questionToUpdate!.id,
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import type { Config} from 'unique-names-generator';
|
import type { Config } from 'unique-names-generator';
|
||||||
import { countries, names } from 'unique-names-generator';
|
import { countries, names } from 'unique-names-generator';
|
||||||
import { adjectives, animals,colors, uniqueNamesGenerator } from 'unique-names-generator';
|
import {
|
||||||
|
adjectives,
|
||||||
|
animals,
|
||||||
|
colors,
|
||||||
|
uniqueNamesGenerator,
|
||||||
|
} from 'unique-names-generator';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const customConfig: Config = {
|
const customConfig: Config = {
|
||||||
dictionaries: [adjectives, colors, animals],
|
dictionaries: [adjectives, colors, animals],
|
||||||
@ -12,33 +17,34 @@ const customConfig: Config = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export async function generateRandomName(): Promise<string> {
|
export async function generateRandomName(): Promise<string> {
|
||||||
let uniqueName: string = uniqueNamesGenerator(customConfig);
|
let uniqueName: string = uniqueNamesGenerator(customConfig);
|
||||||
|
|
||||||
let sameNameProfiles = await prisma.offersProfile.findMany({
|
let sameNameProfiles = await prisma.offersProfile.findMany({
|
||||||
where: {
|
where: {
|
||||||
profileName: uniqueName
|
profileName: uniqueName,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
while (sameNameProfiles.length !== 0) {
|
while (sameNameProfiles.length !== 0) {
|
||||||
uniqueName = uniqueNamesGenerator(customConfig);
|
uniqueName = uniqueNamesGenerator(customConfig);
|
||||||
sameNameProfiles = await prisma.offersProfile.findMany({
|
sameNameProfiles = await prisma.offersProfile.findMany({
|
||||||
where: {
|
where: {
|
||||||
profileName: uniqueName
|
profileName: uniqueName,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return uniqueName
|
return uniqueName;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenConfig: Config = {
|
const tokenConfig: Config = {
|
||||||
dictionaries: [adjectives, colors, animals, countries, names]
|
dictionaries: [adjectives, colors, animals, countries, names].sort(
|
||||||
.sort((_a, _b) => 0.5 - Math.random()),
|
(_a, _b) => 0.5 - Math.random(),
|
||||||
|
),
|
||||||
length: 5,
|
length: 5,
|
||||||
separator: '-',
|
separator: '-',
|
||||||
};
|
};
|
||||||
|
|
||||||
export function generateRandomStringForToken(): string {
|
export function generateRandomStringForToken(): string {
|
||||||
return uniqueNamesGenerator(tokenConfig)
|
return uniqueNamesGenerator(tokenConfig);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user