All files / lib/lambda/update adminChangeSchemas.ts

88.88% Statements 16/18
100% Branches 0/0
71.42% Functions 5/7
100% Lines 13/13

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    4x                       4x                     4x                       4x                       4x 6x             4x 6x             4x             4x             4x                           4x                               4x              
import { z } from "zod";
 
export const deleteAdminChangeSchema = z
  .object({
    id: z.string(),
    deleted: z.boolean(),
    adminChangeType: z.literal("delete"),
    makoChangedDate: z.number(),
    changedDate: z.number(),
    statusDate: z.number(),
    timestamp: z.number(),
  })
  .and(z.record(z.string(), z.any()));
 
export const updateValuesAdminChangeSchema = z
  .object({
    id: z.string(),
    adminChangeType: z.literal("update-values"),
    makoChangedDate: z.number(),
    changedDate: z.number(),
    statusDate: z.number(),
    timestamp: z.number(),
  })
  .and(z.record(z.string(), z.any()));
 
export const updateIdAdminChangeSchema = z
  .object({
    id: z.string(),
    adminChangeType: z.literal("update-id"),
    idToBeUpdated: z.string(),
    makoChangedDate: z.number(),
    changedDate: z.number(),
    statusDate: z.number(),
    timestamp: z.number(),
  })
  .and(z.record(z.string(), z.any()));
 
export const splitSPAAdminChangeSchema = z
  .object({
    id: z.string(),
    adminChangeType: z.literal("split-spa"),
    idToBeUpdated: z.string(),
    makoChangedDate: z.number(),
    changedDate: z.number(),
    statusDate: z.number(),
    timestamp: z.number(),
  })
  .and(z.record(z.string(), z.any()));
 
export const transformDeleteSchema = (offset: number) =>
  deleteAdminChangeSchema.transform((data) => ({
    ...data,
    event: "delete",
    packageId: data.id,
    id: `${data.id}-${offset}`,
  }));
 
export const transformUpdateValuesSchema = (offset: number) =>
  updateValuesAdminChangeSchema.transform((data) => ({
    ...data,
    event: "update-values",
    packageId: data.id,
    id: `${data.id}-${offset}`,
  }));
 
export const transformedUpdateIdSchema = updateIdAdminChangeSchema.transform((data) => ({
  ...data,
  event: "update-id",
  packageId: data.id,
  id: `${data.id}`,
}));
 
export const transformedSplitSPASchema = splitSPAAdminChangeSchema.transform((data) => ({
  ...data,
  event: "split-spa",
  packageId: data.id,
  id: `${data.id}`,
}));
 
export const submitNOSOAdminSchema = z.object({
  id: z.string(),
  authority: z.string(),
  status: z.string(),
  submitterEmail: z.string(),
  submitterName: z.string(),
  adminChangeType: z.literal("NOSO"),
  mockEvent: z.string(),
  changeMade: z.string(),
  changeReason: z.string(),
  submissionDate: z.string(),
  proposedDate: z.string(),
});
 
export const extendSubmitNOSOAdminSchema = submitNOSOAdminSchema.extend({
  packageId: z.string(),
  origin: z.string(),
  makoChangedDate: z.number(),
  changedDate: z.number(),
  statusDate: z.number(),
  timestamp: z.number(),
  submissionDate: z.number().optional(),
  proposedDate: z.number().optional(),
  isAdminChange: z.boolean(),
  state: z.string(),
  event: z.string(),
  stateStatus: z.string(),
  cmsStatus: z.string(),
});
 
export const transformSubmitValuesSchema = extendSubmitNOSOAdminSchema.transform((data) => ({
  ...data,
  adminChangeType: "NOSO",
  event: "NOSO",
  id: data.id,
  packageId: data.id,
}));