[resumes][refactor] Package routers into folders (#341)
* [resumes][refactor] package routers into folders * [resumes][fix] use US as valuepull/342/head
parent
e9d12dfce7
commit
e7d08d46c8
@ -1,27 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { createProtectedRouter } from './context';
|
|
||||||
|
|
||||||
export const resumesResumeUserRouter = createProtectedRouter().mutation(
|
|
||||||
'create',
|
|
||||||
{
|
|
||||||
// TODO: Use enums for experience, location, role
|
|
||||||
input: z.object({
|
|
||||||
additionalInfo: z.string().optional(),
|
|
||||||
experience: z.string(),
|
|
||||||
location: z.string(),
|
|
||||||
role: z.string(),
|
|
||||||
title: z.string(),
|
|
||||||
url: z.string(),
|
|
||||||
}),
|
|
||||||
async resolve({ ctx, input }) {
|
|
||||||
const userId = ctx.session?.user.id;
|
|
||||||
return await ctx.prisma.resumesResume.create({
|
|
||||||
data: {
|
|
||||||
...input,
|
|
||||||
userId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
@ -1,42 +0,0 @@
|
|||||||
import { createRouter } from './context';
|
|
||||||
|
|
||||||
import type { Resume } from '~/types/resume';
|
|
||||||
|
|
||||||
export const resumesRouter = createRouter().query('all', {
|
|
||||||
async resolve({ ctx }) {
|
|
||||||
const resumesData = await ctx.prisma.resumesResume.findMany({
|
|
||||||
include: {
|
|
||||||
_count: {
|
|
||||||
select: {
|
|
||||||
comments: true,
|
|
||||||
stars: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
select: {
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
orderBy: {
|
|
||||||
createdAt: 'desc',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return resumesData.map((r) => {
|
|
||||||
const resume: Resume = {
|
|
||||||
additionalInfo: r.additionalInfo,
|
|
||||||
createdAt: r.createdAt,
|
|
||||||
experience: r.experience,
|
|
||||||
id: r.id,
|
|
||||||
location: r.location,
|
|
||||||
numComments: r._count.comments,
|
|
||||||
numStars: r._count.stars,
|
|
||||||
role: r.role,
|
|
||||||
title: r.title,
|
|
||||||
url: r.url,
|
|
||||||
user: r.user.name!,
|
|
||||||
};
|
|
||||||
return resume;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
@ -0,0 +1,79 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
import { createRouter } from '../context';
|
||||||
|
|
||||||
|
import type { Resume } from '~/types/resume';
|
||||||
|
|
||||||
|
export const resumesRouter = createRouter()
|
||||||
|
.query('findAll', {
|
||||||
|
async resolve({ ctx }) {
|
||||||
|
const resumesData = await ctx.prisma.resumesResume.findMany({
|
||||||
|
include: {
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
comments: true,
|
||||||
|
stars: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
orderBy: {
|
||||||
|
createdAt: 'desc',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return resumesData.map((r) => {
|
||||||
|
const resume: Resume = {
|
||||||
|
additionalInfo: r.additionalInfo,
|
||||||
|
createdAt: r.createdAt,
|
||||||
|
experience: r.experience,
|
||||||
|
id: r.id,
|
||||||
|
location: r.location,
|
||||||
|
numComments: r._count.comments,
|
||||||
|
numStars: r._count.stars,
|
||||||
|
role: r.role,
|
||||||
|
title: r.title,
|
||||||
|
url: r.url,
|
||||||
|
user: r.user.name!,
|
||||||
|
};
|
||||||
|
return resume;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.query('findOne', {
|
||||||
|
input: z.object({
|
||||||
|
resumeId: z.string(),
|
||||||
|
}),
|
||||||
|
async resolve({ ctx, input }) {
|
||||||
|
const { resumeId } = input;
|
||||||
|
const userId = ctx.session?.user?.id;
|
||||||
|
|
||||||
|
// Use the resumeId to query all related information of a single resume
|
||||||
|
// from Resumesresume:
|
||||||
|
return await ctx.prisma.resumesResume.findUnique({
|
||||||
|
include: {
|
||||||
|
_count: {
|
||||||
|
select: {
|
||||||
|
stars: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
stars: {
|
||||||
|
where: {
|
||||||
|
userId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
user: {
|
||||||
|
select: {
|
||||||
|
name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
id: resumeId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
@ -1,6 +1,6 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { createRouter } from './context';
|
import { createRouter } from '../context';
|
||||||
|
|
||||||
import type { ResumeComment } from '~/types/resume-comments';
|
import type { ResumeComment } from '~/types/resume-comments';
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { ResumesSection } from '@prisma/client';
|
import { ResumesSection } from '@prisma/client';
|
||||||
|
|
||||||
import { createProtectedRouter } from './context';
|
import { createProtectedRouter } from '../context';
|
||||||
|
|
||||||
type IResumeCommentInput = Readonly<{
|
type IResumeCommentInput = Readonly<{
|
||||||
description: string;
|
description: string;
|
Loading…
Reference in new issue