A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
import z from "zod";
import { applicationClosedReasonSchema } from "@reactive-resume/schema/applications/data";
import { protectedProcedure } from "../../context";
import { applicationDto } from "../../dto/application";
import { resumeMutationRateLimit } from "../../middleware/rate-limit";
import { paginate, paginationShape } from "../../pagination";
import { applicationService } from "./service";
export const crudRouter = {
listTrash: protectedProcedure
.route({
method: "GET",
path: "/applications/trash",
tags: ["Applications"],
operationId: "listTrashedApplications",
summary: "List applications in Trash",
})
.input(z.object(paginationShape).default({}))
.output(
z.object({
items: z.array(z.object({ id: z.string(), company: z.string(), role: z.string(), trashedAt: z.date() })),
total: z.number().int(),
}),
)
.handler(({ input, context }) =>
applicationService.listTrash({ userId: context.user.id, limit: input.limit ?? 100, offset: input.offset ?? 0 }),
),
restore: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/restore",
tags: ["Applications"],
operationId: "restoreApplication",
summary: "Restore an application from Trash",
description:
"Restores the retained application, timeline and relationships. Requires the timestamp returned by listTrashedApplications; a stale Trash action is refused.",
})
.input(z.object({ id: z.string(), trashedAt: z.date() }))
.use(resumeMutationRateLimit)
.output(z.void())
.handler(({ input, context }) => applicationService.restore({ ...input, userId: context.user.id })),
purge: protectedProcedure
.route({
method: "DELETE",
path: "/applications/{id}/trash",
tags: ["Applications"],
operationId: "purgeApplication",
summary: "Permanently delete an application from Trash",
description:
"Permanently removes only the listed Trash generation. Refuses a restored or re-trashed application. Linked resumes and letters are kept.",
})
.input(z.object({ id: z.string(), trashedAt: z.date() }))
.use(resumeMutationRateLimit)
.output(z.void())
.handler(({ input, context }) => applicationService.purge({ ...input, userId: context.user.id })),
trash: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/trash",
tags: ["Applications"],
operationId: "trashApplication",
summary: "Move an application to Trash",
description:
"Retains the timeline, relationships and files until explicitly permanently deleted. Restore from Trash after reload.",
})
.input(applicationDto.delete.input)
.use(resumeMutationRateLimit)
.output(applicationDto.delete.output)
.handler(({ input, context }) => applicationService.delete({ id: input.id, userId: context.user.id })),
bulkTrash: protectedProcedure
.route({
method: "POST",
path: "/applications/trash",
tags: ["Applications"],
operationId: "trashApplications",
summary: "Move applications to Trash",
})
.input(applicationDto.bulkDelete.input)
.use(resumeMutationRateLimit)
.output(applicationDto.bulkDelete.output)
.handler(({ input, context }) => applicationService.bulkDelete({ ...input, userId: context.user.id })),
findPosting: protectedProcedure
.route({
method: "GET",
path: "/applications/by-posting",
tags: ["Applications"],
operationId: "findTrackedPosting",
summary: "Find an owned application by canonical posting URL",
})
.input(z.object({ sourceUrl: z.string().max(2048) }))
.output(
z.object({
application: z
.object({ id: z.string(), role: z.string(), company: z.string(), sourceUrl: z.string().nullable() })
.nullable(),
}),
)
.handler(async ({ input, context }) => ({
application: await applicationService.findPosting({ ...input, userId: context.user.id }),
})),
priorNoResponse: protectedProcedure
.route({
method: "GET",
path: "/applications/prior-no-response",
tags: ["Applications"],
operationId: "getPriorNoResponseApplications",
summary: "Find prior no-response applications at a company",
description:
"Up to the ten most recent earlier applications at the same company that ended without a response. With `anyOutcome`, up to the ten most recent earlier closed applications, with their outcome (`closedReason`). Requires authentication.",
})
.input(
z.object({
company: z.string().trim().min(1).max(500),
excludeId: z.string().optional(),
anyOutcome: z.boolean().optional(),
}),
)
.output(
z.array(
z.object({
id: z.string(),
company: z.string(),
role: z.string(),
at: z.date(),
closedReason: applicationClosedReasonSchema.nullable().optional(),
}),
),
)
.handler(({ input, context }) => applicationService.priorNoResponse({ ...input, userId: context.user.id })),
list: protectedProcedure
.route({
method: "GET",
path: "/applications",
tags: ["Applications"],
operationId: "listApplications",
summary: "List job applications",
description:
"Returns all job applications belonging to the authenticated user, most recently updated first. Optionally filter by pipeline stage. Requires authentication.",
successDescription: "A list of the user's job applications.",
})
.input(applicationDto.list.input)
.output(applicationDto.list.output)
.handler(async ({ input, context }) => {
const { items, total } = await applicationService.list({
userId: context.user.id,
...(input.status ? { status: input.status } : {}),
...(input.laneId ? { laneId: input.laneId } : {}),
...(input.tags ? { tags: input.tags } : {}),
...(input.limit !== undefined ? { limit: input.limit } : {}),
...(input.offset !== undefined ? { offset: input.offset } : {}),
});
context.resHeaders?.set("X-Total-Count", String(total));
if (input.limit !== undefined || input.offset !== undefined) {
context.resHeaders?.set("X-Limit", String(input.limit ?? 20));
context.resHeaders?.set("X-Offset", String(input.offset ?? 0));
}
return items;
}),
listSummary: protectedProcedure
.route({
method: "GET",
path: "/applications/summary",
tags: ["Applications"],
operationId: "listApplicationSummaries",
summary: "List application summaries",
description:
"Returns lightweight application summaries for list views. Full descriptions, notes, documents and timeline note text are omitted; structured followed-up events keep their contact timestamp and stage identity. Use the application endpoint for full detail. When includeInitialDetails is N, up to 2N full details may be attached as initialDetail: the union of the first N candidates under web and mobile ordering, with closed applications excluded unless status is provided.",
successDescription: "A list of lightweight application summaries.",
})
.input(applicationDto.listSummary.input)
.output(applicationDto.listSummary.output)
.handler(async ({ input, context }) => {
const { items, total } = await applicationService.listSummary({
userId: context.user.id,
...(input.status ? { status: input.status } : {}),
...(input.laneId ? { laneId: input.laneId } : {}),
...(input.tags ? { tags: input.tags } : {}),
...(input.limit !== undefined ? { limit: input.limit } : {}),
...(input.offset !== undefined ? { offset: input.offset } : {}),
...(input.includeInitialDetails !== undefined ? { includeInitialDetails: input.includeInitialDetails } : {}),
});
context.resHeaders?.set("X-Total-Count", String(total));
if (input.limit !== undefined || input.offset !== undefined) {
context.resHeaders?.set("X-Limit", String(input.limit ?? 20));
context.resHeaders?.set("X-Offset", String(input.offset ?? 0));
}
return items;
}),
getById: protectedProcedure
.route({
method: "GET",
path: "/applications/{id}",
tags: ["Applications"],
operationId: "getApplication",
summary: "Get application by ID",
description:
"Returns a single job application with its full detail (contacts, activity timeline, linked resume). Only applications belonging to the authenticated user can be retrieved. Requires authentication.",
successDescription: "The job application.",
})
.input(applicationDto.getById.input)
.output(applicationDto.getById.output)
.handler(({ input, context }) => applicationService.getById({ id: input.id, userId: context.user.id })),
create: protectedProcedure
.route({
method: "POST",
path: "/applications",
tags: ["Applications"],
operationId: "createApplication",
summary: "Create a job application",
description:
"Creates a new job application in the pipeline. Company and role are required; all other fields (stage, location, salary, source, linked resume, follow-up, notes, contacts) are optional. Requires authentication.",
successDescription: "The ID of the newly created application.",
})
.input(applicationDto.create.input)
.use(resumeMutationRateLimit)
.output(applicationDto.create.output)
.handler(({ input, context }) => applicationService.create({ userId: context.user.id, ...input })),
import: protectedProcedure
.route({
method: "POST",
path: "/applications/import",
tags: ["Applications"],
operationId: "importApplications",
summary: "Bulk import applications",
description:
"Creates many applications at once from a parsed CSV. Each item requires company and role. Returns the number imported. Requires authentication.",
successDescription: "The number of applications imported.",
})
.input(applicationDto.import.input)
.use(resumeMutationRateLimit)
.output(applicationDto.import.output)
.handler(({ input, context }) => applicationService.importMany({ userId: context.user.id, items: input.items })),
update: protectedProcedure
.route({
method: "PUT",
path: "/applications/{id}",
tags: ["Applications"],
operationId: "updateApplication",
summary: "Update a job application",
description:
"Updates one or more fields of an application, including moving it to a different pipeline stage or archiving it. Moving stages automatically appends an entry to the activity timeline. Only provided fields are changed. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.update.input)
.use(resumeMutationRateLimit)
.output(applicationDto.update.output)
.handler(({ input, context }) =>
applicationService.update({
userId: context.user.id,
...input,
canDeleteAttachments: context.authentication?.permissions.includes("delete") ?? false,
}),
),
deleteContact: protectedProcedure
.route({
method: "DELETE",
path: "/applications/{id}/contacts/{index}",
tags: ["Applications"],
operationId: "deleteApplicationContact",
summary: "Remove an application contact",
description:
"Read the full application and retain its contactsVersion as expectedVersion. Removes only the contact at the reviewed index. On CONFLICT (409), reload and review again; never retry automatically with a new version. Requires authentication and delete permission.",
})
.input(applicationDto.deleteContact.input)
.use(resumeMutationRateLimit)
.output(applicationDto.deleteContact.output)
.handler(({ input, context }) => applicationService.deleteContact({ ...input, userId: context.user.id })),
attachDocument: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/documents/{kind}",
tags: ["Applications"],
operationId: "attachApplicationDocument",
summary: "Attach an application document",
description:
"Uploads and attaches a PDF document to an application. Kind must be either resume or cover-letter. Requires authentication.",
successDescription: "The updated application.",
spec: (current) => {
const requestBody = current.requestBody;
if (!requestBody || "$ref" in requestBody) return current;
const multipart = requestBody.content?.["multipart/form-data"];
if (!multipart) return current;
return {
...current,
requestBody: {
...requestBody,
content: { "multipart/form-data": multipart },
},
};
},
})
.input(applicationDto.attachDocument.input)
.use(resumeMutationRateLimit)
.output(applicationDto.attachDocument.output)
.handler(({ input, context }) =>
applicationService.attachDocument({
userId: context.user.id,
...input,
canDeleteAttachments: context.authentication?.permissions.includes("delete") ?? false,
}),
),
removeDocument: protectedProcedure
.route({
method: "DELETE",
path: "/applications/{id}/documents/{kind}",
tags: ["Applications"],
operationId: "removeApplicationDocument",
summary: "Remove an application document",
description:
"Removes a resume or cover-letter PDF from an application and clears the stored document fields. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.removeDocument.input)
.use(resumeMutationRateLimit)
.output(applicationDto.removeDocument.output)
.handler(({ input, context }) =>
applicationService.removeDocument({ id: input.id, userId: context.user.id, kind: input.kind }),
),
addNote: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/notes",
tags: ["Applications"],
operationId: "addApplicationNote",
summary: "Log a note on the timeline",
description: "Appends a free-text note to the application's activity timeline. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.addNote.input)
.use(resumeMutationRateLimit)
.output(applicationDto.addNote.output)
.handler(({ input, context }) =>
applicationService.addNote({
id: input.id,
userId: context.user.id,
text: input.text,
date: input.date,
}),
),
logFollowUp: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/follow-ups",
tags: ["Applications"],
operationId: "logApplicationFollowUp",
summary: "Log a completed follow-up",
description:
"Records contact now and restarts the no-reply clock for the current stage visit. Keeps stage dates and scheduled reminders. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.logFollowUp.input)
.use(resumeMutationRateLimit)
.output(applicationDto.logFollowUp.output)
.handler(({ input, context }) => applicationService.logFollowUp({ id: input.id, userId: context.user.id })),
logReply: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/replies",
tags: ["Applications"],
operationId: "logApplicationReply",
summary: "Log an explicitly confirmed reply",
description:
"First GET /applications/{id}, review the full application and retain its opaque replyVersion. POST that value as expectedVersion. On CONFLICT (409), reload and review again before retrying. Records the user's confirmation of replying now, restarts the current stage's no-reply clock and clears the application's follow-up and its delivery schedule only at the reviewed revision. Sends no message. Keeps stage dates and interview reminders. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.logReply.input)
.use(resumeMutationRateLimit)
.output(applicationDto.logReply.output)
.handler(({ input, context }) =>
applicationService.logFollowUp({
id: input.id,
userId: context.user.id,
reply: { expectedVersion: input.expectedVersion },
}),
),
addInterview: protectedProcedure
.route({
method: "POST",
path: "/applications/{id}/interviews",
tags: ["Applications"],
operationId: "addApplicationInterview",
summary: "Schedule an interview",
description:
"Adds an interview (screening, technical, behavioral, onsite or other) with a scheduled date-time to the application's activity timeline. Applications can have any number of interviews. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.addInterview.input)
.use(resumeMutationRateLimit)
.output(applicationDto.addInterview.output)
.handler(({ input, context }) => applicationService.addInterview({ ...input, userId: context.user.id })),
updateInterview: protectedProcedure
.route({
method: "PUT",
path: "/applications/{id}/interviews/{entryId}",
tags: ["Applications"],
operationId: "updateApplicationInterview",
summary: "Update a scheduled interview",
description:
"Updates an interview timeline entry (date-time, kind, duration, location, notes). Only provided fields are changed. Delete interviews with the timeline entry delete endpoint. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.updateInterview.input)
.use(resumeMutationRateLimit)
.output(applicationDto.updateInterview.output)
.handler(({ input, context }) => applicationService.updateInterview({ ...input, userId: context.user.id })),
updateTimelineEntry: protectedProcedure
.route({
method: "PUT",
path: "/applications/{id}/timeline/{entryId}",
tags: ["Applications"],
operationId: "updateApplicationTimelineEntry",
summary: "Update a timeline entry",
description:
"Updates a stage or note timeline entry date, or note text for note entries. Interview entries are rejected; use updateApplicationInterview. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.updateTimelineEntry.input)
.use(resumeMutationRateLimit)
.output(applicationDto.updateTimelineEntry.output)
.handler(({ input, context }) => applicationService.updateTimelineEntry({ ...input, userId: context.user.id })),
deleteTimelineEntry: protectedProcedure
.route({
method: "DELETE",
path: "/applications/{id}/timeline/{entryId}",
tags: ["Applications"],
operationId: "deleteApplicationTimelineEntry",
summary: "Delete a timeline entry",
description:
"Deletes a note or older stage entry. The current stage entry cannot be deleted. Requires authentication.",
successDescription: "The updated application.",
})
.input(applicationDto.deleteTimelineEntry.input)
.use(resumeMutationRateLimit)
.output(applicationDto.deleteTimelineEntry.output)
.handler(({ input, context }) => applicationService.deleteTimelineEntry({ ...input, userId: context.user.id })),
delete: protectedProcedure
.route({
method: "DELETE",
path: "/applications/{id}",
tags: ["Applications"],
operationId: "deleteApplication",
summary: "Delete a job application",
description:
"Moves a job application to Trash, retaining its timeline, relationships and files. Restore from Trash after reload. Requires authentication.",
successDescription: "The application was deleted successfully.",
})
.input(applicationDto.delete.input)
.use(resumeMutationRateLimit)
.output(applicationDto.delete.output)
.handler(({ input, context }) => applicationService.delete({ id: input.id, userId: context.user.id })),
bulkUpdate: protectedProcedure
.route({
method: "POST",
path: "/applications/bulk-update",
tags: ["Applications"],
operationId: "bulkUpdateApplications",
summary: "Bulk update applications",
description:
"Applies the same change (move stage, archive/unarchive, add tags) to multiple applications at once. A closedReason requires every selected application to be Closed already, or status/laneId to move them to Closed. Contradictory selections fail atomically. Requires authentication.",
successDescription: "The number of applications updated.",
})
.input(applicationDto.bulkUpdate.input)
.use(resumeMutationRateLimit)
.output(applicationDto.bulkUpdate.output)
.handler(({ input, context }) => applicationService.bulkUpdate({ userId: context.user.id, ...input })),
bulkDelete: protectedProcedure
.route({
method: "POST",
path: "/applications/bulk-delete",
tags: ["Applications"],
operationId: "bulkDeleteApplications",
summary: "Bulk delete applications",
description:
"Moves multiple applications to Trash, retaining their timelines, relationships and files. Requires authentication.",
successDescription: "The number of applications deleted.",
})
.input(applicationDto.bulkDelete.input)
.use(resumeMutationRateLimit)
.output(applicationDto.bulkDelete.output)
.handler(({ input, context }) => applicationService.bulkDelete({ userId: context.user.id, ids: input.ids })),
stats: protectedProcedure
.route({
method: "GET",
path: "/applications/stats",
tags: ["Applications"],
operationId: "getApplicationStats",
summary: "Application pipeline stats",
description: "Returns aggregate counts (per stage, per source) for the Insights view. Requires authentication.",
successDescription: "Aggregate application counts.",
})
.input(applicationDto.stats.input)
.output(applicationDto.stats.output)
.handler(({ context }) => applicationService.stats({ userId: context.user.id })),
tags: protectedProcedure
.route({
method: "GET",
path: "/applications/tags",
tags: ["Applications"],
operationId: "listApplicationTags",
summary: "List application tags",
description: "Returns the distinct tags used across the user's applications. Requires authentication.",
successDescription: "Distinct tags.",
})
.output(applicationDto.tags.output)
.input(z.object(paginationShape).default({}))
.handler(async ({ context, input }) =>
paginate(await applicationService.listTags({ userId: context.user.id }), input, context.resHeaders),
),
};