mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-23 14:52:18 +10:00
refactor: ponytail audit
This commit is contained in:
@@ -17,7 +17,5 @@ export const analysisRouter = {
|
||||
})
|
||||
.input(z.object({ id: z.string().describe("The unique identifier of the resume.") }))
|
||||
.output(storedResumeAnalysisSchema.nullable())
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.analysis.getById({ id: input.id, userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context, input }) => resumeService.analysis.getById({ id: input.id, userId: context.user.id })),
|
||||
};
|
||||
|
||||
@@ -19,13 +19,13 @@ export const crudRouter = {
|
||||
})
|
||||
.input(resumeDto.list.input.optional().default({ tags: [], sort: "lastUpdatedAt" }))
|
||||
.output(resumeDto.list.output)
|
||||
.handler(async ({ input, context }) => {
|
||||
return resumeService.list({
|
||||
.handler(({ input, context }) =>
|
||||
resumeService.list({
|
||||
userId: context.user.id,
|
||||
tags: input.tags,
|
||||
sort: input.sort,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
getById: protectedProcedure
|
||||
.route({
|
||||
@@ -40,9 +40,7 @@ export const crudRouter = {
|
||||
})
|
||||
.input(resumeDto.getById.input)
|
||||
.output(resumeDto.getById.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.getById({ id: input.id, userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context, input }) => resumeService.getById({ id: input.id, userId: context.user.id })),
|
||||
|
||||
create: protectedProcedure
|
||||
.route({
|
||||
@@ -64,16 +62,16 @@ export const crudRouter = {
|
||||
status: 400,
|
||||
},
|
||||
})
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.create({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.create({
|
||||
name: input.name,
|
||||
slug: input.slug,
|
||||
tags: input.tags,
|
||||
locale: context.locale,
|
||||
userId: context.user.id,
|
||||
...(input.withSampleData ? { data: createSampleResumeData(input.name) } : {}),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
import: protectedProcedure
|
||||
.route({
|
||||
@@ -139,8 +137,8 @@ export const crudRouter = {
|
||||
status: 400,
|
||||
},
|
||||
})
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.update({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.update({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
...(input.name !== undefined ? { name: input.name } : {}),
|
||||
@@ -148,8 +146,8 @@ export const crudRouter = {
|
||||
...(input.tags !== undefined ? { tags: input.tags } : {}),
|
||||
...(input.data !== undefined ? { data: input.data } : {}),
|
||||
...(input.isPublic !== undefined ? { isPublic: input.isPublic } : {}),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
patch: protectedProcedure
|
||||
.route({
|
||||
@@ -175,14 +173,14 @@ export const crudRouter = {
|
||||
status: 409,
|
||||
},
|
||||
})
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.patch({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.patch({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
operations: input.operations,
|
||||
...(input.expectedUpdatedAt ? { expectedUpdatedAt: input.expectedUpdatedAt } : {}),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
setLocked: protectedProcedure
|
||||
.route({
|
||||
@@ -198,13 +196,13 @@ export const crudRouter = {
|
||||
.input(resumeDto.setLocked.input)
|
||||
.use(resumeMutationRateLimit)
|
||||
.output(resumeDto.setLocked.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.setLocked({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.setLocked({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
isLocked: input.isLocked,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
duplicate: protectedProcedure
|
||||
.route({
|
||||
@@ -247,7 +245,5 @@ export const crudRouter = {
|
||||
.input(resumeDto.delete.input)
|
||||
.use(resumeMutationRateLimit)
|
||||
.output(resumeDto.delete.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.delete({ id: input.id, userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context, input }) => resumeService.delete({ id: input.id, userId: context.user.id })),
|
||||
};
|
||||
|
||||
@@ -75,10 +75,10 @@ export const downloadResumePdfProcedure = protectedProcedure
|
||||
}),
|
||||
)
|
||||
.use(pdfExportRateLimit)
|
||||
.handler(async ({ context, input }) => {
|
||||
return createResumePdfDownload({
|
||||
.handler(({ context, input }) =>
|
||||
createResumePdfDownload({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
...(input.target ? { target: input.target } : {}),
|
||||
});
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -165,10 +165,7 @@ const tags = {
|
||||
.from(schema.resume)
|
||||
.where(eq(schema.resume.userId, input.userId));
|
||||
|
||||
const uniqueTags = new Set(result.flatMap((tag) => tag.tags));
|
||||
const sortedTags = Array.from(uniqueTags).sort((a, b) => a.localeCompare(b));
|
||||
|
||||
return sortedTags;
|
||||
return [...new Set(result.flatMap((tag) => tag.tags))].sort((a, b) => a.localeCompare(b));
|
||||
},
|
||||
};
|
||||
|
||||
@@ -422,8 +419,8 @@ export const resumeService = {
|
||||
},
|
||||
},
|
||||
|
||||
list: async (input: { userId: string; tags: string[]; sort: "lastUpdatedAt" | "createdAt" | "name" }) => {
|
||||
return await db
|
||||
list: (input: { userId: string; tags: string[]; sort: "lastUpdatedAt" | "createdAt" | "name" }) =>
|
||||
db
|
||||
.select({
|
||||
id: schema.resume.id,
|
||||
name: schema.resume.name,
|
||||
@@ -449,8 +446,7 @@ export const resumeService = {
|
||||
.with("createdAt", () => asc(schema.resume.createdAt))
|
||||
.with("name", () => asc(schema.resume.name))
|
||||
.exhaustive(),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
getById: async (input: { id: string; userId: string }) => {
|
||||
const [resume] = await db
|
||||
|
||||
@@ -18,13 +18,13 @@ export const sharingRouter = {
|
||||
})
|
||||
.input(resumeDto.getBySlug.input)
|
||||
.output(resumeDto.getBySlug.output)
|
||||
.handler(async ({ input, context }) => {
|
||||
return resumeService.getBySlug({
|
||||
.handler(({ input, context }) =>
|
||||
resumeService.getBySlug({
|
||||
...input,
|
||||
requestHeaders: context.reqHeaders,
|
||||
...(context.user?.id ? { currentUserId: context.user.id } : {}),
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
setPassword: protectedProcedure
|
||||
.route({
|
||||
@@ -40,13 +40,13 @@ export const sharingRouter = {
|
||||
.input(resumeDto.setPassword.input)
|
||||
.use(resumeMutationRateLimit)
|
||||
.output(resumeDto.setPassword.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.setPassword({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.setPassword({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
password: input.password,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
|
||||
verifyPassword: publicProcedure
|
||||
.route({
|
||||
@@ -68,14 +68,15 @@ export const sharingRouter = {
|
||||
)
|
||||
.use(resumePasswordRateLimit)
|
||||
.output(z.boolean())
|
||||
.handler(async ({ context, input }): Promise<boolean> => {
|
||||
return resumeService.verifyPassword({
|
||||
username: input.username,
|
||||
slug: input.slug,
|
||||
password: input.password,
|
||||
...(context.resHeaders ? { responseHeaders: context.resHeaders } : {}),
|
||||
});
|
||||
}),
|
||||
.handler(
|
||||
({ context, input }): Promise<boolean> =>
|
||||
resumeService.verifyPassword({
|
||||
username: input.username,
|
||||
slug: input.slug,
|
||||
password: input.password,
|
||||
...(context.resHeaders ? { responseHeaders: context.resHeaders } : {}),
|
||||
}),
|
||||
),
|
||||
|
||||
removePassword: protectedProcedure
|
||||
.route({
|
||||
@@ -91,10 +92,10 @@ export const sharingRouter = {
|
||||
.input(resumeDto.removePassword.input)
|
||||
.use(resumeMutationRateLimit)
|
||||
.output(resumeDto.removePassword.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.removePassword({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.removePassword({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -24,9 +24,7 @@ export const resumeStatisticsRouter = {
|
||||
lastDownloadedAt: z.date().nullable().describe("Timestamp of the last download, or null if never downloaded."),
|
||||
}),
|
||||
)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.statistics.getById({ id: input.id, userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context, input }) => resumeService.statistics.getById({ id: input.id, userId: context.user.id })),
|
||||
|
||||
getDailyById: protectedProcedure
|
||||
.route({
|
||||
@@ -54,7 +52,11 @@ export const resumeStatisticsRouter = {
|
||||
}),
|
||||
),
|
||||
)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.statistics.getDailySeries({ id: input.id, userId: context.user.id, days: input.days });
|
||||
}),
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.statistics.getDailySeries({
|
||||
id: input.id,
|
||||
userId: context.user.id,
|
||||
days: input.days,
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
@@ -15,7 +15,5 @@ export const tagsRouter = {
|
||||
successDescription: "A sorted array of unique tag strings.",
|
||||
})
|
||||
.output(z.array(z.string()))
|
||||
.handler(async ({ context }) => {
|
||||
return resumeService.tags.list({ userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context }) => resumeService.tags.list({ userId: context.user.id })),
|
||||
};
|
||||
|
||||
@@ -17,9 +17,9 @@ export const versionsRouter = {
|
||||
})
|
||||
.input(resumeDto.listVersions.input)
|
||||
.output(resumeDto.listVersions.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.versions.list({ resumeId: input.resumeId, userId: context.user.id });
|
||||
}),
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.versions.list({ resumeId: input.resumeId, userId: context.user.id }),
|
||||
),
|
||||
|
||||
restoreVersion: protectedProcedure
|
||||
.route({
|
||||
@@ -35,11 +35,11 @@ export const versionsRouter = {
|
||||
.input(resumeDto.restoreVersion.input)
|
||||
.use(resumeMutationRateLimit)
|
||||
.output(resumeDto.restoreVersion.output)
|
||||
.handler(async ({ context, input }) => {
|
||||
return resumeService.versions.restore({
|
||||
.handler(({ context, input }) =>
|
||||
resumeService.versions.restore({
|
||||
resumeId: input.resumeId,
|
||||
versionId: input.versionId,
|
||||
userId: context.user.id,
|
||||
});
|
||||
}),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user