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