# All files / src/trpc/routers preview.ts

10% Statements 1/10
100% Branches 0/0
20% Functions 1/5
10% Lines 1/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52

    11x

     /**
     * Preview Router — start, stop, list, status for Docker-based preview deployments
     */

    import { z } from 'zod';
    import type { ProcedureBuilder } from '../trpc.js';
    import { requirePreviewManager } from './_helpers.js';

    export function previewProcedures(publicProcedure: ProcedureBuilder) {
      return {
        startPreview: publicProcedure
          .input(z.object({
            initiativeId: z.string().min(1),
            phaseId: z.string().min(1).optional(),
            projectId: z.string().min(1),
            branch: z.string().min(1),
          }))
          .mutation(async ({ ctx, input }) => {
            const previewManager = requirePreviewManager(ctx);
            return previewManager.start(input);
          }),

        stopPreview: publicProcedure
          .input(z.object({
            previewId: z.string().min(1),
          }))
          .mutation(async ({ ctx, input }) => {
            const previewManager = requirePreviewManager(ctx);
            await previewManager.stop(input.previewId);
            return { success: true };
          }),

        listPreviews: publicProcedure
          .input(z.object({
            initiativeId: z.string().min(1).optional(),
          }).optional())
          .query(async ({ ctx, input }) => {
            const previewManager = requirePreviewManager(ctx);
            return previewManager.list(input?.initiativeId);
          }),

        getPreviewStatus: publicProcedure
          .input(z.object({
            previewId: z.string().min(1),
          }))
          .query(async ({ ctx, input }) => {
            const previewManager = requirePreviewManager(ctx);
            return previewManager.getStatus(input.previewId);
          }),
      };
    }