(input: z.infer<typeof apiCreatePatch>)
| 12 | export type Patch = typeof patch.$inferSelect; |
| 13 | |
| 14 | export const createPatch = async (input: z.infer<typeof apiCreatePatch>) => { |
| 15 | if (!input.applicationId && !input.composeId) { |
| 16 | throw new TRPCError({ |
| 17 | code: "BAD_REQUEST", |
| 18 | message: "Either applicationId or composeId must be provided", |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | const newPatch = await db |
| 23 | .insert(patch) |
| 24 | .values({ |
| 25 | ...input, |
| 26 | content: input.content, |
| 27 | enabled: true, |
| 28 | }) |
| 29 | .returning() |
| 30 | .then((value) => value[0]); |
| 31 | |
| 32 | if (!newPatch) { |
| 33 | throw new TRPCError({ |
| 34 | code: "BAD_REQUEST", |
| 35 | message: "Error creating the patch", |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | return newPatch; |
| 40 | }; |
| 41 | |
| 42 | export const findPatchById = async (patchId: string) => { |
| 43 | const result = await db.query.patch.findFirst({ |
no outgoing calls
no test coverage detected