All files / apps/api-gateway/src/gateway/http api-types.ts

100% Statements 65/65
100% Branches 4/4
100% Functions 0/0
100% Lines 65/65

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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 23510x               10x   10x     10x     10x     10x     10x         10x     10x                               10x             10x     10x     10x     10x     10x     10x   10x     10x     10x     10x     10x     10x     10x     10x     10x   10x     10x     10x     10x     10x             10x     10x     10x     10x   10x     10x     10x                         10x   10x     10x     10x   10x     10x     10x   10x             10x     10x   10x             10x     10x           10x   10x     10x     10x           10x     10x   10x     10x   10x     10x   10x     10x     10x     10x     10x    
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
 
/**
 * Downstream response shapes as the gateway consumes them — and, decorated,
 * the OpenAPI contract it publishes at /api/docs. Kept minimal and local:
 * the gateway is a client of the services' public APIs, not of their
 * internals. (Generated OpenAPI clients would replace these at scale.)
 */
export class WorkOrderDto {
  @ApiProperty({ format: 'uuid' })
  id!: string;
 
  @ApiProperty({ example: 'Leaking tap in kitchen' })
  title!: string;
 
  @ApiProperty({ example: 'Constant drip under the sink' })
  description!: string;
 
  @ApiProperty({ format: 'uuid' })
  propertyId!: string;
 
  @ApiProperty({ enum: ['low', 'medium', 'high', 'urgent'] })
  priority!: string;
 
  @ApiProperty({
    enum: ['open', 'assigned', 'in_progress', 'completed', 'cancelled'],
  })
  status!: string;
 
  @ApiProperty({ format: 'uuid', nullable: true, type: String })
  assigneeId!: string | null;
 
  @ApiProperty({
    nullable: true,
    type: String,
    enum: [
      'plumbing',
      'electrical',
      'hvac',
      'appliance',
      'structural',
      'pest_control',
      'other',
    ],
    description: 'AI triage category — null until (and unless) triage runs',
  })
  triageCategory!: string | null;
 
  @ApiProperty({
    nullable: true,
    type: String,
    enum: ['emergency', 'high', 'medium', 'low'],
  })
  triageUrgency!: string | null;
 
  @ApiProperty({ nullable: true, type: String })
  triageReasoning!: string | null;
 
  @ApiProperty({ nullable: true, type: String, format: 'date-time' })
  triagedAt!: string | null;
 
  @ApiProperty({ format: 'date-time' })
  createdAt!: string;
 
  @ApiProperty({ format: 'date-time' })
  updatedAt!: string;
}
 
export class PropertyDto {
  @ApiProperty({ format: 'uuid' })
  id!: string;
 
  @ApiProperty({ example: 'Riverside House' })
  name!: string;
 
  @ApiProperty({ example: '12 Thames Road' })
  addressLine1!: string;
 
  @ApiProperty({ example: 'London' })
  city!: string;
 
  @ApiProperty({ example: 'SE1 7TP' })
  postcode!: string;
 
  @ApiProperty({ example: 'manager@propflow.dev' })
  managerEmail!: string;
 
  @ApiProperty({ format: 'date-time' })
  createdAt!: string;
 
  @ApiProperty({ format: 'date-time' })
  updatedAt!: string;
}
 
export class ActivityEventDto {
  @ApiProperty({ description: 'Feed cursor — monotonic, opaque to clients' })
  id!: string;
 
  @ApiProperty({ example: 'work-order.created' })
  eventType!: string;
 
  @ApiProperty({ format: 'uuid' })
  workOrderId!: string;
 
  @ApiProperty({ format: 'uuid' })
  propertyId!: string;
 
  @ApiProperty({ nullable: true, type: String })
  correlationId!: string | null;
 
  @ApiProperty({
    nullable: true,
    type: String,
    description: 'Who performed the action — null for system-initiated events',
  })
  actorId!: string | null;
 
  @ApiProperty({ format: 'date-time' })
  occurredAt!: string;
 
  @ApiProperty({ type: Object })
  payload!: Record<string, unknown>;
}
 
export class PageMeta {
  @ApiProperty()
  page!: number;
 
  @ApiProperty()
  limit!: number;
 
  @ApiProperty()
  total!: number;
}
 
export interface Paginated<T> {
  data: T[];
  meta: PageMeta;
}
 
export interface CursorPage<T> {
  data: T[];
  nextCursor: string | null;
}
 
export class WorkOrderPage implements Paginated<WorkOrderDto> {
  @ApiProperty({ type: [WorkOrderDto] })
  data!: WorkOrderDto[];
 
  @ApiProperty()
  meta!: PageMeta;
}
 
export class PropertyPage implements Paginated<PropertyDto> {
  @ApiProperty({ type: [PropertyDto] })
  data!: PropertyDto[];
 
  @ApiProperty()
  meta!: PageMeta;
}
 
export class ActivityPage implements CursorPage<ActivityEventDto> {
  @ApiProperty({ type: [ActivityEventDto] })
  data!: ActivityEventDto[];
 
  @ApiProperty({
    nullable: true,
    type: String,
    description: 'Pass back as ?cursor= for the next page; null at the end',
  })
  nextCursor!: string | null;
}
 
export class PropertySummaryDto {
  @ApiProperty()
  property!: PropertyDto;
 
  @ApiProperty({
    type: [WorkOrderDto],
    nullable: true,
    description: 'null when the work-orders service was unreachable',
  })
  workOrders!: WorkOrderDto[] | null;
 
  @ApiProperty()
  workOrdersAvailable!: boolean;
}
 
// Request bodies. Validation lives with the owning service (the gateway
// passes bodies through untouched) — these classes document, not validate.
 
export class CreateWorkOrderRequest {
  @ApiProperty({ example: 'Leaking tap in kitchen', maxLength: 200 })
  title!: string;
 
  @ApiProperty({ example: 'Constant drip under the sink' })
  description!: string;
 
  @ApiProperty({ format: 'uuid' })
  propertyId!: string;
 
  @ApiPropertyOptional({
    enum: ['low', 'medium', 'high', 'urgent'],
    default: 'medium',
  })
  priority?: string;
}
 
export class AssignWorkOrderRequest {
  @ApiProperty({ format: 'uuid' })
  assigneeId!: string;
}
 
export class UpdateWorkOrderStatusRequest {
  @ApiProperty({ enum: ['in_progress', 'completed', 'cancelled'] })
  status!: string;
}
 
export class CreatePropertyRequest {
  @ApiProperty({ example: 'Riverside House' })
  name!: string;
 
  @ApiProperty({ example: '12 Thames Road' })
  addressLine1!: string;
 
  @ApiProperty({ example: 'London' })
  city!: string;
 
  @ApiProperty({ example: 'SE1 7TP' })
  postcode!: string;
 
  @ApiProperty({ example: 'manager@propflow.dev' })
  managerEmail!: string;
}