Skip to content

Commit 1c26896

Browse files
committed
fix typing
1 parent 9aaeec8 commit 1c26896

2 files changed

Lines changed: 14 additions & 24 deletions

File tree

lambdas/api-handler/src/contracts/mi.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
import z from "zod";
22
import { makeDocumentSchema } from "./json-api";
33

4-
export const GetMIResponseResourceSchema = z
5-
.object({
6-
id: z.string(),
7-
type: z.literal("ManagementInformation"),
8-
attributes: z
9-
.object({
10-
lineItem: z.string(),
11-
timestamp: z.string(),
12-
quantity: z.string(),
13-
specificationId: z.string().optional(),
14-
groupId: z.string().optional(),
15-
stockRemaining: z.number().optional(),
16-
})
17-
.strict(),
18-
})
19-
.strict();
20-
21-
export const GetMIResponseSchema = makeDocumentSchema(
22-
GetMIResponseResourceSchema,
23-
);
24-
25-
export type GetMIResponse = z.infer<typeof GetMIResponseSchema>;
26-
274
export const PostMIRequestResourceSchema = z
285
.object({
296
type: z.literal("ManagementInformation"),
@@ -60,3 +37,16 @@ export type PostMIResponse = z.infer<typeof PostMIResponseSchema>;
6037
export type IncomingMI = PostMIRequest["data"]["attributes"] & {
6138
supplierId: string;
6239
};
40+
41+
export const GetMIResponseResourceSchema = z
42+
.object({
43+
id: z.string(),
44+
...PostMIRequestResourceSchema.shape,
45+
})
46+
.strict();
47+
48+
export const GetMIResponseSchema = makeDocumentSchema(
49+
GetMIResponseResourceSchema,
50+
);
51+
52+
export type GetMIResponse = z.infer<typeof GetMIResponseSchema>;

lambdas/api-handler/src/mappers/mi-mapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export function mapToPostMIResponse(mi: MIBase): PostMIResponse {
3838
export function mapToGetMIResponse(mi: MIBase): GetMIResponse {
3939
return GetMIResponseResourceSchema.parse({
4040
data: {
41-
id: mi.id,
4241
type: "ManagementInformation",
4342
attributes: {
4443
lineItem: mi.lineItem,
@@ -48,6 +47,7 @@ export function mapToGetMIResponse(mi: MIBase): GetMIResponse {
4847
groupId: mi.groupId,
4948
stockRemaining: mi.stockRemaining,
5049
},
50+
id: mi.id,
5151
},
5252
});
5353
}

0 commit comments

Comments
 (0)