[offers][chore] return user object in get comments

pull/380/head
Stuart Long Chay Boon 2 years ago
parent dccc68b710
commit 0f2f0dc64d

@ -3,17 +3,31 @@ import * as trpc from '@trpc/server';
import { createProtectedRouter } from '../context';
import type { Reply } from '~/types/offers-profile';
export const offersCommentsRouter = createProtectedRouter()
.query('getComments', {
input: z.object({
profileId: z.string()
}),
async resolve({ ctx, input }) {
const profile = await ctx.prisma.offersProfile.findFirst({
where: {
id: input.profileId
}
})
const result = await ctx.prisma.offersProfile.findFirst({
include: {
discussion: {
include: {
replies: true,
replies: {
include: {
user: true
}
},
replyingTo: true,
user: true
}
@ -25,7 +39,32 @@ export const offersCommentsRouter = createProtectedRouter()
})
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

@ -4,7 +4,7 @@ import * as trpc from '@trpc/server';
import { createRouter } from '../context';
import type { offersProfile } from '~/types/offers-profile';
import type { OffersProfile } from '~/types/offers-profile';
const valuation = z.object({
currency: z.string(),
@ -99,19 +99,19 @@ type WithIsEditable<T> = T & {
};
function computeIsEditable(
profileInput: offersProfile,
profileInput: OffersProfile,
editToken?: string,
): WithIsEditable<offersProfile> {
): WithIsEditable<OffersProfile> {
return {
...profileInput,
isEditable: profileInput.editToken === editToken,
};
}
function exclude<Key extends keyof WithIsEditable<offersProfile>>(
profile: WithIsEditable<offersProfile>,
function exclude<Key extends keyof WithIsEditable<OffersProfile>>(
profile: WithIsEditable<OffersProfile>,
...keys: Array<Key>
): Omit<WithIsEditable<offersProfile>, Key> {
): Omit<WithIsEditable<OffersProfile>, Key> {
for (const key of keys) {
delete profile[key];
}

@ -1,26 +1,26 @@
export type offersProfile = {
background?: background | null;
export type OffersProfile = {
background?: Background | null;
createdAt: Date;
// Discussions: Array<discussion>;
editToken: string;
id: string;
offers: Array<offer>;
offers: Array<Offer>;
profileName: string;
userId?: string | null;
};
export type background = {
educations: Array<education>;
experiences: Array<experience>;
export type Background = {
educations: Array<Education>;
experiences: Array<Experience>;
id: string;
offersProfileId: string;
specificYoes: Array<specificYoe>;
specificYoes: Array<SpecificYoe>;
totalYoe?: number | null;
}
export type experience = {
export type Experience = {
backgroundId: string;
company?: company | null;
company?: Company | null;
companyId?: string | null;
durationInMonths?: number | null;
id: string;
@ -34,7 +34,7 @@ export type experience = {
totalCompensationId?: string | null;
}
export type company = {
export type Company = {
createdAt: Date;
description: string | null;
id: string;
@ -44,13 +44,13 @@ export type company = {
updatedAt: Date
}
export type valuation = {
export type Valuation = {
currency: string;
id: string;
value: number;
}
export type education = {
export type Education = {
backgroundId: string;
endDate?: Date | null;
field?: string | null;
@ -60,54 +60,70 @@ export type education = {
type?: string | null;
}
export type specificYoe = {
backgroundId: string;
domain: string;
id: string;
yoe: number;
export type SpecificYoe = {
backgroundId: string;
domain: string;
id: string;
yoe: number;
}
export type offers = {
OffersFullTime?: offersFullTime | null;
OffersIntern?: offersIntern | null;
comments?: string | null;
company: company;
companyId: string;
id: string;
jobType: string;
location: string;
monthYearReceived: string;
negotiationStrategy?: string | null;
offersFullTimeId?: string | null;
offersInternId?: string | null;
profileId: string;
export type Offers = {
OffersFullTime?: OffersFullTime | null;
OffersIntern?: OffersIntern | null;
comments?: string | null;
company: Company;
companyId: string;
id: string;
jobType: string;
location: string;
monthYearReceived: Date;
negotiationStrategy?: string | null;
offersFullTimeId?: string | null;
offersInternId?: string | null;
profileId: string;
}
export type offersFullTime = {
baseSalary: valuation;
baseSalaryId: string;
bonus: valuation;
bonusId: string;
id: string;
level: string;
specialization: string;
stocks: valuation;
stocksId: string;
title?: string | null;
totalCompensation: valuation;
totalCompensationId: string;
export type OffersFullTime = {
baseSalary: valuation;
baseSalaryId: string;
bonus: valuation;
bonusId: string;
id: string;
level: string;
specialization: string;
stocks: valuation;
stocksId: string;
title?: string | null;
totalCompensation: valuation;
totalCompensationId: string;
}
export type offersIntern = {
id: string;
internshipCycle: string;
monthlySalary: valuation;
monthlySalaryId: string;
specialization: string;
startYear: number;
export type OffersIntern = {
id: string;
internshipCycle: string;
monthlySalary: valuation;
monthlySalaryId: string;
specialization: string;
startYear: number;
}
// TODO: fill in next time
export type discussion = {
id: string;
export type Reply = {
createdAt: Date;
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?;
}
Loading…
Cancel
Save