mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 20:52:00 +08:00
[offers][chore] return user object in get comments
This commit is contained in:
@ -3,17 +3,31 @@ import * as trpc from '@trpc/server';
|
|||||||
|
|
||||||
import { createProtectedRouter } from '../context';
|
import { createProtectedRouter } from '../context';
|
||||||
|
|
||||||
|
import type { Reply } from '~/types/offers-profile';
|
||||||
|
|
||||||
|
|
||||||
export const offersCommentsRouter = createProtectedRouter()
|
export const offersCommentsRouter = createProtectedRouter()
|
||||||
.query('getComments', {
|
.query('getComments', {
|
||||||
input: z.object({
|
input: z.object({
|
||||||
profileId: z.string()
|
profileId: z.string()
|
||||||
}),
|
}),
|
||||||
async resolve({ ctx, input }) {
|
async resolve({ ctx, input }) {
|
||||||
|
|
||||||
|
const profile = await ctx.prisma.offersProfile.findFirst({
|
||||||
|
where: {
|
||||||
|
id: input.profileId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const result = await ctx.prisma.offersProfile.findFirst({
|
const result = await ctx.prisma.offersProfile.findFirst({
|
||||||
include: {
|
include: {
|
||||||
discussion: {
|
discussion: {
|
||||||
include: {
|
include: {
|
||||||
replies: true,
|
replies: {
|
||||||
|
include: {
|
||||||
|
user: true
|
||||||
|
}
|
||||||
|
},
|
||||||
replyingTo: true,
|
replyingTo: true,
|
||||||
user: true
|
user: true
|
||||||
}
|
}
|
||||||
@ -25,7 +39,32 @@ export const offersCommentsRouter = createProtectedRouter()
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return result.discussion.filter((x) => x.replyingToId === null)
|
return result.discussion
|
||||||
|
.filter((x: Reply) => x.replyingToId === null)
|
||||||
|
.map((x: Reply) => {
|
||||||
|
if (x.user == null) {
|
||||||
|
x.user = {
|
||||||
|
email: "",
|
||||||
|
emailVerified: null,
|
||||||
|
id: "",
|
||||||
|
image: "",
|
||||||
|
name: profile?.profileName ?? "<missing name>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
x.replies?.map((y) => {
|
||||||
|
if (y.user == null) {
|
||||||
|
y.user = {
|
||||||
|
email: "",
|
||||||
|
emailVerified: null,
|
||||||
|
id: "",
|
||||||
|
image: "",
|
||||||
|
name: profile?.profileName ?? "<missing name>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return x;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -4,7 +4,7 @@ import * as trpc from '@trpc/server';
|
|||||||
|
|
||||||
import { createRouter } from '../context';
|
import { createRouter } from '../context';
|
||||||
|
|
||||||
import type { offersProfile } from '~/types/offers-profile';
|
import type { OffersProfile } from '~/types/offers-profile';
|
||||||
|
|
||||||
const valuation = z.object({
|
const valuation = z.object({
|
||||||
currency: z.string(),
|
currency: z.string(),
|
||||||
@ -99,19 +99,19 @@ type WithIsEditable<T> = T & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function computeIsEditable(
|
function computeIsEditable(
|
||||||
profileInput: offersProfile,
|
profileInput: OffersProfile,
|
||||||
editToken?: string,
|
editToken?: string,
|
||||||
): WithIsEditable<offersProfile> {
|
): WithIsEditable<OffersProfile> {
|
||||||
return {
|
return {
|
||||||
...profileInput,
|
...profileInput,
|
||||||
isEditable: profileInput.editToken === editToken,
|
isEditable: profileInput.editToken === editToken,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function exclude<Key extends keyof WithIsEditable<offersProfile>>(
|
function exclude<Key extends keyof WithIsEditable<OffersProfile>>(
|
||||||
profile: WithIsEditable<offersProfile>,
|
profile: WithIsEditable<OffersProfile>,
|
||||||
...keys: Array<Key>
|
...keys: Array<Key>
|
||||||
): Omit<WithIsEditable<offersProfile>, Key> {
|
): Omit<WithIsEditable<OffersProfile>, Key> {
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
delete profile[key];
|
delete profile[key];
|
||||||
}
|
}
|
||||||
|
124
apps/portal/src/types/offers-profile.d.ts
vendored
124
apps/portal/src/types/offers-profile.d.ts
vendored
@ -1,26 +1,26 @@
|
|||||||
export type offersProfile = {
|
export type OffersProfile = {
|
||||||
background?: background | null;
|
background?: Background | null;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
// Discussions: Array<discussion>;
|
// Discussions: Array<discussion>;
|
||||||
editToken: string;
|
editToken: string;
|
||||||
id: string;
|
id: string;
|
||||||
offers: Array<offer>;
|
offers: Array<Offer>;
|
||||||
profileName: string;
|
profileName: string;
|
||||||
userId?: string | null;
|
userId?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type background = {
|
export type Background = {
|
||||||
educations: Array<education>;
|
educations: Array<Education>;
|
||||||
experiences: Array<experience>;
|
experiences: Array<Experience>;
|
||||||
id: string;
|
id: string;
|
||||||
offersProfileId: string;
|
offersProfileId: string;
|
||||||
specificYoes: Array<specificYoe>;
|
specificYoes: Array<SpecificYoe>;
|
||||||
totalYoe?: number | null;
|
totalYoe?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type experience = {
|
export type Experience = {
|
||||||
backgroundId: string;
|
backgroundId: string;
|
||||||
company?: company | null;
|
company?: Company | null;
|
||||||
companyId?: string | null;
|
companyId?: string | null;
|
||||||
durationInMonths?: number | null;
|
durationInMonths?: number | null;
|
||||||
id: string;
|
id: string;
|
||||||
@ -34,7 +34,7 @@ export type experience = {
|
|||||||
totalCompensationId?: string | null;
|
totalCompensationId?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type company = {
|
export type Company = {
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
id: string;
|
id: string;
|
||||||
@ -44,13 +44,13 @@ export type company = {
|
|||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
}
|
}
|
||||||
|
|
||||||
export type valuation = {
|
export type Valuation = {
|
||||||
currency: string;
|
currency: string;
|
||||||
id: string;
|
id: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type education = {
|
export type Education = {
|
||||||
backgroundId: string;
|
backgroundId: string;
|
||||||
endDate?: Date | null;
|
endDate?: Date | null;
|
||||||
field?: string | null;
|
field?: string | null;
|
||||||
@ -60,54 +60,70 @@ export type education = {
|
|||||||
type?: string | null;
|
type?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type specificYoe = {
|
export type SpecificYoe = {
|
||||||
backgroundId: string;
|
backgroundId: string;
|
||||||
domain: string;
|
domain: string;
|
||||||
id: string;
|
id: string;
|
||||||
yoe: number;
|
yoe: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type offers = {
|
export type Offers = {
|
||||||
OffersFullTime?: offersFullTime | null;
|
OffersFullTime?: OffersFullTime | null;
|
||||||
OffersIntern?: offersIntern | null;
|
OffersIntern?: OffersIntern | null;
|
||||||
comments?: string | null;
|
comments?: string | null;
|
||||||
company: company;
|
company: Company;
|
||||||
companyId: string;
|
companyId: string;
|
||||||
id: string;
|
id: string;
|
||||||
jobType: string;
|
jobType: string;
|
||||||
location: string;
|
location: string;
|
||||||
monthYearReceived: string;
|
monthYearReceived: Date;
|
||||||
negotiationStrategy?: string | null;
|
negotiationStrategy?: string | null;
|
||||||
offersFullTimeId?: string | null;
|
offersFullTimeId?: string | null;
|
||||||
offersInternId?: string | null;
|
offersInternId?: string | null;
|
||||||
profileId: string;
|
profileId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type offersFullTime = {
|
export type OffersFullTime = {
|
||||||
baseSalary: valuation;
|
baseSalary: valuation;
|
||||||
baseSalaryId: string;
|
baseSalaryId: string;
|
||||||
bonus: valuation;
|
bonus: valuation;
|
||||||
bonusId: string;
|
bonusId: string;
|
||||||
id: string;
|
id: string;
|
||||||
level: string;
|
level: string;
|
||||||
specialization: string;
|
specialization: string;
|
||||||
stocks: valuation;
|
stocks: valuation;
|
||||||
stocksId: string;
|
stocksId: string;
|
||||||
title?: string | null;
|
title?: string | null;
|
||||||
totalCompensation: valuation;
|
totalCompensation: valuation;
|
||||||
totalCompensationId: string;
|
totalCompensationId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type offersIntern = {
|
export type OffersIntern = {
|
||||||
id: string;
|
id: string;
|
||||||
internshipCycle: string;
|
internshipCycle: string;
|
||||||
monthlySalary: valuation;
|
monthlySalary: valuation;
|
||||||
monthlySalaryId: string;
|
monthlySalaryId: string;
|
||||||
specialization: string;
|
specialization: string;
|
||||||
startYear: number;
|
startYear: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fill in next time
|
export type Reply = {
|
||||||
export type discussion = {
|
createdAt: Date;
|
||||||
id: string;
|
id: string;
|
||||||
|
message: string;
|
||||||
|
// Profile: OffersProfile | null;
|
||||||
|
profileId: string;
|
||||||
|
replies: Array<Discussion>?;
|
||||||
|
replyingTo: Discussion?;
|
||||||
|
replyingToId: string | null;
|
||||||
|
user: User?;
|
||||||
|
userId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type User = {
|
||||||
|
email: string?;
|
||||||
|
emailVerified: Date?;
|
||||||
|
id: string;
|
||||||
|
image: string?;
|
||||||
|
name: string?;
|
||||||
}
|
}
|
Reference in New Issue
Block a user