async listJobs()

in app/lib/server/jobStore.ts [9:67]


  async listJobs({
    page = 1,
    limit = 20,
    status,
    search,
    author,
  }: {
    page?: number;
    limit?: number;
    status?: string;
    search?: string;
    author?: string;
  } = {}) {
    let jobs = Array.from(this.jobs.values());

    // Filter by status
    if (status) {
      jobs = jobs.filter((job) => job.status === status);
    }

    // Filter by search
    if (search) {
      const searchLower = search.toLowerCase();
      jobs = jobs.filter(
        (job) =>
          job.title.toLowerCase().includes(searchLower) ||
          job.description.toLowerCase().includes(searchLower)
      );
    }

    // Filter by author
    if (author) {
      jobs = jobs.filter((job) => job.author === author);
    }

    // Sort by creation date (newest first)
    jobs.sort(
      (a, b) =>
        new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
    );

    // Pagination
    const total = jobs.length;
    const totalPages = Math.ceil(total / limit);
    const offset = (page - 1) * limit;
    const paginatedJobs = jobs.slice(offset, offset + limit);

    return {
      jobs: paginatedJobs,
      pagination: {
        page,
        limit,
        total,
        totalPages,
        hasNext: page < totalPages,
        hasPrev: page > 1,
      },
    };
  }