Skip to content

Commit

Permalink
make owner fields consistent across the api
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaniyaps committed Oct 26, 2023
1 parent 00555d7 commit 3266f9c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
8 changes: 2 additions & 6 deletions app/src/schemas/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "zod";
import { attachmentFileSchema } from "./attachment";
import { ownerSchema } from "./user";

export const messageSchema = z.object({
id: z.string(),
Expand All @@ -10,12 +11,7 @@ export const messageSchema = z.object({
isEdited: z.boolean(),
createdAt: z.date(),
updatedAt: z.date().nullable(),
owner: z.object({
name: z.string().nullish(),
username: z.string(),
image: z.string().nullable(),
createdAt: z.date(),
}),
owner: ownerSchema,
});

export const messageCreateSchema = messageSchema.extend({
Expand Down
7 changes: 2 additions & 5 deletions app/src/schemas/room.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { z } from "zod";
import { ownerSchema } from "./user";

export const roomSchema = z.object({
id: z.string(),
name: z.string(),
ownerId: z.string(),
createdAt: z.date(),
updatedAt: z.date().nullable(),
owner: z.object({
name: z.string().nullish(),
username: z.string(),
image: z.string().nullable(),
}),
owner: ownerSchema,
});

export type Room = z.infer<typeof roomSchema>;
8 changes: 8 additions & 0 deletions app/src/schemas/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ export const userSchema = z.object({
updatedAt: z.date().nullable(),
});

export const ownerSchema = z.object({
name: z.string().nullish(),
image: z.string().nullable(),
username: z.string(),
createdAt: z.date(),
updatedAt: z.date().nullable(),
});

export type User = z.infer<typeof userSchema>;
3 changes: 3 additions & 0 deletions app/src/server/api/routers/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const messageRouter = createTRPCRouter({
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down Expand Up @@ -152,6 +153,7 @@ export const messageRouter = createTRPCRouter({
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down Expand Up @@ -217,6 +219,7 @@ export const messageRouter = createTRPCRouter({
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions app/src/server/api/routers/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const roomRouter = createTRPCRouter({
name: true,
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down Expand Up @@ -63,6 +65,8 @@ export const roomRouter = createTRPCRouter({
name: true,
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down Expand Up @@ -139,6 +143,8 @@ export const roomRouter = createTRPCRouter({
name: true,
username: true,
image: true,
createdAt: true,
updatedAt: true,
},
},
},
Expand Down

0 comments on commit 3266f9c

Please sign in to comment.