Skip to main content

Overview

The Jobs API enables companies to post job openings and manage applications. Freelancers and job seekers can apply to posted positions with cover letters.

Mutations

create

Create a new job posting. Requires the user to have a company profile. Input Parameters:
title
string
required
Job title (5-250 characters)
description
object
required
EditorJS OutputData object with job description
location
string
required
Job location (5-250 characters)
jobType
enum
required
Employment type:
  • full_time: Full-time position
  • part_time: Part-time position
  • contract: Contract work
  • intern: Internship
canBeRemote
boolean
Whether the position can be performed remotelyDefault: false
salary
string
Salary range or information (optional)
Response: Returns the created Job object with generated slug. Errors:
  • BAD_REQUEST: User needs to setup a company profile first
  • BAD_REQUEST: Error occurred while creating the job
Example:
const job = await trpc.job.create.mutate({
  title: "Senior Full-Stack Developer",
  description: {
    blocks: [
      {
        type: "paragraph",
        data: {
          text: "We are looking for an experienced full-stack developer..."
        }
      },
      {
        type: "list",
        data: {
          style: "unordered",
          items: [
            "5+ years of experience",
            "React and Node.js expertise",
            "Strong communication skills"
          ]
        }
      }
    ]
  },
  location: "Casablanca, Morocco",
  jobType: "full_time",
  canBeRemote: true,
  salary: "15,000 - 25,000 MAD/month"
});

console.log(`Job created with slug: ${job.slug}`);

update

Update an existing job posting. Input Parameters:
id
string
required
Job ID to update
title
string
required
Job title (5-250 characters)
description
object
required
EditorJS OutputData object with job description
location
string
required
Job location (5-250 characters)
jobType
enum
required
Employment type: full_time, part_time, contract, or intern
canBeRemote
boolean
Whether remote work is allowed
salary
string
Salary information
Response: Returns the updated Job object. Errors:
  • BAD_REQUEST: User needs a company profile or update failed
Example:
const updated = await trpc.job.update.mutate({
  id: "job_clxxx...",
  title: "Senior Full-Stack Developer (Updated)",
  description: updatedDescription,
  location: "Rabat, Morocco",
  jobType: "full_time",
  canBeRemote: true,
  salary: "20,000 - 30,000 MAD/month"
});

apply

Submit a job application with a cover letter. Input Parameters:
slug
string
required
Job posting slug (URL identifier)
coverLetter
string
required
Cover letter text
Response: Returns the created Application object. Errors:
  • BAD_REQUEST: Job not found
  • BAD_REQUEST: Error occurred while applying
Example:
const application = await trpc.job.apply.mutate({
  slug: "senior-full-stack-developer-ab12",
  coverLetter: `Dear Hiring Manager,

I am excited to apply for the Senior Full-Stack Developer position...

With over 7 years of experience in React and Node.js, I have successfully...

Best regards,
John Doe`
});

console.log("Application submitted:", application.id);

Job Model

Job Fields

id
string
Unique job identifier (CUID)
slug
string
URL-friendly unique identifier (auto-generated)
title
string
Job title
description
Json
Rich text job description (EditorJS format)
location
string
Job location
salary
string
Salary information (optional)
canBeRemote
boolean
Whether remote work is allowed
type
JobType
Employment type enum: full_time, part_time, contract, intern
companyId
string
ID of the company posting the job
createdAt
DateTime
Creation timestamp
updatedAt
DateTime
Last update timestamp

Relations

company
Company
The company that posted this job
applications
Application[]
All applications submitted for this job

Application Model

Application Fields

id
string
Unique application identifier (CUID)
jobId
string
ID of the job being applied to
userId
string
ID of the applicant
coverLetter
string
Cover letter text
createdAt
DateTime
Application submission timestamp
updatedAt
DateTime
Last update timestamp

Relations

applicant
User
The user who applied
job
Job
The job being applied to

Server-Side Functions

getJobById(id: string)

Fetch job details by ID. Returns: Job object or null if not found Example:
import { getJobById } from "@/server/api/routers/job";

const job = await getJobById("job_clxxx...");

getUserJobs()

Fetch all jobs posted by the authenticated user’s company, including applications. Returns: Array of jobs with detailed application data Redirects: To /auth/sign-in if not authenticated Response includes:
  • Job details (id, title, slug, type, description, location, salary, canBeRemote)
  • Application details for each job:
    • Application ID and cover letter
    • Applicant profile (name, bio, resume, contact info)
Example:
import { getUserJobs } from "@/server/api/routers/job";

const jobs = await getUserJobs();

for (const job of jobs) {
  console.log(`${job.title}: ${job.applications.length} applications`);
  
  for (const app of job.applications) {
    console.log(`  - ${app.applicant.firstName} ${app.applicant.lastName}`);
  }
}

getJobApplications(id: string)

Fetch all applications for a specific job. Parameters:
  • id: Job ID
Returns: Array of application objects with applicant details Example:
import { getJobApplications } from "@/server/api/routers/job";

const applications = await getJobApplications("job_clxxx...");

console.log(`Received ${applications.length} applications`);

Complete Example: Job Posting Flow

// 1. Company creates a job posting
const newJob = await trpc.job.create.mutate({
  title: "React Developer",
  description: editorContent,
  location: "Casablanca, Morocco",
  jobType: "full_time",
  canBeRemote: true,
  salary: "12,000 - 18,000 MAD/month"
});

// 2. Job seeker views and applies
const application = await trpc.job.apply.mutate({
  slug: newJob.slug,
  coverLetter: "I am excited to apply..."
});

// 3. Company reviews applications
const allApplications = await getJobApplications(newJob.id);

for (const app of allApplications) {
  console.log(`
    Applicant: ${app.applicant.firstName} ${app.applicant.lastName}
    Email: ${app.applicant.email}
    Resume: ${app.applicant.resume}
    Cover Letter: ${app.coverLetter}
  `);
}

// 4. Update job posting if needed
await trpc.job.update.mutate({
  id: newJob.id,
  title: "Senior React Developer",
  // ... other fields
});

Build docs developers (and LLMs) love